public CalculationProcessTests()
 {
     var pluginReader = new OperationPluginReader();
     var operationsList = pluginReader.ReadPluginsFrom(Environment.CurrentDirectory + "\\Plugins");
     var recognizer = new BaseRecognizer(operationsList);
     calculator = new PostfixCalculator(recognizer);
 }
Example #2
0
        public void GetFullOperation_ThrowsUnrecognizedOperationException()
        {
            var moqOperation = new Mock<IOperation>();
            moqOperation.Setup(operation => operation.StringPresentation).Returns("+");
            var operationsList = new List<IOperation> {moqOperation.Object};
            IRecognizer recognizer = new BaseRecognizer(operationsList);

            Assert.Throws<UnrecognizedOperationException>(() => recognizer.GetFullOperation("-23"));
        }
Example #3
0
        public void GetFullOperation_ReturnsRecognizedOperation()
        {
            var moqOperation = new Mock<IOperation>();
            moqOperation.Setup(operation => operation.StringPresentation).Returns("+");
            var operationsList = new List<IOperation> {moqOperation.Object};
            IRecognizer recognizer = new BaseRecognizer(operationsList);

            var result = recognizer.GetFullOperation("+56");

            Assert.Equal("+",result);
        }
Example #4
0
        public void Recognize_ReturnsCorrectRecognizedOperands()
        {
            var moqFirstOperation = new Mock<IOperation>();
            moqFirstOperation.Setup(operation => operation.StringPresentation).Returns("+");
            var moqSecondOperation = new Mock<IOperation>();
            moqSecondOperation.Setup(operation => operation.StringPresentation).Returns("-");
            var operationsList = new List<IOperation> { moqFirstOperation.Object, moqSecondOperation.Object };
            IRecognizer recognizer = new BaseRecognizer(operationsList);

            var result = recognizer.Recognize("2+6-8");

            Assert.Equal(new[] { "2", "+", "6", "-", "8" }, result);
        }
Example #5
0
 static void Main()
 {
     var pluginReader = new OperationPluginReader();
     List<IOperation> operations;
     try
     {
         operations = pluginReader.ReadPluginsFrom(Environment.CurrentDirectory + "\\Plugins");
     }
     catch (DirectoryNotFoundException)
     {
         Console.WriteLine("Ошибка! Отсутсвует директория Plugins");
         Console.WriteLine("Нажмите любую клавишу, чтобы выйти...");
         Console.ReadKey();
         return;
     }
     var recognizer = new BaseRecognizer(operations);
     var calculator = new PostfixCalculator(recognizer);
     ShowAvailableOperations(calculator.GetAvailableOperations());
     var reader = new ConsoleInputReader();
     while (true)
     {
         try
         {
             var result = calculator.Calculate(reader.GetExpression());
             Console.WriteLine("Результат: {0}",result);
         }
         catch (UnrecognizedOperationException e)
         {
             Console.WriteLine(e.Message);
         }
         Console.WriteLine("Нажмите Enter, чтобы продолжить или Esc, чтобы выйти");
         if (Console.ReadKey().Key == ConsoleKey.Escape)
         {
             return;
         }
     }
 }
Example #6
0
 public void GetFullNumber_ReturnsFullNumberWithFloatingPointFromExpression()
 {
     IRecognizer recognizer = new BaseRecognizer();
     var result = recognizer.GetFullNumber("56.57rhrdhr");
     Assert.Equal("56.57",result);
 }
Example #7
0
 public void GetFullNumber_ReturnsFullNumberFromExpression()
 {
     IRecognizer recognizer = new BaseRecognizer();
     var result = recognizer.GetFullNumber("7904fss");
     Assert.Equal("7904",result);
 }