Search in sources :

Example 26 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method onFrame_propertyChangedSinceDiscovery_latestPropertyReturned.

@Test
public void onFrame_propertyChangedSinceDiscovery_latestPropertyReturned() {
    final Unit unit = createMockUnit(true);
    final Player originalUnitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(originalUnitOwner);
    this.target.onUnitDiscover(unit, 0);
    // Owner has changed and unit still exists, so tracked owner should change at next onFrame()
    final Player newUnitOwner = Mockito.mock(Player.class);
    when(unit.getPlayer()).thenReturn(newUnitOwner);
    this.target.onFrame(1);
    assertThat(this.target.getPlayer(unit)).isEqualTo(newUnitOwner);
}
Also used : Player(bwapi.Player) Unit(bwapi.Unit) Test(org.junit.Test)

Example 27 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitTrackerTest method unitDestroyed_unitDestroyed_existsIsFalse.

@Test
public void unitDestroyed_unitDestroyed_existsIsFalse() {
    final Unit unit = createMockUnit(true);
    this.target.onUnitDiscover(unit, 1);
    this.target.onFrame(1);
    this.target.onFrame(2);
    when(unit.exists()).thenReturn(false);
    this.target.onUnitDestroy(unit, 2);
    this.target.onFrame(3);
    assertThat(this.target.doesUnitExist(unit)).isFalse();
}
Also used : Unit(bwapi.Unit) Test(org.junit.Test)

Example 28 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class ReservedMapTest method canBuildHere_gameCanBuildHereFalse.

@Test
public void canBuildHere_gameCanBuildHereFalse() {
    final TilePosition positionToBuild = new TilePosition(2, 2);
    final Unit builder = Mockito.mock(Unit.class);
    final UnitType typeToBuild = Mockito.mock(UnitType.class);
    verifyNoMoreInteractions(typeToBuild);
    when(this.mockGame.canBuildHere(positionToBuild, typeToBuild, builder)).thenReturn(false);
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
    verify(this.mockGame).canBuildHere(positionToBuild, typeToBuild, builder);
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 29 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class ReservedMapTest method canBuildHere_partialTilesReserved.

@Test
public void canBuildHere_partialTilesReserved() {
    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);
    this.target.reserveTiles(3, 3);
    assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
    verify(this.mockGame).canBuildHere(positionToBuild, typeToBuild, builder);
    verify(typeToBuild, times(1)).tileWidth();
    verify(typeToBuild, times(1)).tileHeight();
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 30 with Unit

use of bwapi.Unit in project BWJSAL by RobinsonMann.

the class UnitsMutexTest method isUnitUnlocked_unitIsFree_returnsTrue.

@Test
public void isUnitUnlocked_unitIsFree_returnsTrue() {
    final Unit unit = UnitBuilder.mockUnit();
    assertThat(this.target.isUnitUnlocked(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