Ejemplo n.º 1
0
 public void CanNotDivideByZero()
 {
     _controller.AcceptCharacter('5');
     _controller.AcceptCharacter('/');
     _controller.AcceptCharacter('0');
     _controller.AcceptCharacter('=');
     Assert.That(_controller.GetOutput(), Is.EqualTo("Division by 0"));
 }
        public void CanPerformSimpleAddition()
        {
            _controller.AcceptCharacter('1');
            _controller.AcceptCharacter('+');
            _controller.AcceptCharacter('1');

            Assert.That(_controller.GetOutput(), Is.EqualTo("2"));
        }
Ejemplo n.º 3
0
 public void CanEnterSingleDigit()
 {
     for (int a = 0; a <= 9; a++)
     {
         _controller.AcceptCharacter((char)a);
         Assert.That(_controller.GetOutput(), Is.EqualTo(a.ToString(CultureInfo.InvariantCulture)));
     }
 }
Ejemplo n.º 4
0
 public void CanEnterSingleDigit()
 {
     for (int i = 0; i < 9; i++)
     {
         _controller.AcceptCharacter((char)i);
         Assert.That(_controller.GetOutput(), Is.EqualTo(i.ToString()));
     }
 }
        public void CanPerformSimpleMultiplication()
        {
            _controller.AcceptCharacter('5');
            _controller.AcceptCharacter('*');
            _controller.AcceptCharacter('6');

            Assert.That(_controller.GetOutput(), Is.EqualTo("30"));
        }
Ejemplo n.º 6
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 CanEnterMultipleDigits()
        {
            _controller.AcceptCharacter('1');
            _controller.AcceptCharacter('3');

            // An example of a constraint other than "Is"  In this case, the Substring() method of the
            // "Contains" class returns a constraint that requires that the value being tested contain the
            // substring "3".
            Assert.That(_controller.GetOutput(), Contains.Substring("3"));
            Assert.That(_controller.GetOutput(), Is.EqualTo("13"));
        }
        public void CalculatorStartsOffShowingZero()
        {
            // Make a new calculator controller
            // Check that GetOutput() is equal to "0"

            CalculatorController calc1 = new CalculatorController();

            // The two following lines are equivalent.  One uses the "constraints" model, and one uses the "static test assertions" model.
            Assert.That(calc1.GetOutput(), Is.EqualTo("0")); // Google "NUnit constraints"
            Assert.AreEqual(calc1.GetOutput(), "0");         // Google "NUnit static test assertions"

            // In this class, we will prefer the constraints-based approach, as it reads more like English and gives more detailed
            // and precise failure messages.
            // It also avoids the ambiguity as to which parameters is the "expected" result and which is the "actual" result.
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        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('4');
            Assert.That(calc1.GetOutput(), Is.EqualTo("4"));
            calc1.AcceptCharacter('2');
            Assert.That(calc1.GetOutput(), Is.EqualTo("42"));
            calc1.AcceptCharacter('c');
            Assert.That(calc1.GetOutput(), Is.EqualTo("0"));
        }
Ejemplo n.º 11
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;      // this will fail if the combination of the two numbers is > int.MaxValue
                break;

            case '-':
                expectedResult = number1 - number2;       // this does not test any subtraction where the first number is negative
                break;

            case '*':
                expectedResult = number1 * number2;       // will fail if overflow
                break;

            case '/':
                expectedResult = number1 / number2;       // will fail if number2 is zero
                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);
        }
Ejemplo n.º 12
0
 public void CanNotDivideByZero()
 {
     _controller.AcceptCharacter('5');
     _controller.AcceptCharacter('/');
     _controller.AcceptCharacter('0');
     _controller.AcceptCharacter('=');
     Assert.That(_controller.GetOutput(), Is.EqualTo("Divide by Zero"));  // modified string
 }
Ejemplo n.º 13
0
        public void CalculatorStartsOffShowingZero()
        {
            //make a new calculator controller
            CalculatorController calc1 = new CalculatorController();

            //check that GetOutput() is equal to "o"
            Assert.That(calc1.GetOutput(), Is.EqualTo("0")); //Google "NUnit constraints"
            // or Assert.AreEqual(calc1.GetOutput(), "0");
        }
Ejemplo n.º 14
0
        public void CanEnterMultipleDigits()
        {
            Random random  = new Random();
            var    aNumber = random.Next(0, int.MaxValue).ToString();//as a string

            foreach (char thisCharacter in aNumber)
            {
                _controller.AcceptCharacter(thisCharacter);
                Assert.That(_controller.GetOutput(), Is.EqualTo(aNumber));
            }
        }
        public void DigitsAreAddedToTheRightOfTheCurrentValue()
        {
            // Abstract idea in English:
            // When I enter "1" and then "3" and then "7", the calculator displays "1" and then "13" and then "137".

            // Psedocode, often following the "when I/then" paradigm
            // When I: enter "1"
            // Then: the calculator should say "1"
            // When I: enter "3"
            // Then: the calculator should say "13"
            // When I: enter "7"
            // Then: the calculator should say "137"

            // Actual test code, where each line (approximately) corresponds to a line of the pseudocode
            EnterNumber(1);
            Assert.That(_controller.GetOutput(), Is.EqualTo("1"));
            EnterNumber(3);
            Assert.That(_controller.GetOutput(), Is.EqualTo("13"));
            EnterNumber(7);
            Assert.That(_controller.GetOutput(), Is.EqualTo("137"));
        }
Ejemplo n.º 16
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
            }
Ejemplo n.º 17
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'));
        }
Ejemplo n.º 18
0
 protected void AssertOutput(string expectedOutput)
 {
     Assert.That(_controller.GetOutput(), Is.EqualTo(expectedOutput));
 }
Ejemplo n.º 19
0
 public void CanEnterSingleDigit()
 {
     _controller.AcceptCharacter('1');
     Assert.That(_controller.GetOutput(), Is.EqualTo("1"));
 }
        public void CalculatorClearButtonResetsValue()
        {
            CalculatorController calc1 = new CalculatorController();

            Assert.That(calc1.GetOutput(), Is.EqualTo("0"));
        }
        public void CalculatorStartOffShowingZero()
        {
            CalculatorController calc1 = new CalculatorController();

            Assert.That(calc1.GetOutput(), Is.EqualTo("0"));
        }
Ejemplo n.º 22
0
 public void InitialStateIsZero()
 {
     Assert.That(_controller.GetOutput(), Is.EqualTo("0"));
 }
Ejemplo n.º 23
0
 public void CanClearOutput()
 {
     _controller.AcceptCharacter('C');
     Assert.That(_controller.GetOutput(), Is.Empty);
 }