Esempio n. 1
0
        public void Multiplication_Calculate_ReturnsProduct()
        {
            // arrange
            var basicOperation = new BasicOperation();

            // act
            var result = basicOperation.Multiplication(100, 3);

            // assert
            Assert.That(result, Is.EqualTo(300));
        }
        public void Multiplication_Calculate_ReturnsProduct()
        {
            // Arrange
            var multiplicationOperation = new BasicOperation();

            // Act
            var result = multiplicationOperation.Multiplication(6, 6);

            // Assert
            Assert.That(result, Is.EqualTo(36));
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var basicOperations = new BasicOperation();

            Console.WriteLine("#######################################################");
            Console.WriteLine("# Hi, I'm your Test Application for MathLibrary Light #");
            Console.WriteLine("#######################################################");
            Console.WriteLine();

            // **********************************************************************************************
            // Test Addition
            // **********************************************************************************************
            Console.WriteLine("Try to test Method 'Addition'");
            var additionResult    = basicOperations.Addition(2, 3);
            var additionOperation = $"Result: '2 + 3 = {additionResult}'";

            if (additionResult == 5)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{additionOperation}{TEXT_IS_CORRECT}");
                Console.WriteLine(TEXT_TEST_PASSED);
                Console.ResetColor();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"{additionOperation}{TEXT_IS_WRONG}");
                Console.WriteLine(TEXT_TEST_FAILED);
                Console.ResetColor();
            }

            // **********************************************************************************************
            // Test Subtraction
            // **********************************************************************************************
            Console.WriteLine("Try to test Method 'Subtraction'");
            var subtractionResult    = basicOperations.Subtraction(20, 5);
            var subtractionOperation = $"Result: '20 - 5 = {subtractionResult}'";

            if (subtractionResult == 15)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{subtractionOperation}{TEXT_IS_CORRECT}");
                Console.WriteLine(TEXT_TEST_PASSED);
                Console.ResetColor();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"{subtractionOperation}{TEXT_IS_WRONG}");
                Console.WriteLine(TEXT_TEST_FAILED);
                Console.ResetColor();
            }

            // **********************************************************************************************
            // Test Division
            // **********************************************************************************************
            Console.WriteLine("Try to test Method 'Division'");
            var divisionResult    = basicOperations.Division(100, 5);
            var divisionOperation = $"Result: '100 / 5 = {divisionResult}'";

            if (divisionResult == 20)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{divisionOperation}{TEXT_IS_CORRECT}");
                Console.WriteLine(TEXT_TEST_PASSED);
                Console.ResetColor();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"{divisionOperation}{TEXT_IS_WRONG}");
                Console.WriteLine(TEXT_TEST_FAILED);
                Console.ResetColor();
            }

            // **********************************************************************************************
            // Test Division by zero
            // **********************************************************************************************
            Console.WriteLine("Try to test Method 'Division' by zero");

            try
            {
                basicOperations.Division(100, 0);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(TEXT_TEST_FAILED);
                Console.ResetColor();
            }
            catch (ZeroDivisorNotAllowedException)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(TEXT_TEST_PASSED);
                Console.ResetColor();
            }

            // **********************************************************************************************
            // Test Multiplication
            // **********************************************************************************************
            Console.WriteLine("Try to test Method 'Multiplication'");
            var multiplicationResult    = basicOperations.Multiplication(5, 10);
            var multiplicationOperation = $"Result: '5 * 10 = {multiplicationResult}'";

            if (multiplicationResult == 50)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{multiplicationOperation}{TEXT_IS_CORRECT}");
                Console.WriteLine(TEXT_TEST_PASSED);
                Console.ResetColor();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"{multiplicationOperation}{TEXT_IS_WRONG}");
                Console.WriteLine(TEXT_TEST_FAILED);
                Console.ResetColor();
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadLine();
        }