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 469978a commit 37f158c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/java/QuadraticEquationTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.Random;

/**
* Тесты для решения квадратного уравнения
*/
Expand Down Expand Up @@ -70,4 +72,24 @@ public void testABZeroNoRoots() {
public void testABСZero() {
QuadraticEquation.solve(0, 0, 0);
}

/**
* Большие случайные тесты. Выпадает: нет решений или два (одно не выпадает)
*/
@Test
public void testBigRandom() {
Random r = new Random();
int[] stats = {0, 0, 0};
for (int test = 0; test < 10000000; ++test) {
double a = r.nextDouble(), b = r.nextDouble(), c = r.nextDouble();
double[] roots = QuadraticEquation.solve(a, b, c);
stats[roots.length]++;
for (double x : roots) {
assertEquals(0.0, a * Math.pow(x, 2) + b * x + c, 1e-6);
}
}
System.out.println("Нет решений: " + stats[0]);
System.out.println("Одно решение: " + stats[1]);
System.out.println("Два решения: " + stats[2]);
}
}

0 comments on commit 37f158c

Please sign in to comment.