-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Schinc
committed
Feb 24, 2024
1 parent
237a1a3
commit e91c1f1
Showing
12 changed files
with
603 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.epfl.chacun; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class AnimalTest { | ||
@Test | ||
void animalKindIsDefinedCorrectly() { | ||
assertEquals(0, Animal.Kind.MAMMOTH.ordinal()); | ||
assertEquals(1, Animal.Kind.AUROCHS.ordinal()); | ||
assertEquals(2, Animal.Kind.DEER.ordinal()); | ||
assertEquals(3, Animal.Kind.TIGER.ordinal()); | ||
} | ||
|
||
@Test | ||
void animalTileIdWorks() { | ||
var allKinds = List.of(Animal.Kind.values()); | ||
var kindIndex = 0; | ||
for (int tileId = 0; tileId < 10; tileId += 1) { | ||
for (int zoneLocalId = 0; zoneLocalId < 10; zoneLocalId += 1) { | ||
var zoneId = tileId * 10 + zoneLocalId; | ||
for (int animalLocalId = 0; animalLocalId < 2; animalLocalId += 1) { | ||
var animalId = zoneId * 10 + animalLocalId; | ||
var animal = new Animal(animalId, allKinds.get(kindIndex)); | ||
kindIndex = (kindIndex + 1) % allKinds.size(); | ||
assertEquals(tileId, animal.tileId()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ch.epfl.chacun; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class DirectionTest { | ||
@Test | ||
void directionAllIsCorrectlyDefined() { | ||
assertEquals(4, Direction.ALL.size()); | ||
assertEquals(Direction.N, Direction.ALL.get(0)); | ||
assertEquals(Direction.E, Direction.ALL.get(1)); | ||
assertEquals(Direction.S, Direction.ALL.get(2)); | ||
assertEquals(Direction.W, Direction.ALL.get(3)); | ||
} | ||
|
||
@Test | ||
void directionCountIsCorrectlyDefined() { | ||
assertEquals(4, Direction.COUNT); | ||
} | ||
|
||
@Test | ||
void directionRotatedWorksForAllDirectionsAndRotations() { | ||
assertEquals(Direction.N.rotated(Rotation.RIGHT), Direction.E); | ||
assertEquals(Direction.N.rotated(Rotation.LEFT), Direction.W); | ||
assertEquals(Direction.N.rotated(Rotation.HALF_TURN), Direction.S); | ||
assertEquals(Direction.N.rotated(Rotation.NONE), Direction.N); | ||
|
||
assertEquals(Direction.E.rotated(Rotation.RIGHT), Direction.S); | ||
assertEquals(Direction.E.rotated(Rotation.LEFT), Direction.N); | ||
assertEquals(Direction.E.rotated(Rotation.HALF_TURN), Direction.W); | ||
assertEquals(Direction.E.rotated(Rotation.NONE), Direction.E); | ||
|
||
assertEquals(Direction.S.rotated(Rotation.RIGHT), Direction.W); | ||
assertEquals(Direction.S.rotated(Rotation.LEFT), Direction.E); | ||
assertEquals(Direction.S.rotated(Rotation.HALF_TURN), Direction.N); | ||
assertEquals(Direction.S.rotated(Rotation.NONE), Direction.S); | ||
|
||
assertEquals(Direction.W.rotated(Rotation.RIGHT), Direction.N); | ||
assertEquals(Direction.W.rotated(Rotation.LEFT), Direction.S); | ||
assertEquals(Direction.W.rotated(Rotation.HALF_TURN), Direction.E); | ||
assertEquals(Direction.W.rotated(Rotation.NONE), Direction.W); | ||
} | ||
|
||
@Test | ||
void directionOppositeWorksForAllDirections() { | ||
assertEquals(Direction.N.opposite(), Direction.S); | ||
assertEquals(Direction.E.opposite(), Direction.W); | ||
assertEquals(Direction.S.opposite(), Direction.N); | ||
assertEquals(Direction.W.opposite(), Direction.E); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ch.epfl.chacun; | ||
|
||
import java.util.List; | ||
|
||
public class GameTest { | ||
|
||
//Zone forestZone = new Zone.Forest(1, Zone.Forest.Kind.PLAIN); | ||
|
||
//Zone lakeZone = new Zone.Lake(3, 12, null); | ||
//Zone riverZone = new Zone.River(2, 12, new Zone.Lake(3, 12, null)); | ||
//Zone jungleZone = new Zone.Forest(4, ZONE.Forest.WITH_MUSHROOMS); | ||
|
||
|
||
/** | ||
* Create a meadow zone with a hunting trap special power | ||
* Create a meadow zone with a mammoth | ||
* Create a forest zone with a plain kind | ||
* Create a forest zone with a menhir kind | ||
* Create two tile sides with the first meadow zone and the first forest zone | ||
* Create two tile sides with the second meadow zone and the second forest zone | ||
* Create a tile with the four tile sides | ||
* Create a player color | ||
* Create a placed tile with the tile, the player color, a rotation and a position | ||
*/ | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ch.epfl.chacun; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class OccupantTest { | ||
@Test | ||
void occupantConstructorThrowsOnNullKind() { | ||
assertThrows(NullPointerException.class, () -> new Occupant(null, 0)); | ||
} | ||
|
||
@Test | ||
void occupantConstructorThrowsOnNegativeZoneId() { | ||
assertThrows(IllegalArgumentException.class, () -> new Occupant(Occupant.Kind.PAWN, -1)); | ||
} | ||
|
||
@Test | ||
void occupantOccupantCountIsCorrectlyDefined() { | ||
assertEquals(5, Occupant.occupantsCount(Occupant.Kind.PAWN)); | ||
assertEquals(3, Occupant.occupantsCount(Occupant.Kind.HUT)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package ch.epfl.chacun; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
class PlacedTileTest { | ||
|
||
@Test | ||
public void testSideReturnsCorrectValue() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTileRight = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
assertEquals(meadowSide2, placedTileRight.side(Direction.N)); | ||
assertEquals(forestSide, placedTileRight.side(Direction.E)); | ||
|
||
PlacedTile placedTileLeft = new PlacedTile(tile, Habib, Rotation.LEFT, new Pos(0, 0)); | ||
assertEquals(meadowSide, placedTileLeft.side(Direction.N)); | ||
} | ||
|
||
@Test | ||
public void testZoneWithIdReturnsCorrectZone() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
assertEquals(forest, placedTile.zoneWithId(612)); | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
placedTile.zoneWithId(100000); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testTypeZonesReturnsCorrectZones() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
final Set<Zone> expectedForestSet = new HashSet<>(List.of(new Zone[]{forest, forest2})); | ||
assertEquals(expectedForestSet, placedTile.forestZones()); | ||
|
||
final Set<Zone> expectedMeadowSet = new HashSet<>(List.of(new Zone[]{meadow2, meadow})); | ||
assertEquals(expectedMeadowSet, placedTile.meadowZones()); | ||
|
||
assertEquals(new HashSet<>(), placedTile.riverZones()); | ||
} | ||
|
||
@Test | ||
public void testSpecialPowerZoneReturnsCorrectZone() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
assertEquals(meadow, placedTile.specialPowerZone()); | ||
|
||
Zone.Meadow meadow3 = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), null); | ||
TileSide meadowSide3 = new TileSide.Meadow(meadow3); | ||
Tile tile2 = new Tile(1, Tile.Kind.START, forestSide, meadowSide3, forestSide2, meadowSide2); | ||
|
||
PlacedTile placedTile2 = new PlacedTile(tile2, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
assertNull(placedTile2.specialPowerZone()); | ||
} | ||
|
||
@Test | ||
public void testPotentialOccupantsReturnsCorrectValue() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
Set<Occupant> set = new HashSet<>(); | ||
set.add(new Occupant(Occupant.Kind.PAWN, 613)); | ||
set.add(new Occupant(Occupant.Kind.PAWN, 614)); | ||
set.add(new Occupant(Occupant.Kind.PAWN, 615)); | ||
set.add(new Occupant(Occupant.Kind.PAWN, 612)); | ||
|
||
assertEquals(set, placedTile.potentialOccupants()); | ||
|
||
PlacedTile placedTile2 = new PlacedTile(tile, null, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
assertEquals(new HashSet<>(), placedTile2.potentialOccupants()); | ||
|
||
Zone.River river = new Zone.River(623, 3, null); | ||
Zone.Lake lake = new Zone.Lake(628, 0, Zone.SpecialPower.LOGBOAT); | ||
Zone.River river2 = new Zone.River(624, 2, lake); | ||
|
||
TileSide riverSide1 = new TileSide.River(meadow, river, meadow2); | ||
TileSide riverSide2 = new TileSide.River(meadow2, river2, meadow); | ||
|
||
Tile tile2 = new Tile(1, Tile.Kind.START, forestSide, riverSide1, riverSide2, meadowSide2); | ||
PlacedTile placedTile3 = new PlacedTile(tile2, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
Set<Occupant> set2 = new HashSet<>(); | ||
set2.add(new Occupant(Occupant.Kind.PAWN, 623)); | ||
set2.add(new Occupant(Occupant.Kind.PAWN, 624)); | ||
set2.add(new Occupant(Occupant.Kind.HUT, 628)); | ||
set2.add(new Occupant(Occupant.Kind.HUT, 623)); | ||
|
||
set2.add(new Occupant(Occupant.Kind.PAWN, 613)); | ||
set2.add(new Occupant(Occupant.Kind.PAWN, 614)); | ||
set2.add(new Occupant(Occupant.Kind.PAWN, 612)); | ||
|
||
assertEquals(set2, placedTile3.potentialOccupants()); | ||
} | ||
|
||
@Test | ||
public void testWithOccupantWorks() { | ||
Zone.Meadow meadow = new Zone.Meadow(613, List.of(new Animal(6131, Animal.Kind.AUROCHS)), Zone.Meadow.SpecialPower.HUNTING_TRAP); | ||
Zone.Meadow meadow2 = new Zone.Meadow(614, List.of(new Animal(6141, Animal.Kind.MAMMOTH)), null); | ||
Zone.Forest forest2 = new Zone.Forest(615, Zone.Forest.Kind.PLAIN); | ||
Zone.Forest forest = new Zone.Forest(612, Zone.Forest.Kind.WITH_MENHIR); | ||
TileSide forestSide = new TileSide.Forest(forest); | ||
TileSide meadowSide = new TileSide.Meadow(meadow); | ||
TileSide forestSide2 = new TileSide.Forest(forest2); | ||
TileSide meadowSide2 = new TileSide.Meadow(meadow2); | ||
Tile tile = new Tile(1, Tile.Kind.START, forestSide, meadowSide, forestSide2, meadowSide2); | ||
PlayerColor Habib = PlayerColor.RED; | ||
|
||
PlacedTile placedTile = new PlacedTile(tile, Habib, Rotation.RIGHT, new Pos(0, 0)); | ||
|
||
Occupant occupant = new Occupant(Occupant.Kind.PAWN, 613); | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
PlacedTile withOccupant = placedTile.withOccupant(occupant); | ||
withOccupant.withOccupant(new Occupant(Occupant.Kind.PAWN, 613)); | ||
}); | ||
|
||
PlacedTile withOccupant = placedTile.withOccupant(new Occupant(Occupant.Kind.PAWN, 613)); | ||
assertEquals(occupant, withOccupant.occupant()); | ||
|
||
assertEquals(613, withOccupant.idOfZoneOccupiedBy(Occupant.Kind.PAWN)); | ||
assertEquals(-1, withOccupant.idOfZoneOccupiedBy(Occupant.Kind.HUT)); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ch.epfl.chacun; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class PlayerColorTest { | ||
@Test | ||
void playerColorAllIsCorrectlyDefined() { | ||
assertEquals(5, PlayerColor.ALL.size()); | ||
assertEquals(PlayerColor.RED, PlayerColor.ALL.get(0)); | ||
assertEquals(PlayerColor.BLUE, PlayerColor.ALL.get(1)); | ||
assertEquals(PlayerColor.GREEN, PlayerColor.ALL.get(2)); | ||
assertEquals(PlayerColor.YELLOW, PlayerColor.ALL.get(3)); | ||
assertEquals(PlayerColor.PURPLE, PlayerColor.ALL.get(4)); | ||
} | ||
} |
Oops, something went wrong.