JUnit Testing

I need an explanation for this Computer Science question to help me study.

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.

Requirements

  • Create a simple String calculator with a method int Add(string numbers)
  • 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”
  • Allow the Add method to handle an unknown amount of numbers
  • Allow the Add method to handle new lines between numbers (instead of commas).
  • The following input is ok: “1n2,3” (will equal 6)
  • Support different delimiters
  • To change a delimiter, the beginning of the string will contain a separate line that looks like this: “//[delimiter]n[numbers…]” for example “//;n1;2” should return three where the default delimiter is ‘;’ .
  • The first line is optional. All existing scenarios should still be supported
  • 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 stop here if you are a beginner.
  • Numbers bigger than 1000 should be ignored, so adding 2 + 1001 = 2
  • Delimiters can be of any length with the following format: “//[delimiter]n” for example: “//[—]n1—2—3” should return 6
  • Allow multiple delimiters like this: “//[delim1][delim2]n” for example “//[-][%]n1-2%3” should return 6.
  • Make sure you can also handle multiple delimiters with length longer than one char

Even though this is a very simple program, just looking at those requirements can be overwhelming. Let’s take a different approach. Forget what you just read and let us go through the requirements one by one.

Implement the following test cases for your String Calculator.

Requirement 1: The method can take 0, 1 or 2 numbers separated by comma (,).

Requirement 2: For an empty string the method will return 0

Requirement 3: Method will return their sum of numbers

Requirement 4: Allow the Add method to handle an unknown amount of numbers

Requirement 5: Allow the Add method to handle new lines between numbers (instead of commas).

Requirement 6: Support different delimiters

Requirement 7: Negative numbers will throw an exception

Requirement 8: Numbers bigger than 1000 should be ignored

Example: adding 2 + 1001 = 2

Requirement 9: Delimiters can be of any length

Following format should be used: “//[delimiter]n”. Example: “//[—]n1—2—3” should return 6

Requirement 10: Allow multiple delimiters

Following format should be used: “//[delim1][delim2]n”. Example “//[-][%]n1-2%3” should return 6.

Requirement 11: Make sure you can also handle multiple delimiters with length longer than one char

Zip your code in a folder called “Assignment_3”