Ejemplo n.º 1
0
        public static void TestBoolCalculator()
        {
            Console.Clear();
            ICalculator <bool>      calc = new BoolCalculator();
            INumberValidator <bool> validator = new BoolValidator();
            bool value1, value2, result;

            while (true)
            {
                try
                {
                    Console.Write("Введите операцию (+ - * /): ");
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                    {
                        return;
                    }
                    char operation = key.KeyChar;
                    if (operations.IndexOf(operation) == -1)
                    {
                        Console.WriteLine("\r\nА вот и не правильно");
                        continue;
                    }
                    Console.Write("\r\nВведите 2 булевых значения (false, true, 0, 1) разделенных пробелом: ");
                    if (!validator.ValidateTwoNumbers(Console.ReadLine(), out value1, out value2))
                    {
                        Console.WriteLine("Неверный ввод. Придется повторить");
                        continue;
                    }
                    switch (operation)
                    {
                    case '+':
                        result = calc.Add(value1, value2);
                        break;

                    case '-':
                        result = calc.Add(value1, value2);
                        break;

                    case '*':
                        result = calc.Multiply(value1, value2);
                        break;

                    case '/':
                        result = calc.Divide(value1, value2);
                        break;

                    default:
                        continue;
                    }
                    Console.WriteLine($"{ value1}{ operation}{ value2}={ result}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Exception {e.GetType().Name}: {e.Message}");
                }
            }
        }
        public void ValidateBooleanToBeFalse()
        {
            // Given
            var validator = new BoolValidator(false);

            // When
            validator.BeFalse();

            // Then
            Assert.True(true);
        }
        public void ValidateBooleanToBeFalseViolated()
        {
            // Given
            var validator = new BoolValidator(true);

            // When
            var exception = Assert.Throws <XunitException>(() => validator.BeFalse(because: "that's the bottom line"));

            // Then
            Assert.NotNull(exception);
            var rn = Environment.NewLine;

            Assert.Equal(
                $"{rn}validator{rn}is \"True\"{rn}but was expected to be false{rn}because that's the bottom line",
                exception.UserMessage);
        }