summaryrefslogtreecommitdiff
path: root/game-engine/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'game-engine/src/test/kotlin')
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt5
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt37
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt33
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt3
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/RequirementsTest.kt39
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt55
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt16
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt13
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt21
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt19
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt5
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt2
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt35
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt24
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.kt47
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ProductionTest.kt19
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt22
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/wonders/WonderTest.kt14
18 files changed, 192 insertions, 217 deletions
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
index 6ec279b6..5f76b42e 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/GameTest.kt
@@ -85,7 +85,7 @@ class GameTest {
val requiredResources = handCard.card.requirements.resources
val table = turnInfo.table
val playerIndex = turnInfo.playerIndex
- val transactions = bestTransaction(requiredResources, table, playerIndex)
+ val transactions = bestTransaction(requiredResources, PlayerContext(playerIndex, table, listOf()))
// we're supposed to have a best transaction plan because the card is playable
return transactions!!.asList()
}
@@ -100,11 +100,10 @@ class GameTest {
private fun checkLastPlayedMoves(sentMoves: Map<Int, PlayerMove>, table: Table) {
for (move in table.lastPlayedMoves) {
- val sentMove = sentMoves[move.playerIndex]
+ val sentMove = sentMoves[move.playerContext.index]
assertNotNull(sentMove)
assertNotNull(move.card)
assertEquals(sentMove!!.cardName, move.card.name)
- assertSame(sentMove.type, move.type)
}
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
index 7c23bbd0..68799145 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/BoardTest.kt
@@ -12,7 +12,6 @@ import org.junit.experimental.theories.Theory
import org.junit.rules.ExpectedException
import org.junit.runner.RunWith
import org.luxons.sevenwonders.game.Settings
-import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.boards.Board.InsufficientFundsException
import org.luxons.sevenwonders.game.cards.Color
import org.luxons.sevenwonders.game.effects.RawPointsIncrease
@@ -24,6 +23,7 @@ import org.luxons.sevenwonders.game.test.addCards
import org.luxons.sevenwonders.game.test.createResources
import org.luxons.sevenwonders.game.test.getDifferentColorFrom
import org.luxons.sevenwonders.game.test.playCardWithEffect
+import org.luxons.sevenwonders.game.test.singleBoardPlayer
import org.luxons.sevenwonders.game.test.testBoard
import org.luxons.sevenwonders.game.test.testCard
import org.luxons.sevenwonders.game.test.testCustomizableSettings
@@ -128,10 +128,9 @@ class BoardTest {
@Theory
fun hasSpecial(applied: SpecialAbility, tested: SpecialAbility) {
val board = testBoard(ResourceType.CLAY)
- val table = Table(listOf(board))
val special = SpecialAbilityActivation(applied)
- special.apply(table, 0)
+ special.applyTo(singleBoardPlayer(board))
assertEquals(applied === tested, board.hasSpecial(tested))
}
@@ -139,10 +138,9 @@ class BoardTest {
@Test
fun canPlayFreeCard() {
val board = testBoard(ResourceType.CLAY)
- val table = Table(listOf(board))
val special = SpecialAbilityActivation(SpecialAbility.ONE_FREE_PER_AGE)
- special.apply(table, 0)
+ special.applyTo(singleBoardPlayer(board))
assertTrue(board.canPlayFreeCard(0))
assertTrue(board.canPlayFreeCard(1))
@@ -171,10 +169,9 @@ class BoardTest {
fun computePoints_gold(@FromDataPoints("gold") gold: Int) {
assumeTrue(gold >= 0)
val board = testBoard(ResourceType.WOOD)
- val table = Table(listOf(board))
board.gold = gold
- val score = board.computePoints(table)
+ val score = board.computeScore(singleBoardPlayer(board))
assertEquals(gold / 3, score.pointsByCategory[ScoreCategory.GOLD])
assertEquals(gold / 3, score.totalPoints)
}
@@ -183,48 +180,38 @@ class BoardTest {
fun computePoints_(@FromDataPoints("gold") gold: Int) {
assumeTrue(gold >= 0)
val board = testBoard(ResourceType.WOOD)
- val table = Table(listOf(board))
board.gold = gold
val effect = RawPointsIncrease(5)
- playCardWithEffect(table, 0, Color.BLUE, effect)
+ playCardWithEffect(singleBoardPlayer(board), Color.BLUE, effect)
- val score = board.computePoints(table)
+ val score = board.computeScore(singleBoardPlayer(board))
assertEquals(gold / 3, score.pointsByCategory[ScoreCategory.GOLD])
assertEquals(5, score.pointsByCategory[ScoreCategory.CIVIL])
assertEquals(5 + gold / 3, score.totalPoints)
}
+
companion object {
@JvmStatic
@DataPoints("gold")
- fun goldAmounts(): IntArray {
- return intArrayOf(-3, -1, 0, 1, 2, 3)
- }
+ fun goldAmounts(): IntArray = intArrayOf(-3, -1, 0, 1, 2, 3)
@JvmStatic
@DataPoints("nbCards")
- fun nbCards(): IntArray {
- return intArrayOf(0, 1, 2)
- }
+ fun nbCards(): IntArray = intArrayOf(0, 1, 2)
@JvmStatic
@DataPoints
- fun resourceTypes(): Array<ResourceType> {
- return ResourceType.values()
- }
+ fun resourceTypes(): Array<ResourceType> = ResourceType.values()
@JvmStatic
@DataPoints
- fun colors(): Array<Color> {
- return Color.values()
- }
+ fun colors(): Array<Color> = Color.values()
@JvmStatic
@DataPoints
- fun specialAbilities(): Array<SpecialAbility> {
- return SpecialAbility.values()
- }
+ fun specialAbilities(): Array<SpecialAbility> = SpecialAbility.values()
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
index 783e4c38..e9f95b55 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
@@ -1,9 +1,9 @@
package org.luxons.sevenwonders.game.cards
-import org.junit.Assert.*
-import org.junit.Before
+import org.junit.Assert.assertEquals
import org.junit.Test
import org.luxons.sevenwonders.game.Settings
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.boards.Board
import org.luxons.sevenwonders.game.effects.ProductionIncrease
@@ -15,12 +15,8 @@ import org.luxons.sevenwonders.game.wonders.Wonder
class CardTest {
- private var table: Table? = null
-
- private var treeFarmCard: Card? = null
-
- @Before
- fun initBoard() {
+ @Test
+ fun playCardCostingMoney() {
val settings = Settings(3)
val boards = listOf(
@@ -28,24 +24,21 @@ class CardTest {
Board(Wonder("TestWonder", ResourceType.STONE, emptyList(), ""), 1, settings),
Board(Wonder("TestWonder", ResourceType.PAPYRUS, emptyList(), ""), 2, settings)
)
- table = Table(boards)
+ val table = Table(boards)
val treeFarmRequirements = Requirements(1)
val treeFarmProduction = Production()
treeFarmProduction.addChoice(ResourceType.WOOD, ResourceType.CLAY)
val treeFarmEffect = ProductionIncrease(treeFarmProduction, false)
- treeFarmCard = testCard("Tree Farm", Color.BROWN, treeFarmEffect, treeFarmRequirements)
- }
+ val treeFarmCard = testCard("Tree Farm", Color.BROWN, treeFarmEffect, treeFarmRequirements)
- @Test
- fun playCardCostingMoney() {
- table!!.getBoard(0).gold = 3
- table!!.getBoard(1).gold = 3
- table!!.getBoard(2).gold = 3
- treeFarmCard!!.applyTo(table!!, 0, ResourceTransactions())
- assertEquals(2, table!!.getBoard(0).gold.toLong())
- assertEquals(3, table!!.getBoard(1).gold.toLong())
- assertEquals(3, table!!.getBoard(2).gold.toLong())
+ table.getBoard(0).gold = 3
+ table.getBoard(1).gold = 3
+ table.getBoard(2).gold = 3
+ treeFarmCard.applyTo(SimplePlayer(0, table), ResourceTransactions())
+ assertEquals(2, table.getBoard(0).gold.toLong())
+ assertEquals(3, table.getBoard(1).gold.toLong())
+ assertEquals(3, table.getBoard(2).gold.toLong())
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
index 7ba21089..e7c3835a 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/HandsTest.kt
@@ -8,6 +8,7 @@ import org.junit.experimental.theories.FromDataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.test.sampleCards
import org.luxons.sevenwonders.game.test.testTable
@@ -97,7 +98,7 @@ class HandsTest {
val hands = Hands(listOf(hand0, hand1))
val table = testTable(2)
- val hand = hands.createHand(table, 0)
+ val hand = hands.createHand(SimplePlayer(0, table))
for (handCard in hand) {
assertTrue(hand0.contains(handCard.card))
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/RequirementsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/RequirementsTest.kt
index 196091a6..95a5e174 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/RequirementsTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/RequirementsTest.kt
@@ -1,26 +1,23 @@
package org.luxons.sevenwonders.game.cards
-import java.util.Arrays
-import java.util.Collections
-
+import org.junit.Assert.*
+import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.api.Table
-import org.luxons.sevenwonders.game.boards.Board
import org.luxons.sevenwonders.game.resources.Provider
import org.luxons.sevenwonders.game.resources.ResourceTransactions
import org.luxons.sevenwonders.game.resources.ResourceType
import org.luxons.sevenwonders.game.resources.Resources
-import org.luxons.sevenwonders.game.test.*
-
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertFalse
-import org.junit.Assert.assertSame
-import org.junit.Assert.assertTrue
-import org.junit.Assume.assumeTrue
+import org.luxons.sevenwonders.game.test.createRequirements
+import org.luxons.sevenwonders.game.test.createTransactions
+import org.luxons.sevenwonders.game.test.singleBoardPlayer
+import org.luxons.sevenwonders.game.test.testBoard
+import java.util.Arrays
@RunWith(Theories::class)
class RequirementsTest {
@@ -43,11 +40,11 @@ class RequirementsTest {
val requirements = Requirements(requiredGold)
val board = testBoard(ResourceType.CLAY, boardGold)
- val table = Table(listOf(board))
+ val player = singleBoardPlayer(board)
assertEquals(boardGold >= requiredGold, requirements.areMetWithoutNeighboursBy(board))
assertEquals(boardGold >= requiredGold, requirements.areMetWithHelpBy(board, ResourceTransactions()))
- assertEquals(boardGold >= requiredGold, requirements.areMetBy(table, 0))
+ assertEquals(boardGold >= requiredGold, requirements.areMetBy(player))
}
@Theory
@@ -55,7 +52,7 @@ class RequirementsTest {
val requirements = createRequirements(requiredResource)
val board = testBoard(initialResource, 0)
- val table = Table(listOf(board))
+ val player = singleBoardPlayer(board)
assertEquals(initialResource == requiredResource, requirements.areMetWithoutNeighboursBy(board))
assertEquals(
@@ -64,7 +61,7 @@ class RequirementsTest {
)
if (initialResource == requiredResource) {
- assertTrue(requirements.areMetBy(table, 0))
+ assertTrue(requirements.areMetBy(player))
}
}
@@ -79,7 +76,7 @@ class RequirementsTest {
val board = testBoard(initialResource, 0)
board.production.addFixedResource(producedResource, 1)
- val table = Table(listOf(board))
+ val player = singleBoardPlayer(board)
assertEquals(producedResource == requiredResource, requirements.areMetWithoutNeighboursBy(board))
assertEquals(
@@ -88,7 +85,7 @@ class RequirementsTest {
)
if (producedResource == requiredResource) {
- assertTrue(requirements.areMetBy(table, 0))
+ assertTrue(requirements.areMetBy(player))
}
}
@@ -105,6 +102,7 @@ class RequirementsTest {
val neighbourBoard = testBoard(initialResource, 0)
neighbourBoard.publicProduction.addFixedResource(boughtResource, 1)
val table = Table(Arrays.asList(board, neighbourBoard))
+ val player = SimplePlayer(0, table)
val resources = createTransactions(Provider.RIGHT_PLAYER, boughtResource)
@@ -112,7 +110,7 @@ class RequirementsTest {
assertEquals(boughtResource == requiredResource, requirements.areMetWithHelpBy(board, resources))
if (boughtResource == requiredResource) {
- assertTrue(requirements.areMetBy(table, 0))
+ assertTrue(requirements.areMetBy(player))
}
}
@@ -125,6 +123,7 @@ class RequirementsTest {
val board = testBoard(initialResource, 2)
val neighbourBoard = testBoard(requiredResource, 0)
val table = Table(Arrays.asList(board, neighbourBoard))
+ val player = SimplePlayer(0, table)
val transactions = createTransactions(
Provider.RIGHT_PLAYER,
@@ -133,9 +132,9 @@ class RequirementsTest {
assertFalse(requirements.areMetWithoutNeighboursBy(board))
assertTrue(requirements.areMetWithHelpBy(board, transactions))
- assertTrue(requirements.areMetBy(table, 0))
+ assertTrue(requirements.areMetBy(player))
- requirements.pay(table, 0, transactions)
+ requirements.pay(player, transactions)
assertEquals(0, board.gold.toLong())
assertEquals(2, neighbourBoard.gold.toLong())
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt
index 3f0b0aa0..8899eb06 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt
@@ -1,45 +1,47 @@
package org.luxons.sevenwonders.game.effects
+import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.Player
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
import org.luxons.sevenwonders.game.cards.CardBack
import org.luxons.sevenwonders.game.cards.Color
-import org.luxons.sevenwonders.game.test.*
-
-import org.junit.Assert.assertEquals
+import org.luxons.sevenwonders.game.test.addCards
+import org.luxons.sevenwonders.game.test.testTable
@RunWith(Theories::class)
class BonusPerBoardElementTest {
private var table: Table? = null
+ private var player0: Player? = null
@Before
fun setUp() {
table = testTable(4)
+ player0 = SimplePlayer(0, table!!)
}
@Theory
fun computePoints_countsCards(
- boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int,
- points: Int, gold: Int, color: Color
+ boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int, points: Int, gold: Int, color: Color
) {
val board = table!!.getBoard(0, boardPosition)
addCards(board, nbCards, nbOtherCards, color)
val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.CARD, gold, points, listOf(color))
- assertEquals((nbCards * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ assertEquals((nbCards * points).toLong(), bonus.computePoints(player0!!).toLong())
}
@Theory
fun computePoints_countsDefeatTokens(
- boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int,
- gold: Int
+ boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int, gold: Int
) {
val board = table!!.getBoard(0, boardPosition)
for (i in 0 until nbDefeatTokens) {
@@ -48,29 +50,25 @@ class BonusPerBoardElementTest {
val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.DEFEAT_TOKEN, gold, points, listOf())
- assertEquals((nbDefeatTokens * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ assertEquals((nbDefeatTokens * points).toLong(), bonus.computePoints(player0!!).toLong())
}
@Theory
- fun computePoints_countsWonderStages(
- boardPosition: RelativeBoardPosition, nbStages: Int, points: Int,
- gold: Int
- ) {
+ fun computePoints_countsWonderStages(boardPosition: RelativeBoardPosition, nbStages: Int, points: Int, gold: Int) {
val board = table!!.getBoard(0, boardPosition)
for (i in 0 until nbStages) {
- board.wonder.buildLevel(CardBack(""))
+ board.wonder.placeCard(CardBack(""))
}
val bonus =
BonusPerBoardElement(listOf(boardPosition), BoardElementType.BUILT_WONDER_STAGES, gold, points, listOf())
- assertEquals((nbStages * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ assertEquals((nbStages * points).toLong(), bonus.computePoints(player0!!).toLong())
}
@Theory
fun apply_countsCards(
- boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int, points: Int,
- gold: Int, color: Color
+ boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int, points: Int, gold: Int, color: Color
) {
val board = table!!.getBoard(0, boardPosition)
addCards(board, nbCards, nbOtherCards, color)
@@ -79,14 +77,13 @@ class BonusPerBoardElementTest {
val selfBoard = table!!.getBoard(0)
val initialGold = selfBoard.gold
- bonus.apply(table!!, 0)
+ bonus.applyTo(player0!!)
assertEquals((initialGold + nbCards * gold).toLong(), selfBoard.gold.toLong())
}
@Theory
fun apply_countsDefeatTokens(
- boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int,
- gold: Int
+ boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int, gold: Int
) {
val board = table!!.getBoard(0, boardPosition)
for (i in 0 until nbDefeatTokens) {
@@ -97,7 +94,7 @@ class BonusPerBoardElementTest {
val selfBoard = table!!.getBoard(0)
val initialGold = selfBoard.gold
- bonus.apply(table!!, 0)
+ bonus.applyTo(player0!!)
assertEquals((initialGold + nbDefeatTokens * gold).toLong(), selfBoard.gold.toLong())
}
@@ -105,7 +102,7 @@ class BonusPerBoardElementTest {
fun apply_countsWonderStages(boardPosition: RelativeBoardPosition, nbStages: Int, points: Int, gold: Int) {
val board = table!!.getBoard(0, boardPosition)
for (i in 0 until nbStages) {
- board.wonder.buildLevel(CardBack(""))
+ board.wonder.placeCard(CardBack(""))
}
val bonus =
@@ -113,7 +110,7 @@ class BonusPerBoardElementTest {
val selfBoard = table!!.getBoard(0)
val initialGold = selfBoard.gold
- bonus.apply(table!!, 0)
+ bonus.applyTo(player0!!)
assertEquals((initialGold + nbStages * gold).toLong(), selfBoard.gold.toLong())
}
@@ -121,20 +118,14 @@ class BonusPerBoardElementTest {
@JvmStatic
@DataPoints
- fun values(): IntArray {
- return intArrayOf(0, 1, 2, 3)
- }
+ fun values(): IntArray = intArrayOf(0, 1, 2, 3)
@JvmStatic
@DataPoints
- fun colors(): Array<Color> {
- return Color.values()
- }
+ fun colors(): Array<Color> = Color.values()
@JvmStatic
@DataPoints
- fun positions(): Array<RelativeBoardPosition> {
- return RelativeBoardPosition.values()
- }
+ fun positions(): Array<RelativeBoardPosition> = RelativeBoardPosition.values()
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt
index e228d585..2cd54b2e 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt
@@ -18,7 +18,7 @@ class DiscountTest {
fun apply_givesDiscountedPrice(discountedPrice: Int, discountedType: ResourceType, provider: Provider) {
val board = testBoard(ResourceType.CLAY, 3)
val discount = Discount(listOf(discountedType), listOf(provider), discountedPrice)
- discount.apply(board)
+ discount.applyTo(board)
val transactions = createTransactions(provider, discountedType)
assertEquals(discountedPrice.toLong(), board.tradingRules.computeCost(transactions).toLong())
@@ -34,7 +34,7 @@ class DiscountTest {
val board = testBoard(ResourceType.CLAY, 3)
val discount = Discount(listOf(discountedType), listOf(provider), discountedPrice)
- discount.apply(board)
+ discount.applyTo(board)
// this is the default in the settings used by TestUtilsKt.testBoard()
val normalPrice = 2
@@ -53,20 +53,14 @@ class DiscountTest {
@JvmStatic
@DataPoints
- fun discountedPrices(): IntArray {
- return intArrayOf(0, 1, 2)
- }
+ fun discountedPrices(): IntArray = intArrayOf(0, 1, 2)
@JvmStatic
@DataPoints
- fun resourceTypes(): Array<ResourceType> {
- return ResourceType.values()
- }
+ fun resourceTypes(): Array<ResourceType> = ResourceType.values()
@JvmStatic
@DataPoints
- fun providers(): Array<Provider> {
- return Provider.values()
- }
+ fun providers(): Array<Provider> = Provider.values()
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt
index 175f15ea..897dcf30 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt
@@ -1,13 +1,14 @@
package org.luxons.sevenwonders.game.effects
+import org.junit.Assert.assertEquals
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.resources.ResourceType
-import org.luxons.sevenwonders.game.test.*
-
-import org.junit.Assert.assertEquals
+import org.luxons.sevenwonders.game.test.testBoard
+import org.luxons.sevenwonders.game.test.testTable
@RunWith(Theories::class)
class GoldIncreaseTest {
@@ -17,7 +18,7 @@ class GoldIncreaseTest {
val board = testBoard(type, initialAmount)
val goldIncrease = GoldIncrease(goldIncreaseAmount)
- goldIncrease.apply(board)
+ goldIncrease.applyTo(board)
assertEquals((initialAmount + goldIncreaseAmount).toLong(), board.gold.toLong())
}
@@ -25,8 +26,8 @@ class GoldIncreaseTest {
@Theory
fun computePoints_isAlwaysZero(gold: Int) {
val goldIncrease = GoldIncrease(gold)
- val table = testTable(5)
- assertEquals(0, goldIncrease.computePoints(table, 0).toLong())
+ val player = SimplePlayer(0, testTable(5))
+ assertEquals(0, goldIncrease.computePoints(player).toLong())
}
companion object {
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt
index a8bd01d6..fce3d2bd 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt
@@ -1,13 +1,14 @@
package org.luxons.sevenwonders.game.effects
+import org.junit.Assert.assertEquals
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.resources.ResourceType
-import org.luxons.sevenwonders.game.test.*
-
-import org.junit.Assert.assertEquals
+import org.luxons.sevenwonders.game.test.testBoard
+import org.luxons.sevenwonders.game.test.testTable
@RunWith(Theories::class)
class MilitaryReinforcementsTest {
@@ -18,7 +19,7 @@ class MilitaryReinforcementsTest {
board.military.addShields(initialShields)
val reinforcements = MilitaryReinforcements(additionalShields)
- reinforcements.apply(board)
+ reinforcements.applyTo(board)
assertEquals((initialShields + additionalShields).toLong(), board.military.nbShields.toLong())
}
@@ -26,22 +27,18 @@ class MilitaryReinforcementsTest {
@Theory
fun computePoints_isAlwaysZero(shields: Int) {
val reinforcements = MilitaryReinforcements(shields)
- val table = testTable(5)
- assertEquals(0, reinforcements.computePoints(table, 0).toLong())
+ val player = SimplePlayer(0, testTable(5))
+ assertEquals(0, reinforcements.computePoints(player).toLong())
}
companion object {
@JvmStatic
@DataPoints
- fun shieldCounts(): IntArray {
- return intArrayOf(0, 1, 2, 3, 5)
- }
+ fun shieldCounts(): IntArray = intArrayOf(0, 1, 2, 3, 5)
@JvmStatic
@DataPoints
- fun resourceTypes(): Array<ResourceType> {
- return ResourceType.values()
- }
+ fun resourceTypes(): Array<ResourceType> = ResourceType.values()
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt
index 6f8da55d..9d5be34f 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt
@@ -1,15 +1,16 @@
package org.luxons.sevenwonders.game.effects
+import org.junit.Assert.*
import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.resources.ResourceType
-import org.luxons.sevenwonders.game.test.*
-
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertFalse
-import org.junit.Assert.assertTrue
+import org.luxons.sevenwonders.game.test.createResources
+import org.luxons.sevenwonders.game.test.fixedProduction
+import org.luxons.sevenwonders.game.test.testBoard
+import org.luxons.sevenwonders.game.test.testTable
@RunWith(Theories::class)
class ProductionIncreaseTest {
@@ -23,7 +24,7 @@ class ProductionIncreaseTest {
val board = testBoard(initialType)
val effect = ProductionIncrease(fixedProduction(addedType), false)
- effect.apply(board)
+ effect.applyTo(board)
val resources = createResources(initialType, addedType)
assertTrue(board.production.contains(resources))
@@ -43,7 +44,7 @@ class ProductionIncreaseTest {
val board = testBoard(initialType)
val effect = ProductionIncrease(fixedProduction(addedType), true)
- effect.apply(board)
+ effect.applyTo(board)
val resources = createResources(initialType, addedType)
assertTrue(board.production.contains(resources))
@@ -57,8 +58,8 @@ class ProductionIncreaseTest {
@Theory
fun computePoints_isAlwaysZero(addedType: ResourceType) {
val effect = ProductionIncrease(fixedProduction(addedType), false)
- val table = testTable(5)
- assertEquals(0, effect.computePoints(table, 0).toLong())
+ val player = SimplePlayer(0, testTable(5))
+ assertEquals(0, effect.computePoints(player).toLong())
}
companion object {
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt
index 844c28eb..2cdf6781 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt
@@ -5,6 +5,7 @@ import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.test.testTable
@RunWith(Theories::class)
@@ -13,8 +14,8 @@ class RawPointsIncreaseTest {
@Theory
fun computePoints_equalsNbOfPoints(points: Int) {
val rawPointsIncrease = RawPointsIncrease(points)
- val table = testTable(5)
- assertEquals(points.toLong(), rawPointsIncrease.computePoints(table, 0).toLong())
+ val player = SimplePlayer(0, testTable(5))
+ assertEquals(points.toLong(), rawPointsIncrease.computePoints(player).toLong())
}
companion object {
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt
index cbea1581..db13e641 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt
@@ -24,7 +24,7 @@ class ScienceProgressTest {
board.science.addAll(initialScience)
val effect = createScienceProgress(compasses, wheels, tablets, jokers)
- effect.apply(board)
+ effect.applyTo(board)
assertEquals((initCompasses + compasses).toLong(), board.science.getQuantity(ScienceType.COMPASS).toLong())
assertEquals((initWheels + wheels).toLong(), board.science.getQuantity(ScienceType.WHEEL).toLong())
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
index 0531022d..eeaa5047 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
@@ -8,6 +8,7 @@ import org.junit.experimental.theories.DataPoints
import org.junit.experimental.theories.Theories
import org.junit.experimental.theories.Theory
import org.junit.runner.RunWith
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
import org.luxons.sevenwonders.game.cards.Card
import org.luxons.sevenwonders.game.cards.Color
@@ -20,12 +21,11 @@ class SpecialAbilityActivationTest {
@Theory
fun apply_addsAbility(ability: SpecialAbility) {
val effect = SpecialAbilityActivation(ability)
- val table = testTable(5)
+ val player = SimplePlayer(0, testTable(5))
- effect.apply(table, 0)
+ effect.applyTo(player)
- val board = table.getBoard(0)
- assertTrue(board.hasSpecial(ability))
+ assertTrue(player.board.hasSpecial(ability))
}
@Theory
@@ -33,46 +33,41 @@ class SpecialAbilityActivationTest {
Assume.assumeTrue(ability !== SpecialAbility.COPY_GUILD)
val effect = SpecialAbilityActivation(ability)
- val table = testTable(5)
+ val player = SimplePlayer(0, testTable(5))
- assertEquals(0, effect.computePoints(table, 0).toLong())
+ assertEquals(0, effect.computePoints(player).toLong())
}
@Theory
fun computePoints_copiedGuild(guildCard: Card, neighbour: RelativeBoardPosition) {
val effect = SpecialAbilityActivation(SpecialAbility.COPY_GUILD)
- val table = testTable(5)
+ val player = SimplePlayer(0, testTable(5))
- val neighbourBoard = table.getBoard(0, neighbour)
+ val neighbourBoard = player.getBoard(neighbour)
neighbourBoard.addCard(guildCard)
- val board = table.getBoard(0)
- board.copiedGuild = guildCard
+ player.board.copiedGuild = guildCard
- val directPointsFromGuildCard = guildCard.effects.stream().mapToInt { e -> e.computePoints(table, 0) }.sum()
- assertEquals(directPointsFromGuildCard.toLong(), effect.computePoints(table, 0).toLong())
+ val directPointsFromGuildCard = guildCard.effects.stream().mapToInt { e -> e.computePoints(player) }.sum()
+ assertEquals(directPointsFromGuildCard.toLong(), effect.computePoints(player).toLong())
}
@Test(expected = IllegalStateException::class)
fun computePoints_copyGuild_failWhenNoChosenGuild() {
val effect = SpecialAbilityActivation(SpecialAbility.COPY_GUILD)
- val table = testTable(5)
- effect.computePoints(table, 0)
+ val player = SimplePlayer(0, testTable(5))
+ effect.computePoints(player)
}
companion object {
@JvmStatic
@DataPoints
- fun abilities(): Array<SpecialAbility> {
- return SpecialAbility.values()
- }
+ fun abilities(): Array<SpecialAbility> = SpecialAbility.values()
@JvmStatic
@DataPoints
- fun neighbours(): Array<RelativeBoardPosition> {
- return arrayOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)
- }
+ fun neighbours(): Array<RelativeBoardPosition> = arrayOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)
@JvmStatic
@DataPoints
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
index ee461e38..d1b380e0 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/moves/BuildWonderMoveTest.kt
@@ -3,6 +3,7 @@ package org.luxons.sevenwonders.game.moves
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Test
+import org.luxons.sevenwonders.game.PlayerContext
import org.luxons.sevenwonders.game.Settings
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.cards.Card
@@ -15,17 +16,16 @@ import org.luxons.sevenwonders.game.test.testTable
class BuildWonderMoveTest {
@Test(expected = InvalidMoveException::class)
- fun validate_failsWhenCardNotInHand() {
+ fun init_failsWhenCardNotInHand() {
val table = testTable(3)
val hand = sampleCards(0, 7)
+ val playerContext = PlayerContext(0, table, hand)
val anotherCard = testCard("Card that is not in the hand")
- val move = createMove(0, anotherCard, MoveType.UPGRADE_WONDER)
-
- move.validate(table, hand)
+ createMove(playerContext, anotherCard, MoveType.UPGRADE_WONDER)
}
@Test(expected = InvalidMoveException::class)
- fun validate_failsWhenWonderIsCompletelyBuilt() {
+ fun init_failsWhenWonderIsCompletelyBuilt() {
val settings = testSettings(3)
val table = testTable(settings)
val hand = sampleCards(0, 7)
@@ -49,10 +49,10 @@ class BuildWonderMoveTest {
private fun buildOneWonderLevel(settings: Settings, table: Table, hand: List<Card>, cardIndex: Int) {
val card = hand[cardIndex]
- val move = createMove(0, card, MoveType.UPGRADE_WONDER)
- move.validate(table, hand)
- move.place(table, mutableListOf(), settings)
- move.activate(table, emptyList(), settings)
+ val playerContext = PlayerContext(0, table, hand)
+ val move = createMove(playerContext, card, MoveType.UPGRADE_WONDER)
+ move.place(mutableListOf(), settings)
+ move.activate(emptyList(), settings)
}
@Test
@@ -61,12 +61,12 @@ class BuildWonderMoveTest {
val table = testTable(settings)
val hand = sampleCards(0, 7)
val cardToUse = hand[0]
- val move = createMove(0, cardToUse, MoveType.UPGRADE_WONDER)
- move.validate(table, hand) // should not fail
+ val playerContext = PlayerContext(0, table, hand)
+ val move = createMove(playerContext, cardToUse, MoveType.UPGRADE_WONDER)
val initialStage = table.getBoard(0).wonder.nbBuiltStages
- move.place(table, mutableListOf(), settings)
+ move.place(mutableListOf(), settings)
val newStage = table.getBoard(0).wonder.nbBuiltStages
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.kt
index 005959bc..ca279d97 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.kt
@@ -2,6 +2,7 @@ package org.luxons.sevenwonders.game.resources
import org.junit.Assert.assertEquals
import org.junit.Test
+import org.luxons.sevenwonders.game.SimplePlayer
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.resources.Provider.LEFT_PLAYER
import org.luxons.sevenwonders.game.resources.Provider.RIGHT_PLAYER
@@ -18,9 +19,10 @@ class BestPriceCalculatorTest {
@Test
fun bestPrice_0forEmptyResources() {
val table = testTable(3)
+ val player0 = SimplePlayer(0, table)
val emptyResources = Resources()
val emptyTransactions = ResourceTransactions()
- assertEquals(TransactionPlan(0, emptyTransactions), bestSolution(emptyResources, table, 0))
+ assertEquals(TransactionPlan(0, emptyTransactions), bestSolution(emptyResources, player0))
}
@Test
@@ -29,6 +31,10 @@ class BestPriceCalculatorTest {
val main = testBoard(STONE)
val right = testBoard(WOOD)
val table = Table(Arrays.asList(main, right, left))
+
+ val player0 = SimplePlayer(0, table)
+ val player1 = SimplePlayer(1, table)
+ val player2 = SimplePlayer(2, table)
val resources = createResources(STONE, STONE)
@@ -39,9 +45,9 @@ class BestPriceCalculatorTest {
val stoneRight = createTransactions(stoneRightSingle)
val stoneLeftAndRight = createTransactions(stoneLeftSingle, stoneRightSingle)
- assertEquals(TransactionPlan(2, stoneLeft), bestSolution(resources, table, 0))
- assertEquals(TransactionPlan(4, stoneLeftAndRight), bestSolution(resources, table, 1))
- assertEquals(TransactionPlan(2, stoneRight), bestSolution(resources, table, 2))
+ assertEquals(TransactionPlan(2, stoneLeft), bestSolution(resources, player0))
+ assertEquals(TransactionPlan(4, stoneLeftAndRight), bestSolution(resources, player1))
+ assertEquals(TransactionPlan(2, stoneRight), bestSolution(resources, player2))
}
@Test
@@ -54,15 +60,20 @@ class BestPriceCalculatorTest {
val opposite = testBoard(GLASS)
val table = Table(Arrays.asList(main, right, opposite, left))
+ val player0 = SimplePlayer(0, table)
+ val player1 = SimplePlayer(1, table)
+ val player2 = SimplePlayer(2, table)
+ val player3 = SimplePlayer(3, table)
+
val resources = createResources(WOOD)
val woodLeft = createTransactions(LEFT_PLAYER, WOOD)
val woodRight = createTransactions(RIGHT_PLAYER, WOOD)
- assertEquals(TransactionPlan(1, woodRight), bestSolution(resources, table, 0))
- assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, table, 1))
- assertEquals(TransactionPlan(2, woodLeft), bestSolution(resources, table, 2))
- assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, table, 3))
+ assertEquals(TransactionPlan(1, woodRight), bestSolution(resources, player0))
+ assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, player1))
+ assertEquals(TransactionPlan(2, woodLeft), bestSolution(resources, player2))
+ assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, player3))
}
@Test
@@ -78,12 +89,16 @@ class BestPriceCalculatorTest {
val table = Table(Arrays.asList(main, right, left))
+ val player0 = SimplePlayer(0, table)
+ val player1 = SimplePlayer(1, table)
+ val player2 = SimplePlayer(2, table)
+
val resources = createResources(WOOD)
val woodRight = createTransactions(RIGHT_PLAYER, WOOD)
- assertEquals(TransactionPlan(1, woodRight), bestSolution(resources, table, 0))
- assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, table, 1))
- assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, table, 2))
+ assertEquals(TransactionPlan(1, woodRight), bestSolution(resources, player0))
+ assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, player1))
+ assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, player2))
}
@Test
@@ -102,12 +117,16 @@ class BestPriceCalculatorTest {
val table = Table(Arrays.asList(main, right, left))
+ val player0 = SimplePlayer(0, table)
+ val player1 = SimplePlayer(1, table)
+ val player2 = SimplePlayer(2, table)
+
val resources = createResources(ORE, CLAY)
val oreAndClayLeft = createTransactions(LEFT_PLAYER, ORE, CLAY)
val clayRight = createTransactions(RIGHT_PLAYER, CLAY)
- assertEquals(TransactionPlan(1, clayRight), bestSolution(resources, table, 0))
- assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, table, 1))
- assertEquals(TransactionPlan(4, oreAndClayLeft), bestSolution(resources, table, 2))
+ assertEquals(TransactionPlan(1, clayRight), bestSolution(resources, player0))
+ assertEquals(TransactionPlan(0, ResourceTransactions()), bestSolution(resources, player1))
+ assertEquals(TransactionPlan(4, oreAndClayLeft), bestSolution(resources, player2))
}
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ProductionTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ProductionTest.kt
index ab0b22cf..92623a2b 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ProductionTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ProductionTest.kt
@@ -1,14 +1,10 @@
package org.luxons.sevenwonders.game.resources
-import java.util.EnumSet
-import java.util.HashSet
-
+import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
-
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertFalse
-import org.junit.Assert.assertTrue
+import java.util.EnumSet
+import java.util.HashSet
class ProductionTest {
@@ -266,15 +262,6 @@ class ProductionTest {
}
@Test
- fun equals_falseWhenNull() {
- val production = Production()
- production.addFixedResource(ResourceType.GLASS, 1)
- production.addChoice(ResourceType.ORE, ResourceType.WOOD)
-
- assertFalse(production == null)
- }
-
- @Test
fun equals_trueWhenSame() {
val production = Production()
assertEquals(production, production)
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
index feda9423..2208431d 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
@@ -1,10 +1,13 @@
package org.luxons.sevenwonders.game.test
+import org.luxons.sevenwonders.game.Player
+import org.luxons.sevenwonders.game.PlayerContext
import org.luxons.sevenwonders.game.Settings
import org.luxons.sevenwonders.game.api.CustomizableSettings
import org.luxons.sevenwonders.game.api.PlayerMove
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.boards.Board
+import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
import org.luxons.sevenwonders.game.boards.Science
import org.luxons.sevenwonders.game.boards.ScienceType
import org.luxons.sevenwonders.game.cards.Card
@@ -203,14 +206,21 @@ fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Scien
return science
}
-fun playCardWithEffect(table: Table, playerIndex: Int, color: Color, effect: Effect) {
+fun playCardWithEffect(player: Player, color: Color, effect: Effect) {
val card = testCard(color, effect)
- val board = table.getBoard(playerIndex)
- board.addCard(card)
- card.applyTo(table, playerIndex, ResourceTransactions())
+ player.board.addCard(card)
+ card.applyTo(player, ResourceTransactions())
}
-fun createMove(playerIndex: Int, card: Card, type: MoveType, vararg transactions: ResourceTransaction): Move {
+fun createMove(context: PlayerContext, card: Card, type: MoveType, vararg transactions: ResourceTransaction): Move {
val playerMove = PlayerMove(type, card.name, Arrays.asList(*transactions))
- return type.resolve(playerIndex, card, playerMove)
+ return type.create(playerMove, card, context)
+}
+
+fun singleBoardPlayer(board: Board): Player {
+ return object: Player {
+ override val index=0
+ override val board = board
+ override fun getBoard(relativePosition: RelativeBoardPosition): Board = board
+ }
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/wonders/WonderTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/wonders/WonderTest.kt
index 9270bcca..3d2f3a80 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/wonders/WonderTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/wonders/WonderTest.kt
@@ -13,22 +13,22 @@ class WonderTest {
fun buildLevel_increasesNbBuiltStages() {
val wonder = testWonder()
assertEquals(0, wonder.nbBuiltStages.toLong())
- wonder.buildLevel(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
assertEquals(1, wonder.nbBuiltStages.toLong())
- wonder.buildLevel(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
assertEquals(2, wonder.nbBuiltStages.toLong())
- wonder.buildLevel(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
assertEquals(3, wonder.nbBuiltStages.toLong())
}
@Test
fun buildLevel_failsIfFull() {
val wonder = testWonder()
- wonder.buildLevel(CardBack("img"))
- wonder.buildLevel(CardBack("img"))
- wonder.buildLevel(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
try {
- wonder.buildLevel(CardBack("img"))
+ wonder.placeCard(CardBack("img"))
fail()
} catch (e: IllegalStateException) {
// expected exception because there is no 4th level in this wonder
bgstack15