Skip to content

Commit

Permalink
Нет решений (корней)
Browse files Browse the repository at this point in the history
  • Loading branch information
stden committed May 23, 2015
1 parent 14bff05 commit 484d1ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/QuadraticEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static double[] solve(double a, double b, double c) {
double D = Math.pow(b, 2) - 4 * a * c;
if (Math.abs(D) < EPS)
return new double[]{-b / (2 * a)};
if (D < 0)
return new double[]{};
double d = Math.sqrt(D);
return new double[]{(-b - d) / (2 * a), (-b + d) / (2 * a)};
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/QuadraticEquationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public void testOneRootAccuracy() {
assertArrayEquals("t(x-q)^2 = t*x^2 - 2*t*q*x + t*q^2", new double[]{q}, QuadraticEquation.solve(t, -2 * t * q, t * q * q), EPS);
}
}

/**
* Нет решений (корней)
*/
@Test
public void testNoRoots() {
assertArrayEquals("x^2 + 2 = 0", new double[]{}, QuadraticEquation.solve(1, 0, 2), EPS);
}
}

0 comments on commit 484d1ef

Please sign in to comment.