-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMagnetsTest.java
24 lines (21 loc) · 910 Bytes
/
MagnetsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import static org.junit.Assert.*;
import java.text.DecimalFormat;
import org.junit.Test;
public class MagnetsTest {
private static void assertFuzzyEquals(double act, double exp) {
boolean inrange = Math.abs(act - exp) <= 1e-6;
if (inrange == false) {
DecimalFormat df = new DecimalFormat("#0.000000");
System.out.println("At 1e-6: Expected must be " + df.format(exp) +", but got " + df.format(act));
}
assertEquals(true, inrange);
}
@Test
public void test1() {
System.out.println("Fixed Tests: doubles");
assertFuzzyEquals(Magnets.doubles(1, 10), 0.5580321939764581);
assertFuzzyEquals(Magnets.doubles(10, 1000), 0.6921486500921933);
assertFuzzyEquals(Magnets.doubles(10, 10000), 0.6930471674194457);
assertFuzzyEquals(Magnets.doubles(20, 10000), 0.6930471955575918);
}
}