commit | author | age
|
2d8187
|
1 |
package net.jacekk.bridge; |
JK |
2 |
|
ae5f07
|
3 |
import junit.framework.TestCase; |
JK |
4 |
|
|
5 |
public class BridgeComputeTest extends TestCase { |
|
6 |
BridgeCompute compute = new BridgeCompute(); |
|
7 |
BrydzLicz computeExpected = new BrydzLicz(); |
|
8 |
|
|
9 |
public void testGetIMPs() { |
|
10 |
assertEquals(0, compute.getIMPs(0)); |
|
11 |
assertEquals(0, compute.getIMPs(10)); |
|
12 |
assertEquals(1, compute.getIMPs(20)); |
|
13 |
assertEquals(1, compute.getIMPs(30)); |
|
14 |
assertEquals(1, compute.getIMPs(40)); |
|
15 |
assertEquals(2, compute.getIMPs(50)); |
|
16 |
|
|
17 |
assertEquals(23, compute.getIMPs(3999)); |
|
18 |
assertEquals(24, compute.getIMPs(4000)); |
|
19 |
assertEquals(24, compute.getIMPs(4001)); |
|
20 |
} |
|
21 |
|
|
22 |
public void testGetPercent() { |
|
23 |
assertEquals(50, compute.getPercent(20, 0, 0)); |
|
24 |
assertEquals(44, compute.getPercent(21, 0, 0)); |
|
25 |
} |
|
26 |
|
|
27 |
public void testGetResultForBasic() throws BridgeInputException { |
|
28 |
BridgeInput input = new BridgeInput(); |
|
29 |
input.bid = 0; |
|
30 |
input.PC = 20; |
|
31 |
input.weVulnerable = false; |
|
32 |
input.theyVulnerable = false; |
|
33 |
input.suit = BridgeInput.Suit.MINOR; |
|
34 |
input.contract = BridgeInput.Contract.NORMAL; |
|
35 |
BridgeResult result; |
|
36 |
|
|
37 |
result = compute.getResultForInput(input); |
|
38 |
assertEquals(BridgeResult.Side.They, result.winners); |
|
39 |
assertEquals(0, result.IMPs); |
|
40 |
assertEquals(50, result.percent); |
|
41 |
|
|
42 |
input.PC = 21; |
|
43 |
result = compute.getResultForInput(input); |
|
44 |
assertEquals(BridgeResult.Side.They, result.winners); |
|
45 |
assertEquals(2, result.IMPs); |
|
46 |
assertEquals(56, result.percent); |
|
47 |
|
|
48 |
input.PC = 24; |
|
49 |
result = compute.getResultForInput(input); |
|
50 |
assertEquals(BridgeResult.Side.They, result.winners); |
|
51 |
assertEquals(5, result.IMPs); |
|
52 |
assertEquals(56, result.percent); |
|
53 |
|
|
54 |
input.PC = 25; |
|
55 |
result = compute.getResultForInput(input); |
|
56 |
assertEquals(BridgeResult.Side.They, result.winners); |
|
57 |
assertEquals(7, result.IMPs); |
|
58 |
assertEquals(74, result.percent); |
|
59 |
} |
|
60 |
|
|
61 |
public void testGetResultForFull() throws BridgeInputException { |
|
62 |
int contract; |
|
63 |
int suit; |
|
64 |
int game; |
|
65 |
int vulnerability; |
|
66 |
int PC; |
|
67 |
int tricks; |
|
68 |
BridgeInput input = new BridgeInput(); |
|
69 |
BridgeResult result; |
|
70 |
BrydzLicz.BrydzWynik expectedResult; |
|
71 |
|
|
72 |
for (contract = 0; contract <= 7; contract++) { |
|
73 |
input.bid = contract; |
|
74 |
for (suit = 0; suit <= 2; suit++) { |
|
75 |
input.suit = BridgeInput.Suit.values()[suit]; |
|
76 |
for (game = 0; game <= 2; game++) { |
|
77 |
input.contract = BridgeInput.Contract.values()[game]; |
|
78 |
for (vulnerability = 0; vulnerability <= 3; vulnerability++) { |
|
79 |
input.weVulnerable = vulnerability / 2 >= 1; |
|
80 |
input.theyVulnerable = vulnerability % 2 >= 1; |
|
81 |
for (PC = 0; PC <= 40; PC++) { |
|
82 |
input.PC = PC; |
|
83 |
for (tricks = 0; tricks <= 13; tricks++) { |
|
84 |
|
|
85 |
input.tricks = tricks; |
|
86 |
try { |
|
87 |
result = compute.getResultForInput(input); |
|
88 |
} catch (Exception e) { |
|
89 |
if (contract > 0) { |
|
90 |
throw e; |
|
91 |
} |
|
92 |
continue; |
|
93 |
} |
|
94 |
|
|
95 |
expectedResult = computeExpected.policz(contract, suit, game, vulnerability, PC, tricks); |
|
96 |
|
|
97 |
assertEquals(input.toString(), expectedResult.dla, result.winners.ordinal()); |
|
98 |
assertEquals(input.toString(), expectedResult.punkty_przed, result.pointsBefore); |
|
99 |
assertEquals(input.toString(), expectedResult.punkty, result.points); |
|
100 |
assertEquals(input.toString(), expectedResult.IMP, result.IMPs); |
|
101 |
assertEquals(input.toString(), expectedResult.procent, result.percent); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
} |
2d8187
|
109 |
} |