Beispiel #1
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();
        }
        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));
        }