public void RunAllSwitchBranches_Tests()
        {
            var inputStrings = new StringBuilder();

            inputStrings.AppendLine("0 + 0");
            inputStrings.AppendLine("MC");
            inputStrings.AppendLine("help");
            inputStrings.AppendLine("asdasdas");
            inputStrings.AppendLine("0 / 0");
            inputStrings.AppendLine("exit");
            var outputStrings = new StringBuilder();

            outputStrings.AppendLine(ConsoleMessages.Greeting.Description);
            outputStrings.AppendLine("Результат: 0");
            outputStrings.AppendLine("Память: 0");
            outputStrings.AppendLine(ConsoleMessages.Help.Description);
            outputStrings.AppendLine(ConsoleMessages.InvalidInput.Description);
            outputStrings.AppendLine(ConsoleMessages.DivisionByZero.Description);
            var input  = new StringReader(inputStrings.ToString());
            var output = new StringWriter();

            Console.SetIn(input);
            Console.SetOut(output);
            var calculator = new ConsoleCalculator();

            Assert.That(calculator.Run, Throws.Nothing);
            Assert.AreEqual(outputStrings.ToString(), output.ToString());
        }
        public void NoElementCommand_Test()
        {
            var calculator   = new ConsoleCalculator();
            var actualResult = calculator.ParseString("");

            Assert.AreEqual(ResultStatus.InvalidInput, actualResult);
        }
        public void MoreThanThreeElementCommand_Test(string str, ResultStatus expectedResult)
        {
            var calculator   = new ConsoleCalculator();
            var resultStatus = calculator.ParseString(str);

            Assert.AreEqual(expectedResult, resultStatus);
        }
        public void DoubleOrCommandEmptyArrs_Test()
        {
            var result       = new bool[0];
            var parcedStr    = new string[0];
            var actualResult = ConsoleCalculator.DoubleOrCommandDecider(result, parcedStr);

            Assert.AreEqual(ResultStatus.OK, actualResult);
        }
        public void SplitStringManyElements_Test()
        {
            var actualResult   = ConsoleCalculator.SplitString("5 + 2 + 6 + 7 + 8 + 9");
            var expectedResult = new string[] { "5", "+", "2" };

            Assert.AreEqual(3, actualResult.Length);
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void SplitStringTwoElements_Test()
        {
            var actualResult   = ConsoleCalculator.SplitString("5 +");
            var expectedResult = new string[] { "5", "+" };

            Assert.AreEqual(2, actualResult.Length);
            Assert.AreEqual(expectedResult, actualResult);
        }
        public void DoubleOrCommandAsCommand_Test()
        {
            var result       = new bool[] { false };
            var parcedStr    = new string[] { "exit" };
            var actualResult = ConsoleCalculator.DoubleOrCommandDecider(result, parcedStr);

            Assert.AreEqual(ResultStatus.OK, actualResult);
            Assert.AreEqual(new bool[] { false }, result);
        }
        public void RunEnds_Tests()
        {
            var input = new StringReader("Exit");

            Console.SetIn(input);
            var calculator = new ConsoleCalculator();

            Assert.That(calculator.Run, Throws.Nothing);
        }
        public void ThreeElementIncorrectCommand_Test(string input, ResultStatus expectedResult)
        {
            var calculator   = new ConsoleCalculator();
            var resultStatus = calculator.ParseString(input);
            var expOperation = CalculatorOperators.Add;

            Assert.AreEqual(expectedResult, resultStatus);
            Assert.AreEqual(expOperation, calculator.Operator);
        }
        public void DoubleOrCommandMixedResult_Test()
        {
            var result       = new bool[] { false, false, false, false };
            var parcedStr    = new string[] { "exit", "help", "0", "68465.41354138" };
            var actualResult = ConsoleCalculator.DoubleOrCommandDecider(result, parcedStr);

            Assert.AreEqual(ResultStatus.OK, actualResult);
            Assert.AreEqual(new bool[] { false, false, true, true }, result);
        }
        public void FullConstructor_Test()
        {
            var calculator = new ConsoleCalculator(5, 1, 2, 3, CalculatorOperators.Substract);

            Assert.AreEqual(5, calculator.Memory);
            Assert.AreEqual(1, calculator.Result);
            Assert.AreEqual(2, calculator.Operand1);
            Assert.AreEqual(3, calculator.Operand2);
            Assert.AreEqual(CalculatorOperators.Substract, calculator.Operator);
        }
        public void DoOperationExisting_Test()
        {
            var operand1     = 3;
            var operand2     = 4;
            var calculator   = new ConsoleCalculator(1, 2, operand1, operand2, CalculatorOperators.Add);
            var actualResult = calculator.DoOperation();

            Assert.AreEqual(operand1 + operand2, calculator.Result);
            Assert.AreEqual(ResultStatus.OK, actualResult);
        }
        public void EmptyConstructor_Test()
        {
            var calculator = new ConsoleCalculator();

            Assert.AreEqual(0, calculator.Memory);
            Assert.AreEqual(0, calculator.Result);
            Assert.AreEqual(0, calculator.Operand1);
            Assert.AreEqual(0, calculator.Operand2);
            Assert.AreEqual(CalculatorOperators.Add, calculator.Operator);
        }
        public void TwoElementCorrectCommand_Test(string input, double memoryField, double resultField, ResultStatus expectedResult, string expectedOperation, double expectedOp2)
        {
            var calculator   = new ConsoleCalculator(memoryField, resultField, 0, 0, CalculatorOperators.Add);
            var resultStatus = calculator.ParseString(input);
            var expOperation = CalculatorOperators.FromString(expectedOperation);

            Assert.AreEqual(expectedResult, resultStatus);
            Assert.AreEqual(expOperation, calculator.Operator);
            Assert.AreEqual(resultField, calculator.Operand1);
            Assert.AreEqual(expectedOp2, calculator.Operand2);
        }
        public void PrintErrorMessage_Test()
        {
            var output = new StringWriter();

            Console.SetOut(output);
            ConsoleCalculator.PrintErrorMessage(ConsoleMessages.DivisionByZero);
            var winStyleEquals = output.ToString().Equals(ConsoleMessages.DivisionByZero + "\r\n");
            var linStyleEquals = output.ToString().Equals(ConsoleMessages.DivisionByZero + "\n");

            Assert.That(winStyleEquals || linStyleEquals);
        }
        public void SplitStringErrorMessage_Test()
        {
            var inputStrings = new StringBuilder();

            inputStrings.AppendLine("0 + 0 + 2");
            inputStrings.AppendLine("exit");
            var outputStrings = new StringBuilder();

            outputStrings.AppendLine(ConsoleMessages.Greeting.Description);
            outputStrings.AppendLine(ConsoleMessages.ToBigInput.Description);
            outputStrings.AppendLine("0 + 0");
            outputStrings.AppendLine("Результат: 0");
            var input  = new StringReader(inputStrings.ToString());
            var output = new StringWriter();

            Console.SetIn(input);
            Console.SetOut(output);
            var calculator = new ConsoleCalculator();

            Assert.That(calculator.Run, Throws.Nothing);
            Assert.AreEqual(outputStrings.ToString(), output.ToString());
        }
        public void SplitStringEmptyString_Test()
        {
            var actualResult = ConsoleCalculator.SplitString("").Length;

            Assert.AreEqual(0, actualResult);
        }
        public void SplitStringLongString_Test()
        {
            var actualResult = ConsoleCalculator.SplitString("gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg")[0].Length;

            Assert.AreEqual(80, actualResult);
        }
        public void SplitStringManySpacers_Test()
        {
            var actualResult = ConsoleCalculator.SplitString("   5   +    5     ").Length;

            Assert.AreEqual(3, actualResult);
        }
        public void StrToDouble_Test(string str, string operatorName)
        {
            var actualResult = ConsoleCalculator.StrToOperator(str).Name;

            Assert.AreEqual(operatorName, actualResult);
        }
        public void StrToDouble_Test(string str, double expectedResult)
        {
            var actualResult = ConsoleCalculator.StrToDouble(str);

            Assert.AreEqual(expectedResult, actualResult);
        }