use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.
the class DiceRollTest method testSimpleLowLuck.
@Test
public void testSimpleLowLuck() {
GameDataTestUtil.makeGameLowLuck(gameData);
final Territory westRussia = gameData.getMap().getTerritory("West Russia");
final MockBattle battle = new MockBattle(westRussia);
final PlayerID russians = GameDataTestUtil.russians(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(russians);
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
final List<Unit> infantry = infantryType.create(1, russians);
final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(westRussia);
// infantry defends and hits at 1 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
final DiceRoll roll = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
assertThat(roll.getHits(), is(1));
// infantry does not hit at 2 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 2 }));
final DiceRoll roll2 = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
assertThat(roll2.getHits(), is(0));
// infantry attacks and hits at 0 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
final DiceRoll roll3 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
assertThat(roll3.getHits(), is(1));
// infantry attack does not hit at 1 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
final DiceRoll roll4 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
assertThat(roll4.getHits(), is(0));
}
Aggregations