public void DivisionByZero_Calculate_ReturnsException() { // arrange var basicOperation = new BasicOperation(); // act void Calculation() => basicOperation.Division(100, 0); // assert Assert.Throws <ZeroDivisorNotAllowedException>(Calculation, "Die Exception wird nicht ausgelöst!"); }
public void Division_Calculate_ReturnsQuotient() { // arrange var basicOperation = new BasicOperation(); // act var result = basicOperation.Division(100, 5); // assert Assert.That(result, Is.EqualTo(20)); }
public void Division_DivideByZero_ThrowsDivideByZeroException() { // Arrange var divisionOperation = new BasicOperation(); // act void Calculation() => divisionOperation.Division(100, 0); // Act and Assert Assert.Throws <ZeroDivisorNotAllowedException>(Calculation, "The exception doesn't occur."); }
public void Division_Calculate_ReturnsQuotient() { // Arrange var divisionOperation = new BasicOperation(); // Act var result = divisionOperation.Division(12, 6); // Assert Assert.That(result, Is.EqualTo(2)); }
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(); }