Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

JUnit Testing

Question Description

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”

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Essay Noon only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Essay Noon are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Essay Noon are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Essay Noon, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20