static void Main(string[] args) { try { var stringCalculator = new StringCalculator(); var result = stringCalculator.Add("//[**1]\n1**12*3"); Console.WriteLine(result); } catch (Exception e) { Console.WriteLine("Catch in main :" + e.Message); } }
public static void Main() { StringBuilder buffer = new StringBuilder(); while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { int result = StringCalculator.Add(buffer.ToString()); Console.WriteLine($"Sum = {result}"); break; } if (buffer.Length != 0) { buffer.Append('\n'); } buffer.Append(input); } }
static void Main(string[] args) { var calculator = new StringCalculator(); while (true) { Console.WriteLine("\nEnter numbers:"); var input = Console.ReadLine(); input = Regex.Unescape(input); try { var sum = calculator.Add(input); Console.WriteLine($"Sum is : {sum}"); } catch (Exception ex) { Console.WriteLine($"\nError: {ex.Message}"); } } }
public void TestAdd(string input, int expected) { // Arrange var calc = new StringCalculator(); // Act var actual = calc.Add(input); // Assert Assert.AreEqual(expected, actual); }
public void NegativeNumberThrowsException(string input, string expectMessage) { // Arrange var calc = new StringCalculator(); try { // Act calc.Add(input); } catch (Exception ex) { // Assert Assert.AreEqual(ex.Message, expectMessage); return; } Assert.Fail("Exception should be thrown"); }
public static void ShouldEqual(this string input, int expected) { var cal = new StringCalculator(); Assert.Equal(expected, cal.Add(input)); }