public void Divide_ValidNumbers_CorrectPercentage(string inputString, decimal expectedResult) { var sut = new StringCalculator(); var result = sut.Divide(inputString); result.Should().Be(expectedResult); }
public static void TestStringCalculator() { Console.Clear(); ICalculator <string> calc = new StringCalculator(); INumberValidator <string> validator = new StringValidator(); string 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 Test_CalculatorServiceStretch05_Divide(string caclString, double expected) { // Arrange var svc = new CalculatorServiceReq08(); var calc = new StringCalculator(svc); // Act var actual = calc.Divide(caclString); // Assert Assert.AreEqual(actual, expected, 0.001, "calc"); }