package net.jacekk.bridge;
|
|
import junit.framework.TestCase;
|
|
public class BridgeComputeTest extends TestCase {
|
BridgeCompute compute = new BridgeCompute();
|
BrydzLicz computeExpected = new BrydzLicz();
|
|
public void testGetIMPs() {
|
assertEquals(0, compute.getIMPs(0));
|
assertEquals(0, compute.getIMPs(10));
|
assertEquals(1, compute.getIMPs(20));
|
assertEquals(1, compute.getIMPs(30));
|
assertEquals(1, compute.getIMPs(40));
|
assertEquals(2, compute.getIMPs(50));
|
|
assertEquals(23, compute.getIMPs(3999));
|
assertEquals(24, compute.getIMPs(4000));
|
assertEquals(24, compute.getIMPs(4001));
|
}
|
|
public void testGetPercent() {
|
assertEquals(50, compute.getPercent(20, 0, 0));
|
assertEquals(44, compute.getPercent(21, 0, 0));
|
}
|
|
public void testGetResultForBasic() throws BridgeInputException {
|
BridgeInput input = new BridgeInput();
|
input.bid = 0;
|
input.PC = 20;
|
input.weVulnerable = false;
|
input.theyVulnerable = false;
|
input.suit = BridgeInput.Suit.MINOR;
|
input.contract = BridgeInput.Contract.NORMAL;
|
BridgeResult result;
|
|
result = compute.getResultForInput(input);
|
assertEquals(BridgeResult.Side.They, result.winners);
|
assertEquals(0, result.IMPs);
|
assertEquals(50, result.percent);
|
|
input.PC = 21;
|
result = compute.getResultForInput(input);
|
assertEquals(BridgeResult.Side.They, result.winners);
|
assertEquals(2, result.IMPs);
|
assertEquals(56, result.percent);
|
|
input.PC = 24;
|
result = compute.getResultForInput(input);
|
assertEquals(BridgeResult.Side.They, result.winners);
|
assertEquals(5, result.IMPs);
|
assertEquals(56, result.percent);
|
|
input.PC = 25;
|
result = compute.getResultForInput(input);
|
assertEquals(BridgeResult.Side.They, result.winners);
|
assertEquals(7, result.IMPs);
|
assertEquals(74, result.percent);
|
}
|
|
public void testGetResultForFull() throws BridgeInputException {
|
int contract;
|
int suit;
|
int game;
|
int vulnerability;
|
int PC;
|
int tricks;
|
BridgeInput input = new BridgeInput();
|
BridgeResult result;
|
BrydzLicz.BrydzWynik expectedResult;
|
|
for (contract = 0; contract <= 7; contract++) {
|
input.bid = contract;
|
for (suit = 0; suit <= 2; suit++) {
|
input.suit = BridgeInput.Suit.values()[suit];
|
for (game = 0; game <= 2; game++) {
|
input.contract = BridgeInput.Contract.values()[game];
|
for (vulnerability = 0; vulnerability <= 3; vulnerability++) {
|
input.weVulnerable = vulnerability / 2 >= 1;
|
input.theyVulnerable = vulnerability % 2 >= 1;
|
for (PC = 0; PC <= 40; PC++) {
|
input.PC = PC;
|
for (tricks = 0; tricks <= 13; tricks++) {
|
|
input.tricks = tricks;
|
try {
|
result = compute.getResultForInput(input);
|
} catch (Exception e) {
|
if (contract > 0) {
|
throw e;
|
}
|
continue;
|
}
|
|
expectedResult = computeExpected.policz(contract, suit, game, vulnerability, PC, tricks);
|
|
assertEquals(input.toString(), expectedResult.dla, result.winners.ordinal());
|
assertEquals(input.toString(), expectedResult.punkty_przed, result.pointsBefore);
|
assertEquals(input.toString(), expectedResult.punkty, result.points);
|
assertEquals(input.toString(), expectedResult.IMP, result.IMPs);
|
assertEquals(input.toString(), expectedResult.procent, result.percent);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|