示例#1
0
 public double Plus(double summand)
 {
     CurrentResult   += summand;
     _latestOperation = CalculatorOperations.Plus;
     _latestParameter = summand;
     return(CurrentResult);
 }
示例#2
0
 public double Minus(double subtrahend)
 {
     CurrentResult   -= subtrahend;
     _latestOperation = CalculatorOperations.Minus;
     _latestParameter = subtrahend;
     return(CurrentResult);
 }
示例#3
0
 public double Multiply(double multiplier)
 {
     CurrentResult   *= multiplier;
     _latestOperation = CalculatorOperations.Multiply;
     _latestParameter = multiplier;
     return(CurrentResult);
 }
示例#4
0
        public void WrittenValueTestModulus()
        {
            //Set values to test
            string testNumber1 = "one";
            string testNumber2 = "two";

            string result = CalculatorOperations.CalculateAnswer("Modulus", testNumber1, testNumber2);
        }
示例#5
0
        public void Divide(int num1, int num2, int expected)
        {
            var arraySolver = new CalculatorOperations();

            int actual = arraySolver.DivideThis(num1, num2);

            Assert.Equal(expected, actual);
        }
示例#6
0
        public void Multiply(int[] numbers, int expected)
        {
            var arraySolver = new CalculatorOperations();

            int actual = arraySolver.MultiplyThis(numbers);

            Assert.Equal(expected, actual);
        }
示例#7
0
        public void AdditionTest()
        {
            //Set values to test
            string testNumber1 = "10";
            string testNumber2 = "4";

            string actualResult   = CalculatorOperations.CalculateAnswer("Add", testNumber1, testNumber2);
            string expectedResult = "14";

            Assert.AreEqual(actualResult, expectedResult);
        }
示例#8
0
        public void MultiplyTest() //requirement 2.1 / 2.2
        {
            //Set values to test
            string testNumber1 = "10";
            string testNumber2 = "4";

            string actualResult   = CalculatorOperations.CalculateAnswer("Multiply", testNumber1, testNumber2);
            string expectedResult = "40";

            Assert.AreEqual(actualResult, expectedResult);
        }
示例#9
0
        public double Divide(double divisor)
        {
            if (divisor == 0)
            {
                throw new ArgumentException("Divisor cannot be 0!");
            }

            CurrentResult   /= divisor;
            _latestOperation = CalculatorOperations.Divide;
            _latestParameter = divisor;
            return(CurrentResult);
        }
示例#10
0
 public int Execute(CalculatorOperations operation, CalculatorArguments args)
 {
     switch (operation)
     {
         case CalculatorOperations.Add:
             return Add(args);
         case CalculatorOperations.Sub:
             return Sub(args);
         case CalculatorOperations.Mul:
             return Mul(args);
         case CalculatorOperations.Div:
             return Div(args);
         default:
             throw new InvalidOperationException();
     }
 }
示例#11
0
        public void ProcessBinOp(CalculatorOperations op)
        {
            if (this.op.HasValue && input.HasValue && result.HasValue)
            {
                Compute();
                this.op = op;
            }
            else
            {
                this.op = op;
            }

            if (input.HasValue)
            {
                result = input;
                Clear();
            }
        }
示例#12
0
 private void xor_btn_Click(object sender, EventArgs e)
 {
     operation_label.Text = "^";
     operation            = CalculatorOperations.XOR;
 }
示例#13
0
 private void and_btn_Click(object sender, EventArgs e)
 {
     operation_label.Text = "*";
     operation            = CalculatorOperations.AND;
 }
示例#14
0
 private void btnMultiply_Click(object sender, EventArgs e)
 {
     txtAnswer.Text = CalculatorOperations.CalculateAnswer("Multiply", txtNumber1.Text, txtNumber2.Text);
 }
示例#15
0
 private void btnSubtract_Click(object sender, EventArgs e)
 {
     txtAnswer.Text = CalculatorOperations.CalculateAnswer("Subtract", txtNumber1.Text, txtNumber2.Text);
 }
示例#16
0
 private void btnDivide_Click(object sender, EventArgs e)
 {
     txtAnswer.Text = CalculatorOperations.CalculateAnswer("Divide", txtNumber1.Text, txtNumber2.Text);
 }
示例#17
0
 public StandardCalculator()
 {
     _latestOperation = CalculatorOperations.None;
 }
示例#18
0
 public void Clear()
 {
     _latestOperation = CalculatorOperations.Clear;
     CurrentResult    = 0;
     _latestParameter = 0;
 }
示例#19
0
 public double Cube()
 {
     _latestOperation = CalculatorOperations.Cube;
     return(CurrentResult * CurrentResult * CurrentResult);
 }
示例#20
0
 public double Square()
 {
     _latestOperation = CalculatorOperations.Square;
     return(CurrentResult * CurrentResult);
 }