public void Add_Handles_Multiple_Single_Character_Delimiters() { string calcProgram = "//[*][%]\n1*2%3"; StringCalculator calc = new StringCalculator(); int result = calc.Add(calcProgram); Assert.AreEqual(6, result); }
public void Add_Handles_Multi_Character_Delimiter() { string calcProgram = "//[***]\n1***2***3"; StringCalculator calc = new StringCalculator(); int result = calc.Add(calcProgram); Assert.AreEqual(6, result); }
public void should_support_different_delimiters() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add("//:\n1:2"); //assert Assert.AreEqual(3, result); }
public void should_support_delimiters_of_any_length() { //arrange var calulator = new StringCalculator(); //act var result = calulator.Add("//[***]\n1***2***3"); //assert Assert.AreEqual(6, result); }
public void should_sum_except_bigger_than_1000() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add("2,1001"); //assert Assert.AreEqual(2, result); }
public void should_return_sum_for_any_numbers() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add("7,4,5,3,3"); //assert Assert.AreEqual(7+4+5+3+3, result); }
public void should_return_5_for_2_and_3() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add("2,3"); //assert Assert.AreEqual(5, result); }
public void should_return_0_for_empty() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add(""); //assert Assert.AreEqual(0, result); }
public void Add_Calls_Logger() { // Arrange // ========================== ILogger logger = Mock.Create<ILogger>(); Mock.Arrange(() => logger.Write(Arg.AnyString)).MustBeCalled(); StringCalculator calculator = new StringCalculator(logger); // Act // ========================== calculator.Add("1,2,3"); // Assert // ========================== Mock.Assert(logger); }
public static int Main(string[] args) { if (args == null || args.Length == 0) return 1; StringCalculator calculator = new StringCalculator(); int result = calculator.Add(args[0]); Console.WriteLine("The result is " + result); Console.WriteLine("another input please"); string input = Console.ReadLine(); while(input != null) { result = calculator.Add(input); Console.WriteLine("The result is " + result); Console.WriteLine("another input please"); input = Console.ReadLine(); } return 0; }
public void Add_Allows_Comma_Or_Newline_Delimiters() { StringCalculator calc = new StringCalculator(); int result = calc.Add("1\n2,3"); Assert.AreEqual(6, result); }
public void Add_With_Negative_Number_Includes_Number_In_Exception_Message() { StringCalculator calc = new StringCalculator(); try { int result = calc.Add("-1"); } catch (Exception exception) { Assert.IsTrue(exception.Message.Contains("-1")); } }
public void Add_With_Negative_Number_Throws_Exception() { StringCalculator calc = new StringCalculator(); int result = calc.Add("-1"); }
public void Add_SumsTwoNumbers_SeparatedByComma() { StringCalculator calc = new StringCalculator(); int result = calc.Add("1,2"); Assert.AreEqual(3, result); }
public void Add_SumsSingleNumber() { StringCalculator calc = new StringCalculator(); int result = calc.Add("1"); Assert.AreEqual(1, result); }
public void should_throw_exception_for_any_negatives() { //arrange var calculator = new StringCalculator(); //act calculator.Add("-4, 1,-1,-3,-5"); }
public void Add_Ingores_Numbers_Larger_Than_1000() { StringCalculator calc = new StringCalculator(); int result = calc.Add("2,1001"); Assert.AreEqual(2, result); }
public void should_throw_exception_for_one_negative() { //arrange var calculator = new StringCalculator(); //act calculator.Add("-1,3"); }
public void Add_DefaultDelimiterSpecifiedFirstLine() { StringCalculator calc = new StringCalculator(); int result = calc.Add("//;\n1;2"); Assert.AreEqual(3, result); }
public void Add_Logs_To_Console() { // Arrange // ========================== // Create an ILogger that writes to System.Console ConsoleLogger logger = new ConsoleLogger(); // Override the standard output stream of the Console class StringBuilder builder = new StringBuilder(); TextWriter writer = new StringWriter(builder); logger.SetOut(writer); // Create the calculator instance with the logger StringCalculator calculator = new StringCalculator(logger); // Act // ========================== calculator.Add("1,2,3"); // Assert // ========================== Assert.AreEqual(builder.ToString(), "Sum Result: 6" + Environment.NewLine); }
public void Add_SumsEmptyString() { StringCalculator calc = new StringCalculator(); int result = calc.Add(""); Assert.AreEqual(0, result); }
public void Add_SumsMultipleNumbers_SeparatedByComma() { StringCalculator calc = new StringCalculator(); int result = calc.Add("1,2,3,4"); Assert.AreEqual(10, result); }
public void Add_IWebService_Calls_Notify_With_Exception_Message_When_Logger_Throws_Exception() { // Arrange ILogger logger = Mock.Create<ILogger>(); string exceptionMessage = "Logging hath failed verily."; logger.Arrange(x => x.Write(Arg.AnyString)).Throws(new Exception(exceptionMessage)); // The web service must be called once IWebService service = Mock.Create<IWebService>(); service.Arrange(x => x.Notify(exceptionMessage)).OccursOnce(); StringCalculator calculator = new StringCalculator(logger, service); // Act calculator.Add("1,2,3"); // Assert service.AssertAll(); }
public void should_support_new_line_as_delimiter() { //arrange var calculator = new StringCalculator(); //act var result = calculator.Add("1\n2,3"); //assert Assert.AreEqual(6, result); }