Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between a list broker and a list manager?

Answered: 1 week ago