Practice for the SWE 437 final exam
Design and implement tests for the following method findRoots().
- Input Space Partitioning
- Model the method findRoots() using ISP.
- Define characteristics of the input variables.
- Partition characteristics into blocks.
- Use the base choice criterion to design abstract
tests.
- Implement the abstract tests as input values.
- Draw the control flow graph for findRoots().
- Label your control flow graph with predicates for each
decision. Make sure you include a clear mapping of your graph to
the source code (this can be on the graph or using a key).
- Graph-based Testing
- Determine test requirements for satisfying edge
coverage (EC) on the graph.
- Design abstract tests in the form of test paths that
satisfy EC, then choose values to satisfy each test, and provide
expected output.
- Logic-based Testing
- Using the predicates from your CFG, design tests to satisfy
Correlated Active Clause Coverage (CACC) by finding truth statements that satisfy CACC.
- Choose values to satisfy each truth assignment, add values that
will reach the predicate, and provide expected output.
- Implement your tests in JUnit.
public class root
{
private static double Root1, Root2;
// Finds the quadratic root, A must be non-zero
public boolean findRoots(int A, int B, int C) {
double D;
boolean Result;
D = (double)(B*B) - (double)(4.0*A*C);
if (D < 0.0)
{
Result = false;
return(Result);
}
Root1 = (double) ((-B + Math.sqrt(D)) / (2.0*A));
Root2 = (double) ((-B - Math.sqrt(D)) / (2.0*A));
Result = true;
return(Result);
} // End method findRoots
public double getRoot1() {
return(Root1);
}
public double getRoot2() {
return(Root2);
}
} // End class root
Exercises in the AO Book (more practice)
Input Space Partitioning:
Graph-based Testing:
- Chapter 7.3 Exercises 7 and 8
Logic-based testing