CS210 Lab 3

Bob Wilson

 

Junit TestCase for Lab 2 QuadraticSolver Class

 

You previously developed a QuadraticSolver class that purportedly solves all quadratic equations of the form:

 

            a x2 + b x + c = 0

 

for all values of x that make the equation true, if any.  These are called the root(s) of the equation.

 

The QuadraticSolver class uses formulas such as this one (and others) that gives us values of x based on the coefficients a, b, and c:

 

       x = (-b + square root (b2 – 4ac))/2a

 

In this lab, you need to write a child class of the junit.framework.TestCase class to run all of the following test cases.  The junit.framework code will handle all the execution of the test cases and display of the results, e.g. green bars, etc.   Naturally, your program must properly select and execute the correct calculation for any supplied values of a, b, and c.  However, here are six test cases that each force your program to select one of the six different possible calculations with the format of the solution that your program should provide for that case.

 

Value for a

Value for b

Value for c

Solution for some possible test cases

Should return exactly this string in each case!

1

0

-3

Root 1 is 1.7320508075688772

Root 2 is -1.7320508075688772

1

1

1

Root 1 is -0.5 + i * 0.8660254037844386

Root 2 is -0.5 - i * 0.8660254037844386

1

2

1

The only root is -1.0

0

2

4

The only root is -2.0

0

0

6

No value for x is a solution

0

0

0

Any value for x is a solution

 

Following good OOP design principles, I have factored our solution into two classes:

 

            A TestSolver class that extends the junit.framework.TestCase class.

            A QuadraticSolver class that handles all the logic decisions and calculations

            (You will test the QuadraticSolver code you developed in Lab 2.)

 

 

You can get the beginning project files by copying your files from Lab 2.  You will be writing new code for a Java file in this project. Here are some things to consider:

 

QuadraticSolver:

 

You must add Javadoc comments to your code from Lab 2 to document the API for your class.  These comments must be written using the Javadoc style /** . . . */ format for the class itself and for each method.  For the class, include @author and @version and a description of its intended use.  For each method, provide a description of its purpose, @param for the input parameters (if any), and @return for the return values (if any).

 

TestSolver:

 

1. You do not need to write Javadoc comments for TestSolver, just for QuadraticSolver.

 

2. The TestSolver class does not need to have a main method.  The main method is in its parent class, TestCase, and your TestSolver class inherits it.

 

3. The TestSolver class should not use any System.out.println or any Scanner methods. 

 

4. Write one test case method for each of the six test cases in the table.  Test both the output of the equation method and the solution method for each test case.

 

 

 

 

Lab Report:

 

Did you find that you had missed some errors in manually testing your QuadraticSolver class in Lab 2?  What had you missed and why?

 

Why would you take the time to write automated testing code for a project instead of just continuing to test and retest your code manually during development?

 

Turning in your Lab Report:

 

Turn in your lab report to your TA at your next lab session.  Include a copy of your code and screen shots of a sample run of the testing and of the web page generated by Javadoc.