public void CanEnterSingleDigit()
 {
     for (int a = 0; a <= 9; a++)
     {
         Assert.That(_controller.AcceptCharacter((char)a), Is.EqualTo(a.ToString(CultureInfo.InvariantCulture)));
     }
 }
Exemplo n.º 2
0
 public void CanEnterSingleDigit()
 {
     for (int i = 0; i < 9; i++)
     {
         Assert.That(_controller.AcceptCharacter((char)i), Is.EqualTo(i.ToString()));
     }
 }
Exemplo n.º 3
0
 public void CanNotDivideByZero()
 {
     _controller.AcceptCharacter('5');
     _controller.AcceptCharacter('/');
     _controller.AcceptCharacter('0');
     _controller.AcceptCharacter('=');
     Assert.That(_controller.GetOutput(), Is.EqualTo("Division by 0"));
 }
Exemplo n.º 4
0
 private void stuffAndExpect(string StuffIt, string Expecting)
 {
     foreach (char buttonpress in StuffIt)
     {
         _controller.AcceptCharacter(buttonpress);
     }
     Assert.That(_controller.GetOutput(), Is.EqualTo(Expecting));
 }
        public void CanEnterSingleDigit()
        {
            Assert.That(_controller.AcceptCharacter('1'), Is.EqualTo("1"));
            // There are several approaches - this is a small app, and you could easily create tests
            // for each button.  Otherwise 1 and 0, a symbol, equals, and "C" would be the minimum.
            // A happy medium would also include 5 and 9 to cover postioning, midline, and near a boundry.

            Assert.That(_controller.AcceptCharacter('C'), Is.EqualTo("")); // I'm assuming that pressing 'C;' should return nothing as it should clear the textbox.
        }
        public void CalculatorClearButtonResetsValueToZero()
        {
            // Make a new calculator controller
            // Enter a non-zero number
            // Click the clear button
            // Assert GetOutput() is equal to "0"

            CalculatorController calc1 = new CalculatorController();

            calc1.AcceptCharacter('1');
            calc1.AcceptCharacter('c');
            Assert.That(calc1.GetOutput(), Is.EqualTo("0"));
        }
Exemplo n.º 7
0
        private bool DoMath(char @operator)
        {
            decimal expectedResult = 0;
            Random  random         = new Random();
            decimal number1        = random.Next(0, int.MaxValue);
            decimal number2        = random.Next(0, int.MaxValue);

            switch (@operator)
            {
            case '+':
                expectedResult = number1 + number2;
                break;

            case '-':
                expectedResult = number1 - number2;
                break;

            case '*':
                expectedResult = number1 * number2;
                break;

            case '/':
                expectedResult = number1 / number2;
                break;
            }

            string mathExpression = string.Format("{0}{1}{2}=", number1.ToString(), @operator.ToString(), number2.ToString());

            foreach (char expressionChar in mathExpression)
            {
                _controller.AcceptCharacter(expressionChar);
            }

            return(Convert.ToDecimal(_controller.GetOutput()) == expectedResult);
        }
Exemplo n.º 8
0
            public void SimpleAdditionTest()
            {
                SimpleMathOperation SMO = new SimpleMathOperation();
                int operandA            = Convert.ToInt32(_controller.AcceptCharacter('3'));
                int operandB            = Convert.ToInt32(_controller.AcceptCharacter('1'));
                int result = SMO.Add(operandA, operandB);

                Assert.AreEqual(4, result);
            }
Exemplo n.º 9
0
        public void CalculatorClearButtonResetsValueToZero()
        {
            //Make a new calculator controller
            //Enter a non-zero number
            //Convert the number
            // Click clear button
            // Assert output is equals to zero

            CalculatorController calc1 = new CalculatorController();

            calc1.AcceptCharacter('5');
            // Someday, this method will reset the calculator controller to a "like-new" state.
            // I added it to the public interface of the CalculatorController class so that tests
            // can share a CalculatorController instance -- they just need to call "Clear" before
            // each test.

            calc1.AcceptCharacter('c');
            Assert.That(calc1.GetOutput(), Is.EqualTo('0'));
        }
Exemplo n.º 10
0
            public void Disable_SimpleAdditionTest()
            {
                SimpleMathOperation smo = new SimpleMathOperation();

                _controller.AcceptCharacter('3');
                int operandA = Convert.ToInt32(_controller.GetOutput());

                _controller.AcceptCharacter('1');
                // You may want to use "calc" to verify what the current state of the calculator is after you
                // enter "3" and then "1".
                int operandB = Convert.ToInt32(_controller.GetOutput());

                // This is testing the SimpleMathOperation class more than it is testing the CalculatorController
                // class.  Rather than writing a SimpleMathOperation class, try figuring out what intputs you
                // would need to give to the _controller CalculatorController instance in order to get its
                // output to be "4".
                int result = smo.Add(operandA, operandB);
                // Assert.AreEqual(4, result);   does not match assignment
            }
Exemplo n.º 11
0
 public void CanEnterSingleDigit()
 {
     Assert.That(_controller.AcceptCharacter('1'), Is.EqualTo("1"));
 }
 public void CanEnterSingleDigit()
 {
     Assert.That(_controller.AcceptCharacter('1'), Is.EqualTo("1"));
     Assert.That(_controller.AcceptCharacter('2'), Is.EqualTo("2"));
     Assert.That(_controller.AcceptCharacter('3'), Is.EqualTo("3"));
     Assert.That(_controller.AcceptCharacter('4'), Is.EqualTo("4"));
     Assert.That(_controller.AcceptCharacter('5'), Is.EqualTo("5"));
     Assert.That(_controller.AcceptCharacter('6'), Is.EqualTo("6"));
     Assert.That(_controller.AcceptCharacter('7'), Is.EqualTo("7"));
     Assert.That(_controller.AcceptCharacter('8'), Is.EqualTo("8"));
     Assert.That(_controller.AcceptCharacter('9'), Is.EqualTo("9"));
     Assert.That(_controller.AcceptCharacter('+'), Is.EqualTo("+"));
     Assert.That(_controller.AcceptCharacter('-'), Is.EqualTo("-"));
     Assert.That(_controller.AcceptCharacter('='), Is.EqualTo("="));
     Assert.That(_controller.AcceptCharacter('/'), Is.EqualTo("/"));
     Assert.That(_controller.AcceptCharacter('*'), Is.EqualTo("*"));
 }
 private void AcceptCharacters(string inputString)
 {
     foreach (char expressionChar in inputString)
     {
         _controller.AcceptCharacter(expressionChar);
     }
 }
Exemplo n.º 14
0
 public void CanClearOutput()
 {
     _controller.AcceptCharacter('C');
     Assert.That(_controller.GetOutput(), Is.Empty);
 }
        public void CanPerformSimpleMultiplication()
        {
            _controller.AcceptCharacter('5');
            _controller.AcceptCharacter('*');
            _controller.AcceptCharacter('6');

            Assert.That(_controller.GetOutput(), Is.EqualTo("30"));
        }
        public void CanPerformSimpleAddition()
        {
            _controller.AcceptCharacter('1');
            _controller.AcceptCharacter('+');
            _controller.AcceptCharacter('1');

            Assert.That(_controller.GetOutput(), Is.EqualTo("2"));
        }
Exemplo n.º 17
0
 public void BeforeEachTest()
 {
     _controller.AcceptCharacter('c');
 }
Exemplo n.º 18
0
 public void BeforeEachTest()
 {
     // Someday, this method will reset the calculator controller to a "like-new" state.
     // I added it to the public interface of the CalculatorController class so that tests
     // can share a CalculatorController instance -- they just need to call "Clear" before
     // each test.
     _controller.AcceptCharacter('c');
 }