Beispiel #1
0
 public ViewController(IntPtr handle) : base(handle)
 {
     model = new CalculatorModel();
     model.OnDisplayChanged += delegate(CalculatorModel model) {
         DisplayLabel.Text = model.Display;
     };
 }
    public ActionResult Sum()
    {
        CalculatorModel model = new CalculatorModel();

        //Return the result
        return(View(model));
    }
Beispiel #3
0
 protected override void PostInitializeComponent
     (string [] arguments, CalculatorModel model, Control [] sharedControls)
 {
     Array.Resize <Control> (ref sharedControls, sharedControls.Length + 1);
     sharedControls [sharedControls.Length - 1] = printerPaperRoll;
     base.PostInitializeComponent(arguments, model, sharedControls);
 }
Beispiel #4
0
        public BaseCalculator(string [] arguments, CalculatorModel model)
        {
            // Required for Windows Form Designer support.  Beware, only the base class can call
            // this operation: it will dispatch to the most derived class and go up the derivation
            // chain so as to initialize the components at each level.  Explicitly calling
            // InitializeComponent in the constructor of derived classes would result in multiple
            // initializations (which are bad for handlers).
            InitializeComponent();

            // Read the parser tables.
            string [] tags = new string [Controls.Count];
            int       i    = 0;

            foreach (Control control in Controls)
            {
                tags [i] = (string)control.Tag;
                i++;
            }
            reader = new Reader("Mockingbird.HP.Parser.Parser", "CGT", model, tags);

            // Initialize the execution thread and wait until it is ready to process requests.
            executionThread = CreateExecutionThread();

            // Now see if we were called from the command line with arguments.
            if (arguments.Length > 0)
            {
                ProcessCommandLine(arguments);
            }

            // Prepare the UI.
            UnbusyUI();

            // Power on.
            executionThread.PowerOn.Set();
        }
        public CalculatorModel Calculate(CalculatorModel calculator)
        {
            if (calculator.CurrentLevel < 21)
            {
                calculator.CurrentPack = calculator.CurrentPack + (calculator.CurrentLevel - 1);
                int seizoenPacks    = calculator.PlayedSeasons * 5;
                int BattlepassPacks = calculator.Battlepass * 12;
                calculator.CurrentPack = calculator.CurrentPack + seizoenPacks + BattlepassPacks + calculator.BoughtPacks;
            }

            else if (calculator.CurrentLevel > 21 && calculator.CurrentLevel < 301)
            {
                int CurrentLevelPack  = calculator.CurrentLevel - 20;
                int PackCalculator2   = (calculator.CurrentLevel / 2);
                int CurrentLevelPack2 = PackCalculator2 + 19;
                int seizoenPacks      = calculator.PlayedSeasons * 5;
                int BattlepassPacks   = calculator.Battlepass * 12;
                calculator.CurrentPack = calculator.CurrentPack + seizoenPacks + BattlepassPacks + calculator.BoughtPacks + CurrentLevelPack2;
            }

            else if (calculator.CurrentLevel > 300 && calculator.CurrentLevel <= 500)
            {
                int CurrentLevelPack  = calculator.CurrentLevel - 300;
                int PackCalculator2   = (CurrentLevelPack / 5);
                int CurrentLevelPack2 = PackCalculator2 + 159;
                int seizoenPacks      = calculator.PlayedSeasons * 5;
                int BattlepassPacks   = calculator.Battlepass * 12;
                calculator.CurrentPack = calculator.CurrentPack + seizoenPacks + BattlepassPacks + calculator.BoughtPacks + CurrentLevelPack2;
            }

            return(calculator);
        }
Beispiel #6
0
        protected virtual void PostInitializeComponent
            (string [] arguments, CalculatorModel model, Control [] sharedControls)
        {
            // Read the parser tables.
            allControls = GetAllControls(this);
            string [] tags = new string [allControls.Length];
            int       i    = 0;

            foreach (Control control in allControls)
            {
                tags [i] = (string)control.Tag;
                i++;
            }

            // Initialize the execution thread and wait until it is ready to process requests.
            executionThread = new Execution.Thread
                                  (model,
                                  tags,
                                  sharedControls,
                                  new Execution.Thread.CrossThreadUINotification(CrossThreadNotifyUI));

            // Now see if we were called from the command line with arguments.
            if (arguments.Length > 0)
            {
                ProcessCommandLine(arguments);
            }

            // Start the calculator.
            PowerOn();
        }
        public void DivideOutputNondecimal()
        {
            //Arrange  48 / 12  =
            CalculatorModel OperationalModel = new CalculatorModel(OutPut);

            OperationalModel.ButtonHelper("fourButton");
            OperationalModel.ButtonHelper("eightButton");
            Console.WriteLine($"Should be 0 : {OperationalModel.Total}");
            Console.WriteLine($"Should be 48 : {OperationalModel.ResultLabel.Content}");
            OperationalModel.ButtonHelper("divideButton");
            Console.WriteLine($"Should be 48 : {OperationalModel.Total}");
            OperationalModel.ButtonHelper("oneButton");
            OperationalModel.ButtonHelper("twoButton");
            Console.WriteLine($"Should be 12 : {OperationalModel.ResultLabel.Content}");
            OperationalModel.ButtonHelper("equalsButton");
            //Act
            var expectedTotal   = 4;
            var expectedDisplay = "4";
            var actualTotal     = OperationalModel.Total;
            var actualDisplay   = OperationalModel.ResultLabel.Content.ToString();

            //Assert
            Assert.AreEqual(expectedTotal, actualTotal);
            Assert.AreEqual(expectedDisplay, actualDisplay);
        }
 public void CalculateFaculty_ShouldReturnExactResult(
     int parameter,
     int expectedResult
     )
 {
     Assert.Equal(expectedResult, CalculatorModel.CalculateFaculty(parameter));
 }
        public void Results_ShouldHaveAllCalculatedResults()
        {
            List <EquationCalculation> equations = EquationsToBeStored;
            var calucaltorModel = new CalculatorModel();

            foreach (EquationCalculation data in equations)
            {
                calucaltorModel.CalculateFromText(data.Equation);
            }

            for (int i = 0, j = 1, count = equations.Count; i < count; i++, j++)
            {
                // An equation is trimmed before saved in the history in the calculator model.
                string trimedEquation = equations[i].Equation.Trim();

                Assert.Equal(equations[i].Result, calucaltorModel.Results[count - j].Result);
                Assert.Equal(trimedEquation, calucaltorModel.Results[count - j].Equation);
            }

            try
            {
                calucaltorModel.CalculateFromText(null);
            }
            catch (ArgumentNullException)
            {
                // Error provoked to test if invalid equation is not added to history.
            }

            Assert.Equal(3, calucaltorModel.Results.Count);
        }
Beispiel #10
0
        public ActionResult Index(CalculatorModel calculator, string myButton)
        {
            switch (myButton)
            {
            case "Add":
                //add
                ViewBag.result = calculator.ValueA + calculator.ValueB;
                break;

            case "Subtract":
                //sub
                ViewBag.result = calculator.ValueA - calculator.ValueB;
                break;

            case "Multiply":
                //mult
                ViewBag.result = calculator.ValueA * calculator.ValueB;
                break;

            case "Divide":
                //div
                ViewBag.result = calculator.ValueA / calculator.ValueB;
                break;
            }

            Response.Write("myButton:" + myButton + "<br>");
            return(View(calculator));
        }
        public void EvalulateNumberTest()
        {
            //EvalulateNumber(int value)
            //Act
            CalculatorModel OperationalModel = new CalculatorModel(OutPut);

            //Arrange : For Flag to be default and Content to be "0"
            OperationalModel.EvalulateNumber(5);
            //Act
            var expected = "5";

            //Assert
            Assert.AreEqual(expected, OperationalModel.ResultLabel.Content.ToString());
            //Arrange : For Flag to be default and Content to have a value other than "0"
            OperationalModel.EvalulateNumber(6);
            //Act
            expected = "56";
            //Assert
            Assert.AreEqual(expected, OperationalModel.ResultLabel.Content.ToString());
            //Arrange: for when the default is set but Reset is true
            OperationalModel.Reset = true;
            OperationalModel.EvalulateNumber(9);
            //Act
            expected = "9";
            //Assert
            Assert.AreEqual(expected, OperationalModel.ResultLabel.Content.ToString());
            //Arrange : different flag
            OperationalModel.Operation = CalculatorModel.Flag.Add;
            OperationalModel.EvalulateNumber(2);
            //Act
            expected = "2";
            //Assert
            Assert.AreEqual(expected, OperationalModel.ResultLabel.Content.ToString());
        }
        public void AdditionOutputNonDecimal()
        {
            CalculatorModel OperationalModel = new CalculatorModel(OutPut);

            //Arrange  6 + 7 =
            OperationalModel.ButtonHelper("sixButton");
            //6
            Console.WriteLine($"should be 6 : {OperationalModel.ResultLabel.Content}");
            OperationalModel.ButtonHelper("plusButton");
            OperationalModel.ButtonHelper("sevenButton");

            //7
            Console.WriteLine($"should be 7 : {OperationalModel.ResultLabel.Content}");
            OperationalModel.ButtonHelper("equalsButton");
            Console.WriteLine($"should be 13 : {OperationalModel.ResultLabel.Content}");
            //Act
            var expectedTotal   = 13;
            var expectedDisplay = "13";
            var actualTotal     = OperationalModel.Total;
            var actualDisplay   = OperationalModel.ResultLabel.Content.ToString();

            //Assert

            Assert.AreEqual(expectedTotal, actualTotal);
            Assert.AreEqual(expectedDisplay, actualDisplay);
        }
Beispiel #13
0
        public ActionResult DoCalculator(CalculatorModel model)
        {
            switch (model.Operator)
            {
            case Operation.Add:
                model.LOperand += model.ROperand;
                model.ROperand  = null;
                break;

            case Operation.Divide:
                if (model.ROperand == 0)
                {
                    model.LOperand = null;
                    model.ROperand = null;
                    model.Operator = null;
                    break;
                }
                model.LOperand /= model.ROperand;
                break;

            case Operation.Multiply:
                model.LOperand *= model.ROperand;
                model.ROperand  = null;
                break;

            case Operation.Subtract:
                model.LOperand -= model.ROperand;
                model.ROperand  = null;
                break;

            default:
                throw new NotImplementedException();
            }
            return(Json(model));
        }
        public ActionResult Index()
        {
            Calculator = SessionBagModel.Current.calcInstance;
            if (Calculator == null)
            {
                Calculator = new CalculatorModel();
            }

            string num       = Request.QueryString["num"];
            string Operation = Request.QueryString["op"];

            if (num != null)
            {
                int number;
                if (Int32.TryParse(num, out number))
                {
                    Calculator.ProcessNumericButton(number);
                }
            }
            else if (Operation != null)
            {
                Calculator.ProcessOperationButton(Operation);
            }

            return(View(Calculator));
        }
Beispiel #15
0
 public Instruction(Reader reader, Symbol symbol, Argument [] args)
 {
     model       = reader.Model;
     instruction = symbol;
     arguments   = args;
     SetText(reader);
 }
Beispiel #16
0
 public static void ApplyDefaults(this CalculatorModel model)
 {
     model.CalculatorSettings.InputString     = "123456789";
     model.CalculatorSettings.ExpectedResult  = 100;
     model.CalculatorSettings.MaximumTryCount = 200;
     model.CalculatorSettings.UseAdd          = true;
     model.CalculatorSettings.UseMinus        = true;
 }
        public void RoundingPrecision_ShouldThrowIfNegativeOrOver15(int invalidPrecision)
        {
            var calculator = new CalculatorModel();

            Assert.Throws <ArgumentOutOfRangeException>(
                () => calculator.RoundingPrecision = invalidPrecision
                );
        }
        public void MaxNumberOfResults_ShouldThrowIfNegative(int negativeValue)
        {
            var calculator = new CalculatorModel();

            Assert.Throws <ArgumentOutOfRangeException>(
                () => calculator.MaxNumberOfResult = negativeValue
                );
        }
        public void CalculateFromText_ShouldThrowExceptionForEmptyString()
        {
            var calculator = new CalculatorModel();

            Assert.Throws <ArgumentException>(
                () => calculator.CalculateFromText(String.Empty)
                );
        }
Beispiel #20
0
 public ActionResult Index(CalculatorModel model)
 {
     model.Addition       = model.FirstNum + model.SecondNum;
     model.Subtraction    = model.FirstNum - model.SecondNum;
     model.Multiplication = model.FirstNum * model.SecondNum;
     model.Division       = Math.Round(model.FirstNum / model.SecondNum, 2);
     return(View(model));
 }
        public void CalculateFromText_ShouldThrowExceptionForNull()
        {
            var calculator = new CalculatorModel();

            Assert.Throws <ArgumentNullException>(
                () => calculator.CalculateFromText(null)
                );
        }
        public void TestIndexView()
        {
            var obj       = new CalculatorController();
            var model     = new CalculatorModel();
            var actResult = obj.Index(model) as ViewResult;

            Assert.IsNotNull(actResult);
        }
 public CalculatorViewModel()
 {
     _calculator = new CalculatorModel();
     _history    = new List <string>();
     Initialize();
     DigitButtonClickCommand     = new RelayCommand <string>(DigitButtonClick);
     OperationButtonClickCommand = new RelayCommand <string>(OperationButtonClick);
 }
Beispiel #24
0
        public ActionResult Index(CalculatorModel calcModel)
        {
            CalculatorModel result;
            var             types = new List <string>()
            {
                "bit - b",
                "Byte - B",
                "Kilobit - Kb",
                "Kilobyte - KB",
                "Megabit - Mb",
                "Megabyte - MB",
                "Gigabit - Gb",
                "Gigabyte - GB",
                "Terabit - Tb",
                "Terabyte - TB",
                "Petabit - Pb",
                "Petabyte - PB",
                "Exabit - Eb",
                "Exabyte - EB",
                "Zettabit - Zb",
                "Zettabyte - ZB",
                "Yottabit - Yb",
            };
            var kilos = new List <string>()
            {
                "1024",
                "1000"
            };

            if (calcModel == null)
            {
                calcModel = new CalculatorModel();
            }

            calcModel.Types =
                types.Select((x, i) => new SelectListItem {
                Text = x, Value = i.ToString()
            }).ToList();
            calcModel.Kilos =
                kilos.Select((x, i) => new SelectListItem {
                Text = x, Value = i.ToString()
            }).ToList();

            if (calcModel != null &&
                calcModel.Value != null &&
                calcModel.SelectedType != null &&
                calcModel.SelectedKilo != null)
            {
                calcModel.Result = new Dictionary <string, string>();
                for (int i = 0; i < 10; i++)
                {
                    calcModel.Result.Add(types[i], GetType(
                                             i, calcModel.Value, calcModel.SelectedKilo, calcModel.SelectedType));
                }
            }

            return(View(calcModel));
        }
        public IActionResult Index(CalculatorModel cm)
        {
            if (ModelState.IsValid)
            {
                this.calculatorService.CalculateSequence(cm);
            }

            return(View(cm));
        }
Beispiel #26
0
 public override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     RetainInstance          = true;
     model                   = new CalculatorModel();
     model.OnDisplayChanged += delegate(CalculatorModel model) {
         displayTextView.Text = model.Display;
     };
 }
 public CalculatorViewModel()
 {
     this.calculator         = new CalculatorModel();
     this.inputText          = string.Empty;
     this.resultText         = string.Empty;
     this.display            = welcome;
     this.isHusbandBtnEnable = true;
     this.isWifeBtnEnable    = true;
 }
Beispiel #28
0
        public void CalcTestTrue()
        {
            var calc = new CalculatorModel(new Model {
                X = 0, Y = 3
            });
            var result = calc.Calculate();

            Assert.IsTrue(result == 3);
        }
Beispiel #29
0
        private void Btn_TouchUpInside(object sender, EventArgs e)
        {
            var calc = new CalculatorModel(new Model {
                X = i, Y = i
            });

            tv.Text = $"Result: {calc.Calculate()}";
            i++;
        }
Beispiel #30
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="model">the model</param>
        /// <exception cref="ArgumentNullException"/>
        public ResetCommand(CalculatorModel model)
        {
            if (null == model)
            {
                throw new ArgumentNullException(nameof(model));
            }

            _model = model;
        }
        public ActionResult Index(CalculatorModel calculatorModel)
        {
            var types = new List<string>()
            {
                "bit - b",
                "Byte - B",
                "Kilobit - Kb",
                "Kilobyte - KB",
                "Megabit - Mb",
                "Megabyte - MB",
                "Gigabit - Gb",
                "Gigabyte - GB",
                "Terabit - Tb",
                "Terabyte - TB",
                "Petabit - Pb",
                "Petabyte - PB",
                "Exabit - Eb",
                "Exabyte - EB",
                "Zettabit - Zb",
                "Zettabyte - ZB",
                "Yottabit - Yb",
            };

            var kilos = new List<string>()
            {
                "1024",
                "1000"
            };

            if (calculatorModel == null)
            {
                calculatorModel = new CalculatorModel();
            }

            calculatorModel.Types = types
                .Select((x, i) => new SelectListItem { Text = x, Value = i.ToString() }).ToList();
            calculatorModel.Kilos = kilos
                .Select((x, i) => new SelectListItem { Text = x, Value = i.ToString() }).ToList();

            if (calculatorModel != null && calculatorModel.SelectedType != null && calculatorModel.SelectedKilo != null)
            {
                calculatorModel.Result = new Dictionary<string, string>();
                for (int i = 0; i < 10; i++)
                {
                    calculatorModel.Result.Add(types[i], GetType(i, calculatorModel.Value, calculatorModel.SelectedKilo, calculatorModel.SelectedType));
                }
            }

            return View(calculatorModel);
        }