Skip to content

Commit

Permalink
test(building-ops): adjust wrong tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Oct 10, 2023
1 parent cc1374a commit 713b086
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
7 changes: 6 additions & 1 deletion src/test/scala/scatan/model/game/BaseScatanStateTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ import scatan.model.map.RoadSpot
import scatan.model.game.ops.EmptySpotsOps.emptyRoadSpot
import scatan.model.game.ops.BuildingOps.assignBuilding
import scatan.model.components.BuildingType
import scatan.model.map.StructureSpot

abstract class BaseScatanStateTest extends BaseTest:

protected def players(n: Int): Seq[ScatanPlayer] =
(1 to n).map(i => ScatanPlayer(s"Player $i"))

protected def noConstrainToBuildRoad: ScatanState => ((RoadSpot, ScatanPlayer) => Boolean) = _ => (_, _) => true
protected def noConstrainToBuildSettlment: ScatanState => ((StructureSpot, ScatanPlayer) => Boolean) = _ =>
(_, _) => true
protected def spotShouldBeEmptyToBuildRoad: ScatanState => ((RoadSpot, ScatanPlayer) => Boolean) = s =>
(r, _) => s.emptyRoadSpot.contains(r)

// Avoid heavy check on spot type
extension (state: ScatanState)
def assignRoadWithoutRule(spot: RoadSpot, player: ScatanPlayer): Option[ScatanState] =
state.assignBuilding(spot, BuildingType.Road, player, noConstrainToBuildRoad)
state.assignBuilding(spot, BuildingType.Road, player, roadBuildingRules = noConstrainToBuildRoad)
def assignSettlmentWithoutRule(spot: StructureSpot, player: ScatanPlayer): Option[ScatanState] =
state.assignBuilding(spot, BuildingType.Settlement, player, settlementBuildingRules = noConstrainToBuildSettlment)

protected def emptySpot(state: ScatanState): Spot = state.emptySpots.head

Expand Down
8 changes: 1 addition & 7 deletions src/test/scala/scatan/model/game/ops/BuildingOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ class BuildingOpsTest extends BaseScatanStateTest:
it should "not permit to assign a settlement if the spot is not empty" in {
val state = ScatanState(threePlayers)
val spot = spotToBuildStructure(state)
val stateWithBuilding = for
stateWithWood <- state.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Wood))
stateWithBrick <- stateWithWood.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Brick))
stateWithSheep <- stateWithBrick.assignResourceCard(threePlayers.head, ResourceCard(ResourceType.Sheep))
stateWithSettlement <- stateWithSheep.build(spot, BuildingType.Settlement, threePlayers.head)
yield stateWithSettlement
val stateWithBuilding = state.assignSettlmentWithoutRule(spot, threePlayers.head)
stateWithBuilding match
case Some(state) =>
state.assignedBuildings(spot) should be(AssignmentInfo(threePlayers.head, BuildingType.Settlement))
Expand Down Expand Up @@ -194,6 +189,5 @@ class BuildingOpsTest extends BaseScatanStateTest:
state
.assignBuilding(anotherSpot, BuildingType.Settlement, threePlayers.head)
.flatMap(_.assignBuilding(spot, BuildingType.Settlement, threePlayers.head))
println(stateAssigned.map(_.assignedBuildings))
stateAssigned should be(None)
}
12 changes: 6 additions & 6 deletions src/test/scala/scatan/model/game/ops/ResCardOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ class ResCardOpsTest extends BaseScatanStateTest:
val spotWhereToBuild = state.emptyStructureSpot.filter(_.contains(hexagonWithSheep)).iterator
// simulate initial placement
val stateWithBuildings = state
.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.head)
.flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.head))
.flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.tail.head))
.flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.tail.head))
.flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.tail.head))
.flatMap(_.assignBuilding(spotWhereToBuild.next(), BuildingType.Settlement, state.players.head))
.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.head)
.flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.head))
.flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.tail.head))
.flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.tail.head))
.flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.tail.head))
.flatMap(_.assignSettlmentWithoutRule(spotWhereToBuild.next(), state.players.head))
stateWithBuildings match
case Some(state) =>
state.assignResourcesAfterInitialPlacement match
Expand Down
20 changes: 10 additions & 10 deletions src/test/scala/scatan/model/game/ops/ScoreOpsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ class ScoreOpsTest extends BaseScatanStateTest:
val player1 = threePlayers.head
val it = state.emptyStructureSpot.iterator
val stateWithAWinner = for
oneSettlementState <- state.assignBuilding(it.next, BuildingType.Settlement, player1)
twoSettlementState <- oneSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
threeSettlementState <- twoSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
fourSettlementState <- threeSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
fiveSettlementState <- fourSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
sixSettlementState <- fiveSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
sevenSettlementState <- sixSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
eightSettlementState <- sevenSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
nineSettlementState <- eightSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
tenSettlementState <- nineSettlementState.assignBuilding(it.next, BuildingType.Settlement, player1)
oneSettlementState <- state.assignSettlmentWithoutRule(it.next, player1)
twoSettlementState <- oneSettlementState.assignSettlmentWithoutRule(it.next, player1)
threeSettlementState <- twoSettlementState.assignSettlmentWithoutRule(it.next, player1)
fourSettlementState <- threeSettlementState.assignSettlmentWithoutRule(it.next, player1)
fiveSettlementState <- fourSettlementState.assignSettlmentWithoutRule(it.next, player1)
sixSettlementState <- fiveSettlementState.assignSettlmentWithoutRule(it.next, player1)
sevenSettlementState <- sixSettlementState.assignSettlmentWithoutRule(it.next, player1)
eightSettlementState <- sevenSettlementState.assignSettlmentWithoutRule(it.next, player1)
nineSettlementState <- eightSettlementState.assignSettlmentWithoutRule(it.next, player1)
tenSettlementState <- nineSettlementState.assignSettlmentWithoutRule(it.next, player1)
yield tenSettlementState

stateWithAWinner match
Expand Down

0 comments on commit 713b086

Please sign in to comment.