Skip to content

Commit

Permalink
Add MoveValidatorTest for stack limit. (#11834)
Browse files Browse the repository at this point in the history
Covers the fix in #11831.
  • Loading branch information
asvitkine authored Jul 30, 2023
1 parent 566672a commit 23ae1e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class AbstractDelegateTestCase extends AbstractClientSettingTest
protected Territory sfeSeaZone = gameData.getMap().getTerritory("Soviet Far East Sea Zone");
protected Territory brazil = gameData.getMap().getTerritory("Brazil");
protected Territory westCanada = gameData.getMap().getTerritory("West Canada");
protected Territory eastCanada = gameData.getMap().getTerritory("East Canada");
protected Territory westCanadaSeaZone = gameData.getMap().getTerritory("West Canada Sea Zone");
protected Territory germany = gameData.getMap().getTerritory("Germany");
protected Territory syria = gameData.getMap().getTerritory("Syria Jordan");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static games.strategy.triplea.delegate.GameDataTestUtil.addTo;
import static games.strategy.triplea.delegate.GameDataTestUtil.territory;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.in;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -245,4 +248,24 @@ void testValidateUnitsCanLoadInHostileSeaZones() {
germans);
assertTrue(results.isMoveValid());
}

@Test
void testStackingLimitOnMove() {
MoveValidator moveValidator = new MoveValidator(gameData, true);
Route r = new Route(westCanada, eastCanada);

// 7 infantry can move, no problem.
Collection<Unit> units = infantry.create(7, british);
westCanada.getUnitCollection().addAll(units);
assertThat(units, everyItem(in(westCanada.getUnitCollection())));
var result = moveValidator.validateMove(new MoveDescription(units, r), british);
assertTrue(result.isMoveValid());

// But 8 infantry is not allowed due to a movementLimit on the PlayerAttachment.
Collection<Unit> unit = infantry.create(1, british);
units.addAll(unit);
westCanada.getUnitCollection().addAll(unit);
result = moveValidator.validateMove(new MoveDescription(units, r), british);
assertFalse(result.isMoveValid());
}
}
2 changes: 2 additions & 0 deletions game-app/game-core/src/test/resources/DelegateTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@

<attachment name="playerAttachment" attachTo="British" javaClass="PlayerAttachment" type="player">
<option name="placementLimit" value="owned:battleship:carrier" count="3"/>
<option name="movementLimit" value="owned:infantry" count="7"/>
</attachment>

<!-- Chinese Rules -->
Expand Down Expand Up @@ -975,6 +976,7 @@

<territoryOwner territory="United Kingdom" owner="British"/>
<territoryOwner territory="West Canada" owner="British"/>
<territoryOwner territory="East Canada" owner="British"/>

<territoryOwner territory="Anglo Sudan Egypt" owner="British"/>
<territoryOwner territory="Italian East Africa" owner="British"/>
Expand Down

0 comments on commit 23ae1e3

Please sign in to comment.