Esempio n. 1
0
        static void Main(string[] args)
        {
            // new counter for program
            Counter thisCounterInst = new Counter();

            // boolean for running program and breaking out of while loop
            bool isRunning = true;

            // while bool = true, run this loop
            while (isRunning)
            {
                // writing the counter
                Console.Write("[" + thisCounterInst.CountValue + "]");

                // accepting the input
                string input = Console.ReadLine();

                // validating that syntax is right and not exiting loop
                ValidInputs validating = new ValidInputs();
                bool ValidateResult = validating.BreakingLoop(input);

                // if not valid result, exit loop
                if (ValidateResult == false)
                {
                    isRunning = false;
                    break;
                }
                else
                {
                    // other wise, valid result -- new Calculator instance
                    Calculator CalculatorInstance = new Calculator();

                    if (input == "lastq" || input == " lastq")
                    {
                        // show the last question
                        Console.WriteLine(LastQnA.LastQ);
                    }
                    else if (input == "last" || input == " last")
                    {
                        // show last answer
                        Console.WriteLine(LastQnA.LastAns);
                    }
                    else
                    {
                        // new calculator instance and begin calculation
                        int thisAnswer = CalculatorInstance.Calculate(input);
                        Console.WriteLine(thisAnswer);
                    }

                    // increment counter
                    thisCounterInst.CountValue = thisCounterInst.Count + 1;
                }
            }
        }
Esempio n. 2
0
 public void UsingConstantSubtraction()
 {
     Constants.AddKey2Dictionary("e", 11);
     string input = "e - 2";
     Calculator thisCalc = new Calculator();
     string ConstSubtractionAns = thisCalc.Calculate(input);
     Assert.AreEqual("9", ConstSubtractionAns);
 }
Esempio n. 3
0
 public void UsingConstantMultiplication()
 {
     Constants.AddKey2Dictionary("d", 9);
     string input = "d * 2";
     Calculator thisCalc = new Calculator();
     string ConstMultiAns = thisCalc.Calculate(input);
     Assert.AreEqual("18", ConstMultiAns);
 }
Esempio n. 4
0
 public void UsingConstantModulus()
 {
     Constants.AddKey2Dictionary("b", 16);
     string input = "b % 2";
     Calculator thisCalc = new Calculator();
     string ConstModulusAns = thisCalc.Calculate(input);
     Assert.AreEqual("0", ConstModulusAns);
 }
Esempio n. 5
0
 public void UsingConstantDivision()
 {
     Constants.AddKey2Dictionary("c", 8);
     string input = "c / 2";
     Calculator thisCalc = new Calculator();
     string ConstDivisionAns = thisCalc.Calculate(input);
     Assert.AreEqual("4", ConstDivisionAns);
 }
Esempio n. 6
0
 public void UsingConstantAddition()
 {
     Constants.AddKey2Dictionary("a", 10);
     string input = "a + 2";
     Calculator thisCalc = new Calculator();
     string ConstAdditionAns = thisCalc.Calculate(input);
     Assert.AreEqual("12", ConstAdditionAns);
 }
Esempio n. 7
0
 public void TestingWithoutOp()
 {
     string input = "5";
     Calculator thisCalc = new Calculator();
     string AdditionAns = thisCalc.Calculate(input);
 }
Esempio n. 8
0
 public void TestingCalculatorSub()
 {
     string input = "12 - 2";
     Calculator thisCalc = new Calculator();
     string SubtractionAns = thisCalc.Calculate(input);
     Assert.AreEqual("10", SubtractionAns);
 }
Esempio n. 9
0
 public void TestingCalculatorMulti()
 {
     string input = "4 * 2";
     Calculator thisCalc = new Calculator();
     string MultiplicationAns = thisCalc.Calculate(input);
     Assert.AreEqual("8", MultiplicationAns);
 }
Esempio n. 10
0
 public void TestingCalculatorModulation()
 {
     string input = "11 % 2";
     Calculator thisCalc = new Calculator();
     string ModAns = thisCalc.Calculate(input);
     Assert.AreEqual("1", ModAns);
 }
Esempio n. 11
0
 public void TestingCalculatorDiv()
 {
     string input = "4 / 2";
     Calculator thisCalc = new Calculator();
     string DivisionAns = thisCalc.Calculate(input);
     Assert.AreEqual("2", DivisionAns);
 }
Esempio n. 12
0
 public void TestingCalculatorAddition()
 {
     string input = "4 + 2";
     Calculator thisCalc = new Calculator();
     string AdditionAns = thisCalc.Calculate(input);
     Assert.AreEqual("6", AdditionAns);
 }