Skip to content

Commit

Permalink
a = 0, b = 0, c != 0 - нет решений
Browse files Browse the repository at this point in the history
  • Loading branch information
stden committed May 23, 2015
1 parent 74f43e6 commit 4dae578
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -14,6 +14,8 @@ public class QuadraticEquation {
*/
public static double[] solve(double a, double b, double c) {
if (Math.abs(a) < EPS) {
if (Math.abs(b) < EPS)
return new double[]{};
return new double[]{-c / b};
}
// Дискриминант
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/QuadraticEquationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ public void testLinear() {
assertArrayEquals("3x + 4 = 0", new double[]{-4 / 3.}, QuadraticEquation.solve(0, 3, 4), EPS);
assertArrayEquals("1e-16*x^2 + x - 100 = 0", new double[]{100}, QuadraticEquation.solve(1e-16, 1, -100), EPS);
}

/**
* a = 0, b = 0, c != 0 - нет решений
*/
@Test
public void testABZeroNoRoots() {
assertArrayEquals("2 = 0", new double[]{}, QuadraticEquation.solve(0, 0, 2), EPS);
assertArrayEquals("4.5 = 0", new double[]{}, QuadraticEquation.solve(0, 0, 4.5), EPS);
}

}

0 comments on commit 4dae578

Please sign in to comment.