예제 #1
0
        public void ShouldCalculateProperly()
        {
            var calc = new Calculator.Calculator();

            Assert.AreEqual(0, calc.getResult());
            calc.executeOperation("+", new int[] {7 });
            Assert.AreEqual(7, calc.getResult());
            calc.executeOperation("-", new int[] { 15 });
            Assert.AreEqual(-8, calc.getResult());
        }
예제 #2
0
        static void Main(string[] args)
        {
            var calc = new Calculator();

            Console.WriteLine("Input your operations: operator first, then operands, divided by whitespace");
            Console.WriteLine("Avialable operations are:");
            foreach (var op in calc.getAvialableOperators())
                Console.WriteLine("   " + op);
            Console.WriteLine("For exit - type \"quit\"");

            Console.WriteLine("\nCurrent result = " + calc.getResult());

            CalculatorOperation operation;
            while (true)
            {
                operation = parseCalculatorOperation(Console.ReadLine());
                if (operation.opName.Equals("quit"))
                {
                    Console.WriteLine("\nBye-bye!");
                    break;
                }
                calc.executeOperation(operation.opName, operation.operands);
                Console.WriteLine("Current result = " + calc.getResult());
            }

            Console.ReadKey();
        }
예제 #3
0
 public void ShouldThrowOnUnknownOperator()
 {
     try
     {
         var calc = new Calculator.Calculator();
         calc.executeOperation("*", new int[] { 2 });
     }
     catch (Exception exc)
     {
         Assert.AreEqual("Operator \"*\" unknown!\r\nParameter name: operatorName", exc.Message);
     }
 }
예제 #4
0
 public void ShouldThrowOnNullOperandsForNonNullOperator()
 {
     try
     {
         var calc = new Calculator.Calculator();
         calc.executeOperation("+", null);
     }
     catch (Exception exc)
     {
         Assert.AreEqual("Operator \"+\" requires non-empty operands list!\r\nParameter name: operands", exc.Message);
     }
 }
예제 #5
0
 public void ShouldThrowOnInsufficientOperandsNumber()
 {
     try
     {
         var calc = new Calculator.Calculator();
         calc.executeOperation("+", new int[] { });
     }
     catch (Exception exc)
     {
         Assert.AreEqual("operands\r\nParameter name: Operator \"+\" requires 1operands, while only 0 presented!", exc.Message);
     }
 }