Exemplo 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;
                }
            }
        }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo 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);
 }
Exemplo n.º 7
0
 public void TestingWithoutOp()
 {
     string input = "5";
     Calculator thisCalc = new Calculator();
     string AdditionAns = thisCalc.Calculate(input);
 }
Exemplo n.º 8
0
 public void TestingCalculatorSub()
 {
     string input = "12 - 2";
     Calculator thisCalc = new Calculator();
     string SubtractionAns = thisCalc.Calculate(input);
     Assert.AreEqual("10", SubtractionAns);
 }
Exemplo n.º 9
0
 public void TestingCalculatorMulti()
 {
     string input = "4 * 2";
     Calculator thisCalc = new Calculator();
     string MultiplicationAns = thisCalc.Calculate(input);
     Assert.AreEqual("8", MultiplicationAns);
 }
Exemplo n.º 10
0
 public void TestingCalculatorModulation()
 {
     string input = "11 % 2";
     Calculator thisCalc = new Calculator();
     string ModAns = thisCalc.Calculate(input);
     Assert.AreEqual("1", ModAns);
 }
Exemplo n.º 11
0
 public void TestingCalculatorDiv()
 {
     string input = "4 / 2";
     Calculator thisCalc = new Calculator();
     string DivisionAns = thisCalc.Calculate(input);
     Assert.AreEqual("2", DivisionAns);
 }
Exemplo n.º 12
0
 public void TestingCalculatorAddition()
 {
     string input = "4 + 2";
     Calculator thisCalc = new Calculator();
     string AdditionAns = thisCalc.Calculate(input);
     Assert.AreEqual("6", AdditionAns);
 }
Exemplo n.º 13
0
 public void test_substitute()
 {
     //arrange
     const string input = "//;\n1;2";
     var delim = Substitute.For<IDelimiterExtractor>();
     delim.GetDelimiters(input).Returns(new[] { ";" });
     //act
     var res = new Calculator().Add(input);
     //assert
     res.Should().Be(3);
 }
Exemplo n.º 14
0
        private void BtMin_Click(object sender, EventArgs e)
        {
            Calculator Calculator = new Calculator();

            tbUitkomst.Text = Convert.ToString(Calculator.Subtract(Convert.ToDouble(tbGetal1.Text), Convert.ToDouble(tbGetal2.Text)));
        }
Exemplo n.º 15
0
        private void Button2_Click(object sender, EventArgs e)
        {
            Calculator Calculator = new Calculator();

            tbUitkomst.Text = Convert.ToString(Calculator.Square(Convert.ToDouble(tbGetal1.Text)));
        }