Question: Write the test cases for the following function. Assume we have a SimpleParser class (shown below) that we would like to test. It has a

Write the test cases for the following function.

Assume we have a SimpleParser class (shown below) that we would like to test. It has a method named ParseAndSum that takes in a string of 0 or more comma-separated numbers. If there are no numbers, it returns 0. If there is a single number, it returns that numbers as an int. If there are multiple numbers, it adds them all up and returns the sum (although, right now, the code can only handle 0 or 1 number).

public class SimpleParser

{

public int ParseAndSum(string numbers)

{

if (numbers_Length==0)

{

return 0;

}

if (!numbers_Contains(","))

{

return int.Parse(numbers);

}

else

{

throw new InvalidOperationException( "I can only handle 0 or 1 numbers for now!");

}

}

}

Task:

Complete the implementation to make it capable of adding multiple numbers all up and return the sum.

Write test cases to fully test the functionality, cover all branches of your implementation.

(note: this is not a programming language test, implementation written in pseudo-code is acceptable)

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!