Question 6-3

Consider the following method.

public class Quadratic {
  public static int main(String[] args) {
    double a = IO.readDouble();
    double b = IO.readDouble();
    double c = IO.readDouble();
    double disc = b * b - 4 * a * c;

    if(disc < 0.0) {
        return Double.NaN;
    }

    if(-b > Math.sqrt(disc)) {
        return (-b - Math.sqrt(disc)) / (2 * a);
    } else {
        return (-b + Math.sqrt(disc)) / (2 * a);
    }
  }
}
List test cases that test each possible path through this method. Do not list any two cases that test the same path.

Solution

  1. Case 1: 1.0 0.0 1.0
  2. Case 2: 1.0 2.0 1.0
  3. Case 3: 1.0 2.0 -1.0

Back to Review for Quiz 6