Question: String Calculator The following is an exercise in unit testing code. You will need to implement the code for the string calculator specified below. You

String Calculator

The following is an exercise in unit testing code. You will need to implement the code for the string calculator specified below. You will implement unit tests in your given framework that test the correctness of your code.

Before you start:

  • Try not to read ahead.

  • Do one task at a time. The trick is to learn to work incrementally.

  • Make sure you only test for correct inputs. there is no need to test for invalid inputs for this assignment

String Calculator

  1. Create a simple StringCalculator class with a method that returns an integer called Add(string numbers)

    1. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example or 1 or 1,2.

    2. Start with the simplest test case of an empty string and move to 1 and two numbers

    3. Remember to solve things as simply as possible so that you force yourself to write tests you did not think about

    4. Remember to refactor after each passing test

  2. Allow the Add method to handle an unknown amount of numbers

  3. Calling Add with a negative number will throw an exception negatives not allowed - and the negative that was passed.if there are multiple negatives, show all of them in the exception message. There should be a test case that tests for the exception.

  4. Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2

  5. Remember that your input is one string containing 1 or more numbers separated by commas.

You will need a minimum of 4 test cases.

Using C# and MSTest Framework

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!