Esempio n. 1
0
        public void OperationTest_CosinesCorrectly()
        {
            Models.CalculationModel model = new CalculationModel("-45", "cos");

            Assert.AreEqual(model.FirstOperand, "-45");
            Assert.AreEqual(model.Operation, "cos");
            Assert.AreEqual(model.Result, string.Empty);

            model.CalculateResult();
            Assert.AreEqual(model.Result, "0.707106781186548");
        }
Esempio n. 2
0
        public void OperationTest_TangentsCorrectly()
        {
            Models.CalculationModel model = new CalculationModel("-45", "tan");

            Assert.AreEqual(model.FirstOperand, "-45");
            Assert.AreEqual(model.Operation, "tan");
            Assert.AreEqual(model.Result, string.Empty);

            model.CalculateResult();
            Assert.AreEqual(model.Result, "-1");
        }
Esempio n. 3
0
        public void OperationTest_AddsCorrectly()
        {
            Models.CalculationModel model = new CalculationModel("3", "500", "+");

            Assert.AreEqual(model.FirstOperand, "3");
            Assert.AreEqual(model.SecondOperand, "500");
            Assert.AreEqual(model.Operation, "+");
            Assert.AreEqual(model.Result, string.Empty);

            model.CalculateResult();
            Assert.AreEqual(model.Result, "503");
        }
        public void OperationButtonPress(string operation)
        {
            try
            {
                if (FirstOperand == string.Empty || LastOperation == "=")
                {
                    FirstOperand  = display;
                    LastOperation = operation;
                }
                else
                {
                    SecondOperand = display;
                    Operation     = lastOperation;
                    calculation.CalculateResult();


                    if (Operation == "1/" || Operation == "sqr" || Operation == "sqrt")
                    {
                        FullExpression = Operation + "(" +
                                         Math.Round(Convert.ToDouble(SecondOperand), 10) + ")";
                    }
                    else
                    {
                        FullExpression = Math.Round(Convert.ToDouble(FirstOperand), 10) + " " + Operation + " "
                                         + Math.Round(Convert.ToDouble(SecondOperand), 10);
                    }
                    LastOperation = operation;
                    Display       = Result;
                    FirstOperand  = display;
                }
                newDisplayRequired = true;
            }
            catch (Exception)
            {
                Display = Result == string.Empty ? "Error" : Result;
            }
        }