public void DoesEquationHaveaddintionSign()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20+5");
     var expected = '+'; ;
     Assert.AreEqual(expected, calc.GetOperator("+"));
 }
 public void DoesEquationHaveDivisionSign()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20/5");
     var expected = '/'; ;
     Assert.AreEqual(expected, calc.GetOperator("/"));
 }
 public void DoesEquationHaveModulusSign()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20%5");
     var expected = '%'; ;
     Assert.AreEqual(expected, calc.GetOperator("%"));
 }
Example #4
0
 public void SaveConstant(char key, int value )
 {
     Parse parse = new Parse();
         Stack stack = new Stack();
     string input = null;
     parse.ExtractConstant(input);
         stack.SaveConstant(parse.ConstantKey, parse.ConstantValue);
 }
Example #5
0
        //Evaluate
        public string Calculuate(string input)
        {
            /*  if (input.Contains("="))
            {
                Parse.ExtractCharacter();
              //  string letter = "a";
                //return letter;
            }
            */
                if (input == "lastq")
            {
                if (Stack.lastQuestion == null)
                {
                    return "No Operation entered";
                }
                return Stack.lastQuestion;
            }
            else if (input == "last")
            {
                if (Stack.lastQuestion == null)
                {
                    return "No Operation entered";
                }
                return Stack.last;
            }

            else
            {
                Parse parse = new Parse();
                var operans = parse.GetNumbers(input);
                var op = parse.GetOperator(input);
                var result = 0;

                switch (op)
                {
                    case '+':
                        result = Addition.AddNum(operans);
                        break;
                    case '-':
                        result = Subtraction.SubNum(operans);
                        break;
                    case '*':
                        result = Multiplication.MultiplyNum(operans);
                        break;
                    case '/':
                        result = Division.DivideNum(operans);
                        break;
                    case '%':
                        result = Modulus.ModNum(operans);
                        break;
                    default:
                        throw new ArgumentException("incorrect format");
                }
                Stack.last = result.ToString();
                Stack.lastQuestion = input;
                return result.ToString();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            int x = 0;
            while (true)

            {
                Console.WriteLine("[" + x + "]>");
                string input = Console.ReadLine();
                Evaulate eval = new Evaulate();
                Parse parse = new Parse();
                Stack stack = new Stack();

                        if (input.ToLower() == "exit" || input.ToLower() == "quit")
                            break;
                    try
                    {
                    var result = eval.Calculuate(input);
                    Console.WriteLine("   = " + result);

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);

                }

                try
                {
                    if (input.Contains("="))
                    {
                        parse.ExtractConstant(input);
                        stack.SaveConstant(parse.ConstantKey, parse.ConstantValue);
                    }
                    else
                    {
                        parse.ExtractValue(input);
                        eval.Calculuate(Convert.ToInt32(input[0]), Convert.ToInt32(input[1]));
                    }
                }
                catch (System.ArgumentException)
                {
                    Console.WriteLine("You made a syntax error");
                }

                x++;
                    }

                Console.WriteLine("Goodbye, Mr Bond!");
                Task.Delay(TimeSpan.FromSeconds(2)).Wait();
        }
Example #7
0
        public int ExtractValue(string input)
        {
            if (input.Contains('='))
            {
                Parse parse = new Parse();
                var splitInput = input.Split('=');    //splitInput looks something like ['x', '13']

                return int.Parse(splitInput[1]);
            }

                ///Tryparse
            /// public static bool TryParse(
            //string input,
            ///out int result

               return Convert.ToInt32(input[0]);
        }
 public void DoesEquationHaveOperators()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20+5");
     var expected = '+';
     Assert.AreEqual(expected, op);
 }
        public void UserCanGetACostantValueViaString()
        {
            //Arrange
            string input = "a=15";
            Parse parse = new Parse();
            var constants = new Constants();
            Char key = parse.ExtractConstant(input);
            int value = parse.ExtractConstant(input);
            var splitInput = input.Split('=');
            constants.setConstant(key, value);

            //ACT
            int valueExtracted = constants.getConstant(key);

            //Assert
            Assert.AreEqual(value, valueExtracted);
        }
 public void DoesEquationHaveMultiplicationSign()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20*5");
     var expected = '*'; ;
     Assert.AreEqual(expected, calc.GetOperator("*"));
 }
 public void DoesEquationHaveNumbers()
 {
     var calc = new Parse();
     var numb = calc.GetNumbers("20+5");
     var expected = new string[] { "20", "5" };
     CollectionAssert.AreEqual(expected, numb);
 }
 public void GetNumbersShouldReturnTwoStrings()
 {
     var calc = new Parse();
     var stringArray = calc.GetNumbers("12+16");
     var expected = new string[] { "12", "16" };
     CollectionAssert.AreEqual(stringArray, expected);
 }
 public void DoesEquationHaveSubtractionSign()
 {
     var calc = new Parse();
     var op = calc.GetOperator("20-5");
     var expected = '-'; ;
     Assert.AreEqual(expected, calc.GetOperator("-"));
 }
 public void IsNumberInIndexOne()
 {
     Parse parse = new Parse();
     string[] indexOne = parse.GetNumbers("5+8");
     Assert.AreEqual("8", indexOne[1]);
 }
        public void UserCanSetACostantValueViaString()
        {
            //Arrange
            string input = "a=15";
            Parse parse = new Parse();
            var constants = new Constants();
            char key = parse.ExtractConstant(input);
            int value = parse.ExtractValue(input);
            var splitInput = input.Split('=');

            //ACT
            constants.setConstant(key, value);

            //Assert
            Assert.IsTrue(constants.calculatorConstants.ContainsKey(key));
            Assert.IsTrue(constants.calculatorConstants.ContainsValue(value));
        }
        public void IsNumberInIndexZero()
        {
            Parse parse = new Parse();

            string[] indexZero = parse.GetNumbers("5+8");
            Assert.AreEqual("5", indexZero[0]);
        }
 public void UserCanEnterAConstant()
 {
     var calc = new Parse();
        // var constant = calc.GetConstant("a");
     var expected = 'a';
       // Assert.AreEqual(expected, constant);
 }
 public void ShouldGetOperators()
 {
     var calc = new Parse();
     var op = calc.GetOperator("12-8");
     var expected = '-';
     Assert.AreEqual(expected, op);
 }