Skip to content

Commit

Permalink
a = 0, b = 0, c = 0, x - любое (бесконечное число решений)
Browse files Browse the repository at this point in the history
  • Loading branch information
stden committed May 23, 2015
1 parent 4dae578 commit bb06ad4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/AnyXException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Исключение - x может быть любым
*/
public class AnyXException extends RuntimeException {
}
5 changes: 4 additions & 1 deletion src/main/java/QuadraticEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public class QuadraticEquation {
*/
public static double[] solve(double a, double b, double c) {
if (Math.abs(a) < EPS) {
if (Math.abs(b) < EPS)
if (Math.abs(b) < EPS) {
if (Math.abs(c) < EPS)
throw new AnyXException();
return new double[]{};
}
return new double[]{-c / b};
}
// Дискриминант
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 @@ -62,4 +62,12 @@ public void testABZeroNoRoots() {
assertArrayEquals("4.5 = 0", new double[]{}, QuadraticEquation.solve(0, 0, 4.5), EPS);
}

/**
* a = 0, b = 0, c = 0, x - любое (бесконечное число решений)
* Это не возможно выразить с помощью массива double => генерируем исключение
*/
@Test(expected = AnyXException.class)
public void testABСZero() {
QuadraticEquation.solve(0, 0, 0);
}
}

0 comments on commit bb06ad4

Please sign in to comment.