示例#1
0
        public static void TestIntCalculator()
        {
            Console.Clear();
            ICalculator <int>      calc = new IntCalculator();
            INumberValidator <int> validator = new IntValidator();
            int 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 целых числа разделенных пробелом: ");
                    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 Add(int a, int b)
        {
            ICalculator <int> sut = new IntCalculator();

            sut.Add(a);
            sut.Add(b);

            sut.Value.Should().Be(a + b);
        }
示例#3
0
        static void Main(string[] args)
        {
            var mikeCalc = new OneCalculatorToRuleThemAll <MikesNumbers>();

            mikeCalc.Add(new MikesNumbers("Blah"), new MikesNumbers("Foo"));

            Console.ReadLine();

            IntCalculator c = new IntCalculator();

            c.Add(5, 8);
            c.Multiply(5, 8);
            c.Subtract(5, 8);
            c.Mod(5, 8);

            FloatCalculator c2     = new FloatCalculator();
            float           result = c2.Add(5.6f, 4.3f);

            c2.Subtract(5.6f, 4.3f);

            CustomNumberCalculator c3 = new CustomNumberCalculator();
            var          num1         = new CustomNumber("Daniel");
            var          num2         = new CustomNumber("Mike");
            CustomNumber num3         = c3.Add(num1, num2);

            c3.Multiply(num1, num2);
            c3.Subtract(num1, num2);
            c3.Mod(num1, num2);



            Console.ReadLine();
        }
示例#4
0
        public void Ints()
        {
            var fixture = new Fixture();
            var sut     = new IntCalculator();

            int num = fixture.Create <int>();

            sut.Add(num);

            Assert.Equal(num, sut.Value);
        }
        public void Ints()
        {
            //arrange
            IntCalculator sut     = new IntCalculator();
            Fixture       fixture = new Fixture();
            int           num     = fixture.Create <int>();

            //act
            sut.Add(num);

            //assert
            sut.Value.Should().Be(num);
        }
        public void Integer()
        {
            //arrange
            var fixture = new Fixture();
            var sut     = new IntCalculator();
            int num     = fixture.Create <int>();

            //act

            sut.Add(num);
            //assert

            Assert.Equal(num, sut.value);
        }