Search in sources :

Example 66 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method onDiscovery_unitDiscovered_unitTracked.

@Test
public void onDiscovery_unitDiscovered_unitTracked() {
    final Unit unit = createMockUnit(true);
    final Player unitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(unitOwner);
    this.target.onUnitDiscover(unit, 0);
    assertThat(this.target.getPlayer(unit)).isEqualTo(unitOwner);
}
Also used : Player(bwapi.Player) Unit(bwapi.Unit) Test(org.junit.Test)

Example 67 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method createMockUnit.

private Unit createMockUnit(final boolean exists) {
    final Unit unit = Mockito.mock(Unit.class);
    when(unit.exists()).thenReturn(exists);
    return unit;
}
Also used : Unit(bwapi.Unit)

Example 68 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class ReservedMapTest method canBuildHere_blockingTilesWereReservedAndFreed.

@Test
public void canBuildHere_blockingTilesWereReservedAndFreed() {
    final TilePosition positionToBuild = new TilePosition(2, 2);
    final Unit builder = Mockito.mock(Unit.class);
    final UnitType typeToBuild = Mockito.mock(UnitType.class);
    when(typeToBuild.tileWidth()).thenReturn(2);
    when(typeToBuild.tileHeight()).thenReturn(2);
    when(this.mockGame.canBuildHere(positionToBuild, typeToBuild, builder)).thenReturn(true);
    // Reserve a tile that blocks building placement
    this.target.reserveTiles(3, 3);
    // Verify that tile does block placement
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
    // Free blocking tile
    this.target.freeTiles(3, 3);
    // Verify that we can now place
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isTrue();
    verify(this.mockGame, times(2)).canBuildHere(positionToBuild, typeToBuild, builder);
    verify(typeToBuild, times(2)).tileWidth();
    verify(typeToBuild, times(2)).tileHeight();
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 69 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitsMutexTest method unlockUnit_unitNotLocked_unitStillUnlocked.

@Test
public void unlockUnit_unitNotLocked_unitStillUnlocked() {
    final Unit unit = UnitBuilder.mockUnit();
    assertThat(this.target.isUnitLocked(unit)).as("Sanity test that unit unlocked").isFalse();
    this.target.unlockUnit(unit);
    assertThat(this.target.isUnitLocked(unit)).as("unit still unlocked").isFalse();
}
Also used : Unit(bwapi.Unit) Test(org.junit.Test)

Example 70 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitsMutexTest method isUnitFree_unitIsFree_returnsTrue.

@Test
public void isUnitFree_unitIsFree_returnsTrue() {
    final Unit unit = UnitBuilder.mockUnit();
    assertThat(this.target.isUnitFree(unit)).isTrue();
}
Also used : Unit(bwapi.Unit) Test(org.junit.Test)

Aggregations

Unit (bwapi.Unit)73 GameState (ecgberht.GameState)36 Test (org.junit.Test)21 Position (bwapi.Position)14 TilePosition (bwapi.TilePosition)10 BaseLocation (bwta.BaseLocation)7 Pair (bwapi.Pair)6 UnitType (bwapi.UnitType)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Player (bwapi.Player)3 EnemyBuilding (ecgberht.EnemyBuilding)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 Squad (ecgberht.Squad)2 Game (bwapi.Game)1 UnitCommand (bwapi.UnitCommand)1 Region (bwta.Region)1 Random (java.util.Random)1