Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
49 | daniel-mar | 1 | package de.viathinksoft.marschall.raumplan.formula; |
2 | |||
3 | import static org.junit.Assert.*; |
||
4 | |||
5 | import org.junit.Test; |
||
6 | |||
7 | public class FormulaProbeTest { |
||
8 | |||
9 | @Test |
||
10 | public void GeneralTests() throws SelfTestException, InvalidValException { |
||
11 | assertTrue(nearlyEquals(FormulaProbe.b_star(), 0.6823278038280193)); |
||
12 | assertTrue(nearlyEquals(FormulaProbe.g_star(), 0.3819660112501051)); |
||
13 | assertTrue(nearlyEquals(FormulaProbe.w_star(), 0.2838458789785244)); |
||
14 | |||
15 | assertTrue(nearlyEquals(FormulaProbe.w_star(), FormulaProbe.w23( |
||
16 | FormulaProbe.b_star(), FormulaProbe.g_star()))); |
||
17 | assertTrue(nearlyEquals(FormulaProbe.w_star(), FormulaProbe.w3( |
||
18 | FormulaProbe.b_star(), FormulaProbe.g_star()))); |
||
19 | |||
20 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(0.5, 0.5, 0.5))); |
||
21 | assertFalse(nearlyEquals(0.0, FormulaProbe.K3(0.5, 0.5, 0.5))); |
||
22 | |||
23 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(0.0, 0.5, 0.375))); |
||
24 | assertFalse(nearlyEquals(0.0, FormulaProbe.K3(0.0, 0.5, 0.375))); |
||
25 | |||
26 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(FormulaProbe.b_star(), |
||
27 | FormulaProbe.g_star(), FormulaProbe.w_star()))); |
||
28 | assertTrue(nearlyEquals(0.0, FormulaProbe.K3(FormulaProbe.b_star(), |
||
29 | FormulaProbe.g_star(), FormulaProbe.w_star()))); |
||
30 | |||
31 | for (double i = 0; i < 0.99; i += 0.01) { |
||
32 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(FormulaProbe.b_star(), |
||
33 | FormulaProbe.g_star(), i))); |
||
34 | assertFalse(nearlyEquals(0.0, FormulaProbe.K3( |
||
35 | FormulaProbe.b_star(), FormulaProbe.g_star(), i))); |
||
36 | } |
||
37 | |||
38 | // w23test(0.2, 0.7); // TODO |
||
39 | w23test(FormulaProbe.b_star(), FormulaProbe.g_star()); |
||
40 | w3test(FormulaProbe.b_star(), FormulaProbe.g_star()); |
||
41 | w2test(0.5, 0.5); |
||
42 | w3test(0.6, 0.6); |
||
43 | } |
||
44 | |||
45 | private static void w23test(double b, double g) throws SelfTestException, |
||
46 | InvalidValException { |
||
47 | double w = FormulaProbe.w23(b, g); |
||
48 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(b, g, w))); |
||
49 | assertTrue(nearlyEquals(0.0, FormulaProbe.K3(b, g, w))); |
||
50 | } |
||
51 | |||
52 | private static void w2test(double b, double g) throws SelfTestException, |
||
53 | InvalidValException { |
||
54 | double w = FormulaProbe.w2(b, g); |
||
55 | assertTrue(nearlyEquals(0.0, FormulaProbe.K2(b, g, w))); |
||
56 | } |
||
57 | |||
58 | private static void w3test(double b, double g) throws SelfTestException, |
||
59 | InvalidValException { |
||
60 | double w = FormulaProbe.w3(b, g); |
||
61 | assertTrue(nearlyEquals(0.0, FormulaProbe.K3(b, g, w))); |
||
62 | } |
||
63 | |||
64 | private static boolean nearlyEquals(double a, double b) { |
||
65 | return Math.abs(Math.abs(a) - Math.abs(b)) < 0.0000000000001; |
||
66 | } |
||
67 | |||
68 | } |