示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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");
        }
示例#6
0
 public static void ShouldEqual(this string input, int expected)
 {
     var cal = new StringCalculator();
     Assert.Equal(expected, cal.Add(input));
 }