diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-02-19 18:09:27 +0100 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-02-19 19:01:52 +0100 |
commit | cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43 (patch) | |
tree | e2e6ce43eca9b20ef82589e174ac411c22a9f318 /game-engine | |
parent | Update repository URLs in README (diff) | |
download | seven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.tar.gz seven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.tar.bz2 seven-wonders-cab8a5a83e810d14c97fbb26f0cdfe1b86e88d43.zip |
Fix board gold access and cleanup tests
Diffstat (limited to 'game-engine')
38 files changed, 413 insertions, 572 deletions
diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt index 3cb14083..63d5052f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/Settings.kt @@ -1,15 +1,15 @@ package org.luxons.sevenwonders.game import org.luxons.sevenwonders.game.api.CustomizableSettings -import org.luxons.sevenwonders.game.data.definitions.WonderSide import org.luxons.sevenwonders.game.api.WonderSidePickMethod +import org.luxons.sevenwonders.game.data.definitions.WonderSide import java.util.Random internal class Settings( val nbPlayers: Int, customSettings: CustomizableSettings = CustomizableSettings() ) { - val random: Random + val random: Random = customSettings.randomSeedForTests?.let { Random(it) } ?: Random() val timeLimitInSeconds: Int = customSettings.timeLimitInSeconds val initialGold: Int = customSettings.initialGold val discardedCardGold: Int = customSettings.discardedCardGold @@ -21,11 +21,6 @@ internal class Settings( private val wonderSidePickMethod: WonderSidePickMethod = customSettings.wonderSidePickMethod private var lastPickedSide: WonderSide? = null - init { - val seed = customSettings.randomSeedForTests - this.random = if (seed != null) Random(seed) else Random() - } - fun pickWonderSide(): WonderSide { val newSide = wonderSidePickMethod.pickSide(random, lastPickedSide) lastPickedSide = newSide diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt index c4dbeb21..470f3ba0 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/api/Table.kt @@ -36,9 +36,9 @@ class Table internal constructor(val boards: List<Board>) { } internal fun resolveMilitaryConflicts() { - for (i in 0 until nbPlayers) { - val board1 = getBoard(i) - val board2 = getBoard(i, RelativeBoardPosition.RIGHT) + repeat(nbPlayers) { + val board1 = getBoard(it) + val board2 = getBoard(it, RelativeBoardPosition.RIGHT) resolveConflict(board1, board2) } } diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt index fc859931..ae00f23f 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/moves/MoveType.kt @@ -4,7 +4,7 @@ import org.luxons.sevenwonders.game.PlayerContext import org.luxons.sevenwonders.game.api.PlayerMove import org.luxons.sevenwonders.game.cards.Card -enum class MoveType(val create: (move: PlayerMove, card: Card, context: PlayerContext) -> Move) { +enum class MoveType(private val create: (move: PlayerMove, card: Card, context: PlayerContext) -> Move) { PLAY(::PlayCardMove), PLAY_FREE(::PlayFreeCardMove), UPGRADE_WONDER(::BuildWonderMove), diff --git a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt index 7e259023..5c92b887 100644 --- a/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt +++ b/game-engine/src/main/kotlin/org/luxons/sevenwonders/game/resources/ResourceType.kt @@ -1,6 +1,6 @@ package org.luxons.sevenwonders.game.resources -enum class ResourceType(val symbol: Char?) { +enum class ResourceType(val symbol: Char) { WOOD('W'), STONE('S'), ORE('O'), 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 9db75e56..05de1eb4 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 @@ -10,6 +10,7 @@ import org.luxons.sevenwonders.game.api.HandCard import org.luxons.sevenwonders.game.api.PlayerMove import org.luxons.sevenwonders.game.api.PlayerTurnInfo import org.luxons.sevenwonders.game.api.Table +import org.luxons.sevenwonders.game.data.GameDefinition import org.luxons.sevenwonders.game.data.LAST_AGE import org.luxons.sevenwonders.game.moves.MoveType import org.luxons.sevenwonders.game.resources.ResourceTransactions @@ -33,24 +34,22 @@ class GameTest { } private fun playAge(nbPlayers: Int, game: Game, age: Int) { - for (i in 0..5) { - playTurn(nbPlayers, game, age, 7 - i) + repeat(6) { + playTurn(nbPlayers, game, age, 7 - it) } } - private fun createGame(nbPlayers: Int): Game { - val settings = testCustomizableSettings() - return GameDefinition.load().initGame(0, settings, nbPlayers) - } + private fun createGame(nbPlayers: Int): Game = + GameDefinition.load().initGame(0, testCustomizableSettings(), nbPlayers) private fun playTurn(nbPlayers: Int, game: Game, ageToCheck: Int, handSize: Int) { val turnInfos = game.getCurrentTurnInfo() - assertEquals(nbPlayers.toLong(), turnInfos.size.toLong()) + assertEquals(nbPlayers, turnInfos.size) val sentMoves = HashMap<Int, PlayerMove>(turnInfos.size) for (turnInfo in turnInfos) { - assertEquals(ageToCheck.toLong(), turnInfo.currentAge.toLong()) - assertEquals(handSize.toLong(), turnInfo.hand.size.toLong()) + assertEquals(ageToCheck, turnInfo.currentAge) + assertEquals(handSize, turnInfo.hand.size) val move = getFirstAvailableMove(turnInfo) if (move != null) { game.prepareMove(turnInfo.playerIndex, move) diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/api/TableTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/api/TableTest.kt index 4b31a1c7..dd212c0c 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/api/TableTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/api/TableTest.kt @@ -1,8 +1,6 @@ package org.luxons.sevenwonders.game.api import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue import org.junit.Assume.assumeTrue import org.junit.experimental.theories.DataPoints import org.junit.experimental.theories.Theories @@ -54,34 +52,20 @@ class TableTest { table.getBoard(1).addCard(guildCards[2]) table.getBoard(2).addCard(guildCards[3]) - val neightbourCards0 = table.getNeighbourGuildCards(0) - assertEquals(1, neightbourCards0.size.toLong()) - assertFalse(neightbourCards0.contains(guildCards[0])) - assertFalse(neightbourCards0.contains(guildCards[1])) - assertTrue(neightbourCards0.contains(guildCards[2])) - assertFalse(neightbourCards0.contains(guildCards[3])) + val neighbourCards0 = table.getNeighbourGuildCards(0) + assertEquals(listOf(guildCards[2]), neighbourCards0) - val neightbourCards1 = table.getNeighbourGuildCards(1) - assertEquals(3, neightbourCards1.size.toLong()) - assertTrue(neightbourCards1.contains(guildCards[0])) - assertTrue(neightbourCards1.contains(guildCards[1])) - assertFalse(neightbourCards1.contains(guildCards[2])) - assertTrue(neightbourCards1.contains(guildCards[3])) + val neighbourCards1 = table.getNeighbourGuildCards(1) + assertEquals(guildCards - guildCards[2], neighbourCards1) - val neightbourCards2 = table.getNeighbourGuildCards(2) - assertEquals(1, neightbourCards2.size.toLong()) - assertFalse(neightbourCards2.contains(guildCards[0])) - assertFalse(neightbourCards2.contains(guildCards[1])) - assertTrue(neightbourCards2.contains(guildCards[2])) - assertFalse(neightbourCards2.contains(guildCards[3])) + val neighbourCards2 = table.getNeighbourGuildCards(2) + assertEquals(listOf(guildCards[2]), neighbourCards2) } companion object { @JvmStatic @DataPoints - fun nbPlayers(): IntArray { - return intArrayOf(2, 3, 4, 5, 6, 7, 8) - } + fun nbPlayers(): IntArray = intArrayOf(2, 3, 4, 5, 6, 7, 8) } } 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 e5b7af59..e227bf63 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 @@ -13,7 +13,6 @@ import org.junit.experimental.theories.Theories 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.boards.Board.InsufficientFundsException import org.luxons.sevenwonders.game.cards.Color import org.luxons.sevenwonders.game.effects.RawPointsIncrease @@ -28,7 +27,7 @@ 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 +import org.luxons.sevenwonders.game.test.testSettings import org.luxons.sevenwonders.game.test.testWonder @RunWith(Theories::class) @@ -40,15 +39,14 @@ class BoardTest { @Theory fun initialGold_respectsSettings(@FromDataPoints("gold") goldAmountInSettings: Int) { - val customSettings = testCustomizableSettings(goldAmountInSettings) - val settings = Settings(5, customSettings) + val settings = testSettings(initialGold = goldAmountInSettings) val board = Board(testWonder(), 0, settings) assertEquals(goldAmountInSettings, board.gold) } @Theory fun initialProduction_containsInitialResource(type: ResourceType) { - val board = Board(testWonder(type), 0, Settings(5)) + val board = Board(testWonder(type), 0, testSettings()) val resources = resourcesOf(type) assertTrue(board.production.contains(resources)) assertTrue(board.publicProduction.contains(resources)) @@ -61,8 +59,8 @@ class BoardTest { ) { assumeTrue(goldRemoved >= 0) assumeTrue(initialGold >= goldRemoved) - val board = Board(testWonder(), 0, Settings(5)) - board.gold = initialGold + + val board = Board(testWonder(), 0, testSettings(initialGold = initialGold)) board.removeGold(goldRemoved) assertEquals(initialGold - goldRemoved, board.gold) } @@ -75,8 +73,8 @@ class BoardTest { assumeTrue(goldRemoved >= 0) assumeTrue(initialGold < goldRemoved) thrown.expect(InsufficientFundsException::class.java) - val board = Board(testWonder(), 0, Settings(5)) - board.gold = initialGold + + val board = Board(testWonder(), 0, testSettings(initialGold = initialGold)) board.removeGold(goldRemoved) } @@ -87,7 +85,7 @@ class BoardTest { @FromDataPoints("nbCards") nbOtherCards: Int, color: Color ) { - val board = testBoard(type) + val board = testBoard(initialResource = type) addCards(board, nbCards, nbOtherCards, color) assertEquals(nbCards, board.getNbCardsOfColor(listOf(color))) } @@ -101,7 +99,7 @@ class BoardTest { color1: Color, color2: Color ) { - val board = testBoard(type) + val board = testBoard(initialResource = type) addCards(board, nbCards1, color1) addCards(board, nbCards2, color2) addCards(board, nbOtherCards, getDifferentColorFrom(color1, color2)) @@ -110,8 +108,8 @@ class BoardTest { @Test fun setCopiedGuild_succeedsOnPurpleCard() { - val board = testBoard(ResourceType.CLAY) - val card = testCard(Color.PURPLE) + val board = testBoard() + val card = testCard(color = Color.PURPLE) board.copiedGuild = card assertSame(card, board.copiedGuild) @@ -120,8 +118,8 @@ class BoardTest { @Theory fun setCopiedGuild_failsOnNonPurpleCard(color: Color) { assumeTrue(color !== Color.PURPLE) - val board = testBoard(ResourceType.CLAY) - val card = testCard(color) + val board = testBoard() + val card = testCard(color = color) thrown.expect(IllegalArgumentException::class.java) board.copiedGuild = card @@ -129,7 +127,7 @@ class BoardTest { @Theory fun hasSpecial(applied: SpecialAbility, tested: SpecialAbility) { - val board = testBoard(ResourceType.CLAY) + val board = testBoard() val special = SpecialAbilityActivation(applied) special.applyTo(singleBoardPlayer(board)) @@ -139,7 +137,7 @@ class BoardTest { @Test fun canPlayFreeCard() { - val board = testBoard(ResourceType.CLAY) + val board = testBoard() val special = SpecialAbilityActivation(SpecialAbility.ONE_FREE_PER_AGE) special.applyTo(singleBoardPlayer(board)) @@ -170,8 +168,7 @@ class BoardTest { @Theory fun computePoints_gold(@FromDataPoints("gold") gold: Int) { assumeTrue(gold >= 0) - val board = testBoard(ResourceType.WOOD) - board.gold = gold + val board = testBoard(initialGold = gold) val score = board.computeScore(singleBoardPlayer(board)) assertEquals(gold / 3, score.pointsByCategory[ScoreCategory.GOLD]) @@ -181,8 +178,7 @@ class BoardTest { @Theory fun computePoints_(@FromDataPoints("gold") gold: Int) { assumeTrue(gold >= 0) - val board = testBoard(ResourceType.WOOD) - board.gold = gold + val board = testBoard(initialGold = gold) val effect = RawPointsIncrease(5) playCardWithEffect(singleBoardPlayer(board), Color.BLUE, effect) diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt index 735dcaad..f3a50b00 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/MilitaryTest.kt @@ -27,7 +27,7 @@ class MilitaryTest { val initialPoints = military.totalPoints military.victory(age) - assertEquals((initialPoints + nbPointsPerVictory).toLong(), military.totalPoints.toLong()) + assertEquals(initialPoints + nbPointsPerVictory, military.totalPoints) } @Theory @@ -43,27 +43,20 @@ class MilitaryTest { val initialPoints = military.totalPoints military.defeat() - assertEquals((initialPoints - nbPointsLostPerDefeat).toLong(), military.totalPoints.toLong()) + assertEquals(initialPoints - nbPointsLostPerDefeat, military.totalPoints) } companion object { @JvmStatic @DataPoints("points") - fun points(): IntArray { - return intArrayOf(0, 1, 3, 5) - } + fun points(): IntArray = intArrayOf(0, 1, 3, 5) @JvmStatic @DataPoints("ages") - fun ages(): IntArray { - return intArrayOf(1, 2, 3) - } + fun ages(): IntArray = intArrayOf(1, 2, 3) - private fun createMilitary(age: Int, nbPointsPerVictory: Int, nbPointsPerDefeat: Int): Military { - val wonPointsPerAge = HashMap<Int, Int>() - wonPointsPerAge[age] = nbPointsPerVictory - return Military(nbPointsPerDefeat, wonPointsPerAge) - } + private fun createMilitary(age: Int, nbPointsPerVictory: Int, nbPointsPerDefeat: Int): Military = + Military(nbPointsPerDefeat, mapOf(age to nbPointsPerVictory)) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.kt index 4f63557f..e498119f 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.kt @@ -14,34 +14,32 @@ class RelativeBoardPositionTest { fun getIndexFrom_wrapLeft(nbPlayers: Int) { assumeTrue(nbPlayers >= 2) val last = nbPlayers - 1 - assertEquals(last.toLong(), RelativeBoardPosition.LEFT.getIndexFrom(0, nbPlayers).toLong()) - assertEquals(0, RelativeBoardPosition.SELF.getIndexFrom(0, nbPlayers).toLong()) - assertEquals(1, RelativeBoardPosition.RIGHT.getIndexFrom(0, nbPlayers).toLong()) + assertEquals(last, RelativeBoardPosition.LEFT.getIndexFrom(0, nbPlayers)) + assertEquals(0, RelativeBoardPosition.SELF.getIndexFrom(0, nbPlayers)) + assertEquals(1, RelativeBoardPosition.RIGHT.getIndexFrom(0, nbPlayers)) } @Theory fun getIndexFrom_wrapRight(nbPlayers: Int) { assumeTrue(nbPlayers >= 2) val last = nbPlayers - 1 - assertEquals((last - 1).toLong(), RelativeBoardPosition.LEFT.getIndexFrom(last, nbPlayers).toLong()) - assertEquals(last.toLong(), RelativeBoardPosition.SELF.getIndexFrom(last, nbPlayers).toLong()) - assertEquals(0, RelativeBoardPosition.RIGHT.getIndexFrom(last, nbPlayers).toLong()) + assertEquals(last - 1, RelativeBoardPosition.LEFT.getIndexFrom(last, nbPlayers)) + assertEquals(last, RelativeBoardPosition.SELF.getIndexFrom(last, nbPlayers)) + assertEquals(0, RelativeBoardPosition.RIGHT.getIndexFrom(last, nbPlayers)) } @Theory fun getIndexFrom_noWrap(nbPlayers: Int) { assumeTrue(nbPlayers >= 3) - assertEquals(0, RelativeBoardPosition.LEFT.getIndexFrom(1, nbPlayers).toLong()) - assertEquals(1, RelativeBoardPosition.SELF.getIndexFrom(1, nbPlayers).toLong()) - assertEquals(2, RelativeBoardPosition.RIGHT.getIndexFrom(1, nbPlayers).toLong()) + assertEquals(0, RelativeBoardPosition.LEFT.getIndexFrom(1, nbPlayers)) + assertEquals(1, RelativeBoardPosition.SELF.getIndexFrom(1, nbPlayers)) + assertEquals(2, RelativeBoardPosition.RIGHT.getIndexFrom(1, nbPlayers)) } companion object { @JvmStatic @DataPoints - fun nbPlayers(): IntArray { - return intArrayOf(1, 2, 3, 5, 7, 9) - } + fun nbPlayers(): IntArray = intArrayOf(1, 2, 3, 5, 7, 9) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/ScienceTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/ScienceTest.kt index 4fd02640..35e86219 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/ScienceTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/boards/ScienceTest.kt @@ -16,10 +16,10 @@ class ScienceTest { val initial = createScience(3, 4, 5, 1) val empty = Science() initial.addAll(empty) - assertEquals(3, initial.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(4, initial.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(5, initial.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(1, initial.jokers.toLong()) + assertEquals(3, initial.getQuantity(ScienceType.COMPASS)) + assertEquals(4, initial.getQuantity(ScienceType.WHEEL)) + assertEquals(5, initial.getQuantity(ScienceType.TABLET)) + assertEquals(1, initial.jokers) } @Test @@ -27,10 +27,10 @@ class ScienceTest { val initial = createScience(3, 4, 5, 1) val other = createScience(1, 2, 3, 0) initial.addAll(other) - assertEquals(4, initial.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(6, initial.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(8, initial.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(1, initial.jokers.toLong()) + assertEquals(4, initial.getQuantity(ScienceType.COMPASS)) + assertEquals(6, initial.getQuantity(ScienceType.WHEEL)) + assertEquals(8, initial.getQuantity(ScienceType.TABLET)) + assertEquals(1, initial.jokers) } @Test @@ -38,10 +38,10 @@ class ScienceTest { val initial = createScience(3, 4, 5, 1) val other = createScience(0, 0, 0, 3) initial.addAll(other) - assertEquals(3, initial.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(4, initial.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(5, initial.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(4, initial.jokers.toLong()) + assertEquals(3, initial.getQuantity(ScienceType.COMPASS)) + assertEquals(4, initial.getQuantity(ScienceType.WHEEL)) + assertEquals(5, initial.getQuantity(ScienceType.TABLET)) + assertEquals(4, initial.jokers) } @Test @@ -49,70 +49,66 @@ class ScienceTest { val initial = createScience(3, 4, 5, 1) val other = createScience(1, 2, 3, 4) initial.addAll(other) - assertEquals(4, initial.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(6, initial.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(8, initial.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(5, initial.jokers.toLong()) + assertEquals(4, initial.getQuantity(ScienceType.COMPASS)) + assertEquals(6, initial.getQuantity(ScienceType.WHEEL)) + assertEquals(8, initial.getQuantity(ScienceType.TABLET)) + assertEquals(5, initial.jokers) } @Theory fun computePoints_compassesOnly_noJoker(compasses: Int) { val science = createScience(compasses, 0, 0, 0) - assertEquals((compasses * compasses).toLong(), science.computePoints().toLong()) + assertEquals(compasses * compasses, science.computePoints()) } @Theory fun computePoints_wheelsOnly_noJoker(wheels: Int) { val science = createScience(0, wheels, 0, 0) - assertEquals((wheels * wheels).toLong(), science.computePoints().toLong()) + assertEquals(wheels * wheels, science.computePoints()) } @Theory fun computePoints_tabletsOnly_noJoker(tablets: Int) { val science = createScience(0, 0, tablets, 0) - assertEquals((tablets * tablets).toLong(), science.computePoints().toLong()) + assertEquals(tablets * tablets, science.computePoints()) } @Theory fun computePoints_allSameNoJoker(eachSymbol: Int) { val science = createScience(eachSymbol, eachSymbol, eachSymbol, 0) - assertEquals((3 * eachSymbol * eachSymbol + 7 * eachSymbol).toLong(), science.computePoints().toLong()) + assertEquals(3 * eachSymbol * eachSymbol + 7 * eachSymbol, science.computePoints()) } @Theory fun computePoints_expectation(expectation: IntArray) { val science = createScience(expectation[0], expectation[1], expectation[2], expectation[3]) - assertEquals(expectation[4].toLong(), science.computePoints().toLong()) + assertEquals(expectation[4], science.computePoints()) } companion object { @JvmStatic @DataPoints - fun quantitiesWithExpectedPoints(): Array<IntArray> { + fun quantitiesWithExpectedPoints(): Array<IntArray> = arrayOf( // compasses, wheels, tablets, jokers, expected points - return arrayOf( - intArrayOf(0, 0, 0, 1, 1), - intArrayOf(0, 0, 1, 0, 1), - intArrayOf(0, 0, 0, 2, 4), - intArrayOf(0, 0, 1, 1, 4), - intArrayOf(0, 0, 2, 0, 4), - intArrayOf(0, 0, 0, 3, 10), - intArrayOf(0, 0, 1, 2, 10), - intArrayOf(0, 1, 1, 1, 10), - intArrayOf(1, 1, 1, 0, 10), - intArrayOf(0, 0, 0, 4, 16), - intArrayOf(0, 0, 1, 3, 16), - intArrayOf(0, 0, 2, 2, 16), - intArrayOf(0, 0, 3, 1, 16), - intArrayOf(0, 0, 4, 0, 16) - ) - } + intArrayOf(0, 0, 0, 1, 1), + intArrayOf(0, 0, 1, 0, 1), + intArrayOf(0, 0, 0, 2, 4), + intArrayOf(0, 0, 1, 1, 4), + intArrayOf(0, 0, 2, 0, 4), + intArrayOf(0, 0, 0, 3, 10), + intArrayOf(0, 0, 1, 2, 10), + intArrayOf(0, 1, 1, 1, 10), + intArrayOf(1, 1, 1, 0, 10), + intArrayOf(0, 0, 0, 4, 16), + intArrayOf(0, 0, 1, 3, 16), + intArrayOf(0, 0, 2, 2, 16), + intArrayOf(0, 0, 3, 1, 16), + intArrayOf(0, 0, 4, 0, 16) + ) @JvmStatic @DataPoints - fun quantitiesDataPoints(): IntArray { - return intArrayOf(0, 1, 3, 5, 8) - } + fun quantitiesDataPoints(): IntArray = intArrayOf(0, 1, 3, 5, 8) } } 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 b8be570f..6bc8da43 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 @@ -11,13 +11,16 @@ import org.luxons.sevenwonders.game.resources.Production import org.luxons.sevenwonders.game.resources.ResourceType import org.luxons.sevenwonders.game.resources.noTransactions import org.luxons.sevenwonders.game.test.testCard +import org.luxons.sevenwonders.game.test.testSettings import org.luxons.sevenwonders.game.wonders.Wonder class CardTest { @Test fun playCardCostingMoney() { - val settings = Settings(3) + val initialGold = 3 + val price = 1 + val settings = testSettings(3, initialGold) val boards = listOf( Board(Wonder("TestWonder", ResourceType.WOOD, emptyList(), ""), 0, settings), @@ -26,19 +29,15 @@ class CardTest { ) val table = Table(boards) - val treeFarmRequirements = Requirements(1) - val treeFarmProduction = Production() - treeFarmProduction.addChoice(ResourceType.WOOD, ResourceType.CLAY) + val treeFarmRequirements = Requirements(gold = price) + val treeFarmProduction = Production().apply { addChoice(ResourceType.WOOD, ResourceType.CLAY) } val treeFarmEffect = ProductionIncrease(treeFarmProduction, false) + val treeFarmCard = testCard("Tree Farm", Color.BROWN, treeFarmRequirements, treeFarmEffect) - val treeFarmCard = testCard("Tree Farm", Color.BROWN, treeFarmEffect, treeFarmRequirements) - - table.getBoard(0).gold = 3 - table.getBoard(1).gold = 3 - table.getBoard(2).gold = 3 treeFarmCard.applyTo(SimplePlayer(0, table), noTransactions()) - assertEquals(2, table.getBoard(0).gold.toLong()) - assertEquals(3, table.getBoard(1).gold.toLong()) - assertEquals(3, table.getBoard(2).gold.toLong()) + + assertEquals(initialGold - price, table.getBoard(0).gold) + assertEquals(initialGold, table.getBoard(1).gold) + assertEquals(initialGold, table.getBoard(2).gold) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt index ab32937b..f0941412 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/DecksTest.kt @@ -70,7 +70,7 @@ class DecksTest { fun deal_succeedsOnZeroCards(nbPlayers: Int) { val decks = createDecks(1, 0) val hands = decks.deal(1, nbPlayers) - for (i in 0 until nbPlayers) { + repeat(nbPlayers) { i -> assertNotNull(hands[i]) assertTrue(hands[i].isEmpty()) } @@ -81,8 +81,8 @@ class DecksTest { val nbCardsPerAge = nbPlayers * nbCardsPerPlayer val decks = createDecks(1, nbCardsPerAge) val hands = decks.deal(1, nbPlayers) - for (i in 0 until nbPlayers) { - assertEquals(nbCardsPerPlayer.toLong(), hands[i].size.toLong()) + repeat(nbPlayers) { i -> + assertEquals(nbCardsPerPlayer, hands[i].size) } } @@ -90,12 +90,9 @@ class DecksTest { @JvmStatic @DataPoints - fun dataPoints(): IntArray { - return intArrayOf(1, 2, 3, 5, 10) - } + fun dataPoints(): IntArray = intArrayOf(1, 2, 3, 5, 10) - private fun createDecks(nbAges: Int, nbCardsPerAge: Int): Decks { - return Decks(IntRange(1, nbAges).map { it to sampleCards(0, nbCardsPerAge) }.toMap()) - } + private fun createDecks(nbAges: Int, nbCardsPerAge: Int): Decks = + Decks((1..nbAges).map { it to sampleCards(nbCardsPerAge) }.toMap()) } } 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 11794ed8..cc2da04b 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 @@ -25,8 +25,8 @@ class HandsTest { @Test fun get_retrievesCorrectCards() { - val hand0 = sampleCards(0, 5) - val hand1 = sampleCards(5, 10) + val hand0 = sampleCards(5, 0) + val hand1 = sampleCards(10, 5) val hands = Hands(listOf(hand0, hand1)) assertEquals(hand0, hands[0]) assertEquals(hand1, hands[1]) @@ -71,7 +71,6 @@ class HandsTest { @Theory fun maxOneCardRemains_trueWhenAtMost1_someZero(@FromDataPoints("nbPlayers") nbPlayers: Int) { val hands = createHands(nbPlayers, 1) - hands[0].drop(1) assertTrue(hands.maxOneCardRemains()) } @@ -95,16 +94,14 @@ class HandsTest { @Test fun createHand_containsAllCards() { - val hand0 = sampleCards(0, 5) - val hand1 = sampleCards(5, 10) + val hand0 = sampleCards(5, 0) + val hand1 = sampleCards(10, 5) val hands = Hands(listOf(hand0, hand1)) val table = testTable(2) val hand = hands.createHand(SimplePlayer(0, table)) - for (handCard in hand) { - assertTrue(hand0.contains(handCard.card)) - } + hand.map { it.card }.forEach { assertTrue(it in hand0) } } companion object { @@ -122,7 +119,7 @@ class HandsTest { } private fun createHands(nbPlayers: Int, nbCardsPerPlayer: Int): Hands { - return sampleCards(0, nbCardsPerPlayer * nbPlayers).deal(nbPlayers) + return sampleCards(nbCardsPerPlayer * nbPlayers, 0).deal(nbPlayers) } } } 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 2fd180c1..b7bfc935 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 @@ -129,22 +129,18 @@ class RequirementsTest { requirements.pay(player, transactions) - assertEquals(0, board.gold.toLong()) - assertEquals(2, neighbourBoard.gold.toLong()) + assertEquals(0, board.gold) + assertEquals(2, neighbourBoard.gold) } companion object { @JvmStatic @DataPoints - fun goldAmounts(): IntArray { - return intArrayOf(0, 1, 2, 5) - } + fun goldAmounts(): IntArray = intArrayOf(0, 1, 2, 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/data/GameDefinitionTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionTest.kt index 0359938a..44e81368 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/GameDefinitionTest.kt @@ -11,8 +11,8 @@ class GameDefinitionTest { fun successfulGameInit() { val gameDefinition = GameDefinition.load() assertNotNull(gameDefinition) - assertEquals(3, gameDefinition.minPlayers.toLong()) - assertEquals(7, gameDefinition.maxPlayers.toLong()) + assertEquals(3, gameDefinition.minPlayers) + assertEquals(7, gameDefinition.maxPlayers) val game = gameDefinition.initGame(0, CustomizableSettings(), 7) assertNotNull(game) diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethodTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethodTest.kt index 2d992ba6..17e3b316 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethodTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/definitions/WonderSidePickMethodTest.kt @@ -13,9 +13,9 @@ import java.util.Random @RunWith(Theories::class) class WonderSidePickMethodTest { - private var random: Random? = null + private lateinit var random: Random - private var random2: Random? = null + private lateinit var random2: Random @Before fun setUp() { @@ -26,8 +26,8 @@ class WonderSidePickMethodTest { @Test fun pick_allA() { var side: WonderSide? = null - for (i in 0..9) { - side = WonderSidePickMethod.ALL_A.pickSide(random!!, side) + repeat(10) { + side = WonderSidePickMethod.ALL_A.pickSide(random, side) assertEquals(WonderSide.A, side) } } @@ -35,64 +35,62 @@ class WonderSidePickMethodTest { @Test fun pick_allB() { var side: WonderSide? = null - for (i in 0..9) { - side = WonderSidePickMethod.ALL_B.pickSide(random!!, side) + repeat(10) { + side = WonderSidePickMethod.ALL_B.pickSide(random, side) assertEquals(WonderSide.B, side) } } @Test fun pick_eachRandom() { - var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, null) + var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, null) assertEquals(WonderSide.A, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side) assertEquals(WonderSide.A, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random, side) assertEquals(WonderSide.A, side) } @Test fun pick_eachRandom2() { - var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, null) + var side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, null) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side) assertEquals(WonderSide.A, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side) assertEquals(WonderSide.A, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side) assertEquals(WonderSide.B, side) - side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2!!, side) + side = WonderSidePickMethod.EACH_RANDOM.pickSide(random2, side) assertEquals(WonderSide.B, side) } @Theory fun pick_allSameRandom_sameAsFirst(firstSide: WonderSide) { var side = firstSide - for (i in 0..9) { - side = WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random!!, side) + repeat(10) { + side = WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random, side) assertEquals(firstSide, side) } } @Test fun pick_allSameRandom_firstIsRandom() { - assertEquals(WonderSide.A, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random!!, null)) - assertEquals(WonderSide.B, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random2!!, null)) + assertEquals(WonderSide.A, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random, null)) + assertEquals(WonderSide.B, WonderSidePickMethod.SAME_RANDOM_FOR_ALL.pickSide(random2, null)) } companion object { @DataPoints - fun sides(): Array<WonderSide> { - return WonderSide.values() - } + fun sides(): Array<WonderSide> = WonderSide.values() } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt index 22898c8a..3ea3c959 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.kt @@ -18,7 +18,7 @@ import org.luxons.sevenwonders.game.resources.Production @RunWith(Theories::class) class NumericEffectSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -32,101 +32,99 @@ class NumericEffectSerializerTest { @Test fun serialize_militaryReinforcements_null() { - assertEquals("null", gson!!.toJson(null, MilitaryReinforcements::class.java)) + assertEquals("null", gson.toJson(null, MilitaryReinforcements::class.java)) } @Test fun serialize_rawPointsIncrease_null() { - assertEquals("null", gson!!.toJson(null, RawPointsIncrease::class.java)) + assertEquals("null", gson.toJson(null, RawPointsIncrease::class.java)) } @Test fun serialize_goldIncrease_null() { - assertEquals("null", gson!!.toJson(null, GoldIncrease::class.java)) + assertEquals("null", gson.toJson(null, GoldIncrease::class.java)) } @Test(expected = IllegalArgumentException::class) fun serialize_failOnUnknownType() { - gson!!.toJson(ProductionIncrease(Production(), false)) + gson.toJson(ProductionIncrease(Production(), false)) } @Theory fun serialize_militaryReinforcements(count: Int) { val reinforcements = MilitaryReinforcements(count) - assertEquals(count.toString(), gson!!.toJson(reinforcements)) + assertEquals(count.toString(), gson.toJson(reinforcements)) } @Theory fun serialize_rawPointsIncrease(count: Int) { val points = RawPointsIncrease(count) - assertEquals(count.toString(), gson!!.toJson(points)) + assertEquals(count.toString(), gson.toJson(points)) } @Theory fun serialize_goldIncrease(count: Int) { val goldIncrease = GoldIncrease(count) - assertEquals(count.toString(), gson!!.toJson(goldIncrease)) + assertEquals(count.toString(), gson.toJson(goldIncrease)) } @Theory fun deserialize_militaryReinforcements(count: Int) { val reinforcements = MilitaryReinforcements(count) - assertEquals(reinforcements, gson!!.fromJson(count.toString(), MilitaryReinforcements::class.java)) + assertEquals(reinforcements, gson.fromJson(count.toString(), MilitaryReinforcements::class.java)) } @Theory fun deserialize_rawPointsIncrease(count: Int) { val points = RawPointsIncrease(count) - assertEquals(points, gson!!.fromJson(count.toString(), RawPointsIncrease::class.java)) + assertEquals(points, gson.fromJson(count.toString(), RawPointsIncrease::class.java)) } @Theory fun deserialize_goldIncrease(count: Int) { val goldIncrease = GoldIncrease(count) - assertEquals(goldIncrease, gson!!.fromJson(count.toString(), GoldIncrease::class.java)) + assertEquals(goldIncrease, gson.fromJson(count.toString(), GoldIncrease::class.java)) } @Test(expected = NumberFormatException::class) fun deserialize_militaryReinforcements_failOnEmptyString() { - gson!!.fromJson("\"\"", MilitaryReinforcements::class.java) + gson.fromJson("\"\"", MilitaryReinforcements::class.java) } @Test(expected = NumberFormatException::class) fun deserialize_rawPointsIncrease_failOnEmptyString() { - gson!!.fromJson("\"\"", RawPointsIncrease::class.java) + gson.fromJson("\"\"", RawPointsIncrease::class.java) } @Test(expected = NumberFormatException::class) fun deserialize_goldIncrease_failOnEmptyString() { - gson!!.fromJson("\"\"", GoldIncrease::class.java) + gson.fromJson("\"\"", GoldIncrease::class.java) } @Test(expected = NumberFormatException::class) fun deserialize_militaryReinforcements_failOnNonNumericString() { - gson!!.fromJson("\"abc\"", MilitaryReinforcements::class.java) + gson.fromJson("\"abc\"", MilitaryReinforcements::class.java) } @Test(expected = NumberFormatException::class) fun deserialize_rawPointsIncrease_failOnNonNumericString() { - gson!!.fromJson("\"abc\"", RawPointsIncrease::class.java) + gson.fromJson("\"abc\"", RawPointsIncrease::class.java) } @Test(expected = NumberFormatException::class) fun deserialize_goldIncrease_failOnNonNumericString() { - gson!!.fromJson("\"abc\"", GoldIncrease::class.java) + gson.fromJson("\"abc\"", GoldIncrease::class.java) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnUnknownType() { - gson!!.fromJson("\"2\"", ProductionIncrease::class.java) + gson.fromJson("\"2\"", ProductionIncrease::class.java) } companion object { @JvmStatic @DataPoints - fun dataPoints(): IntArray { - return intArrayOf(-2, -1, 0, 1, 2, 5) - } + fun dataPoints(): IntArray = intArrayOf(-2, -1, 0, 1, 2, 5) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt index 8c3d6288..45013d78 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.kt @@ -15,7 +15,7 @@ import org.luxons.sevenwonders.game.resources.Resources class ProductionIncreaseSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -51,130 +51,130 @@ class ProductionIncreaseSerializerTest { @Test fun serialize_nullAsNull() { - assertEquals("null", gson!!.toJson(null, ProductionIncrease::class.java)) + assertEquals("null", gson.toJson(null, ProductionIncrease::class.java)) } @Test fun serialize_emptyProdIncreaseAsNull() { val prodIncrease = ProductionIncrease(Production(), false) - assertEquals("null", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("null", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_singleType() { val prodIncrease = create(true, 1, 0, 0) - assertEquals("\"W\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"W\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_mixedTypes() { val prodIncrease = create(true, 1, 1, 1) - assertEquals("\"WSC\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"WSC\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_mixedTypes_notSellable() { val prodIncrease = create(false, 1, 1, 1) - assertEquals("\"(WSC)\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"(WSC)\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_choice2() { val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.CLAY) - assertEquals("\"W/C\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"W/C\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_choice3() { val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.ORE, ResourceType.CLAY) - assertEquals("\"W/O/C\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"W/O/C\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_choice3_notSellable() { val prodIncrease = createChoice(false, ResourceType.WOOD, ResourceType.ORE, ResourceType.CLAY) - assertEquals("\"(W/O/C)\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"(W/O/C)\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_choice2_unordered() { val prodIncrease = createChoice(true, ResourceType.CLAY, ResourceType.WOOD) - assertEquals("\"W/C\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"W/C\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test fun serialize_choice3_unordered() { val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.CLAY, ResourceType.ORE) - assertEquals("\"W/O/C\"", gson!!.toJson(prodIncrease, ProductionIncrease::class.java)) + assertEquals("\"W/O/C\"", gson.toJson(prodIncrease, ProductionIncrease::class.java)) } @Test(expected = IllegalArgumentException::class) fun serialize_failIfMultipleChoices() { val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.CLAY) prodIncrease.production.addChoice(ResourceType.ORE, ResourceType.GLASS) - gson!!.toJson(prodIncrease, ProductionIncrease::class.java) + gson.toJson(prodIncrease, ProductionIncrease::class.java) } @Test(expected = IllegalArgumentException::class) fun serialize_failIfMixedFixedAndChoices() { val prodIncrease = create(true, 1, 0, 0) prodIncrease.production.addChoice(ResourceType.WOOD, ResourceType.CLAY) - gson!!.toJson(prodIncrease, ProductionIncrease::class.java) + gson.toJson(prodIncrease, ProductionIncrease::class.java) } @Test fun deserialize_nullFromNull() { - assertNull(gson!!.fromJson("null", ProductionIncrease::class.java)) + assertNull(gson.fromJson("null", ProductionIncrease::class.java)) } @Test fun deserialize_emptyList() { val prodIncrease = ProductionIncrease(Production(), true) - assertEquals(prodIncrease, gson!!.fromJson("\"\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"\"", ProductionIncrease::class.java)) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnGarbageString() { - gson!!.fromJson("\"this is garbage\"", ProductionIncrease::class.java) + gson.fromJson("\"this is garbage\"", ProductionIncrease::class.java) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnGarbageStringWithSlashes() { - gson!!.fromJson("\"this/is/garbage\"", ProductionIncrease::class.java) + gson.fromJson("\"this/is/garbage\"", ProductionIncrease::class.java) } @Test fun deserialize_singleType() { val prodIncrease = create(true, 1, 0, 0) - assertEquals(prodIncrease, gson!!.fromJson("\"W\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W\"", ProductionIncrease::class.java)) } @Test fun deserialize_multipleTimesSameType_notSellable() { val prodIncrease = create(false, 3, 0, 0) - assertEquals(prodIncrease, gson!!.fromJson("\"(WWW)\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"(WWW)\"", ProductionIncrease::class.java)) } @Test fun deserialize_mixedTypes() { val prodIncrease = create(true, 1, 1, 1) - assertEquals(prodIncrease, gson!!.fromJson("\"WCS\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"WCS\"", ProductionIncrease::class.java)) } @Test fun deserialize_choice2() { val prodIncrease = createChoice(true, ResourceType.WOOD, ResourceType.CLAY) - assertEquals(prodIncrease, gson!!.fromJson("\"W/C\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W/C\"", ProductionIncrease::class.java)) } @Test fun deserialize_choice3_notSellable() { val prodIncrease = createChoice(false, ResourceType.WOOD, ResourceType.ORE, ResourceType.CLAY) - assertEquals(prodIncrease, gson!!.fromJson("\"(W/O/C)\"", ProductionIncrease::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"(W/O/C)\"", ProductionIncrease::class.java)) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnMultipleResourcesInChoice() { - gson!!.fromJson("\"W/SS/C\"", ProductionIncrease::class.java) + gson.fromJson("\"W/SS/C\"", ProductionIncrease::class.java) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt index 66d4013a..8977255e 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ProductionSerializerTest.kt @@ -14,7 +14,7 @@ import org.luxons.sevenwonders.game.resources.Resources class ProductionSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -49,148 +49,148 @@ class ProductionSerializerTest { @Test fun serialize_nullAsNull() { - assertEquals("null", gson!!.toJson(null, Production::class.java)) + assertEquals("null", gson.toJson(null, Production::class.java)) } @Test fun serialize_emptyProdIncreaseAsNull() { val prodIncrease = Production() - assertEquals("null", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("null", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_singleType() { val prodIncrease = create(1, 0, 0) - assertEquals("\"W\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"W\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_multipleTimesSameType() { val prodIncrease = create(3, 0, 0) - assertEquals("\"WWW\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"WWW\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_mixedTypes() { val prodIncrease = create(1, 1, 1) - assertEquals("\"WSC\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"WSC\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_mixedTypesMultiple() { val prodIncrease = create(2, 1, 2) - assertEquals("\"WWSCC\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"WWSCC\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_choice2() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.CLAY) - assertEquals("\"W/C\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"W/C\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_choice3() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.ORE, ResourceType.CLAY) - assertEquals("\"W/O/C\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"W/O/C\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_choice2_unordered() { val prodIncrease = createChoice(ResourceType.CLAY, ResourceType.WOOD) - assertEquals("\"W/C\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"W/C\"", gson.toJson(prodIncrease, Production::class.java)) } @Test fun serialize_choice3_unordered() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.CLAY, ResourceType.ORE) - assertEquals("\"W/O/C\"", gson!!.toJson(prodIncrease, Production::class.java)) + assertEquals("\"W/O/C\"", gson.toJson(prodIncrease, Production::class.java)) } @Test(expected = IllegalArgumentException::class) fun serialize_failIfMultipleChoices() { val production = createChoice(ResourceType.WOOD, ResourceType.CLAY) production.addChoice(ResourceType.ORE, ResourceType.GLASS) - gson!!.toJson(production, Production::class.java) + gson.toJson(production, Production::class.java) } @Test(expected = IllegalArgumentException::class) fun serialize_failIfMixedFixedAndChoices() { val production = create(1, 0, 0) production.addChoice(ResourceType.WOOD, ResourceType.CLAY) - gson!!.toJson(production, Production::class.java) + gson.toJson(production, Production::class.java) } @Test fun deserialize_nullFromNull() { - assertNull(gson!!.fromJson("null", Production::class.java)) + assertNull(gson.fromJson("null", Production::class.java)) } @Test fun deserialize_emptyList() { val prodIncrease = Production() - assertEquals(prodIncrease, gson!!.fromJson("\"\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"\"", Production::class.java)) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnGarbageString() { - gson!!.fromJson("\"this is garbage\"", Production::class.java) + gson.fromJson("\"this is garbage\"", Production::class.java) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnGarbageStringWithSlashes() { - gson!!.fromJson("\"this/is/garbage\"", Production::class.java) + gson.fromJson("\"this/is/garbage\"", Production::class.java) } @Test fun deserialize_singleType() { val prodIncrease = create(1, 0, 0) - assertEquals(prodIncrease, gson!!.fromJson("\"W\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W\"", Production::class.java)) } @Test fun deserialize_multipleTimesSameType() { val prodIncrease = create(3, 0, 0) - assertEquals(prodIncrease, gson!!.fromJson("\"WWW\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"WWW\"", Production::class.java)) } @Test fun deserialize_mixedTypes() { val prodIncrease = create(1, 1, 1) - assertEquals(prodIncrease, gson!!.fromJson("\"WCS\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"WCS\"", Production::class.java)) } @Test fun deserialize_mixedTypes_unordered() { val prodIncrease = create(1, 3, 2) - assertEquals(prodIncrease, gson!!.fromJson("\"SCWCSS\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"SCWCSS\"", Production::class.java)) } @Test fun deserialize_choice2() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.CLAY) - assertEquals(prodIncrease, gson!!.fromJson("\"W/C\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W/C\"", Production::class.java)) } @Test fun deserialize_choice3() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.ORE, ResourceType.CLAY) - assertEquals(prodIncrease, gson!!.fromJson("\"W/O/C\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W/O/C\"", Production::class.java)) } @Test fun deserialize_choice2_unordered() { val prodIncrease = createChoice(ResourceType.CLAY, ResourceType.WOOD) - assertEquals(prodIncrease, gson!!.fromJson("\"W/C\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W/C\"", Production::class.java)) } @Test fun deserialize_choice3_unordered() { val prodIncrease = createChoice(ResourceType.WOOD, ResourceType.CLAY, ResourceType.ORE) - assertEquals(prodIncrease, gson!!.fromJson("\"W/O/C\"", Production::class.java)) + assertEquals(prodIncrease, gson.fromJson("\"W/O/C\"", Production::class.java)) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnMultipleResourcesInChoice() { - gson!!.fromJson("\"W/SS/C\"", Production::class.java) + gson.fromJson("\"W/SS/C\"", Production::class.java) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt index 79e51bd0..a399a31c 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypeSerializerTest.kt @@ -10,7 +10,7 @@ import org.luxons.sevenwonders.game.resources.ResourceType class ResourceTypeSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -21,7 +21,7 @@ class ResourceTypeSerializerTest { fun serialize_useSymbolForEachType() { for (type in ResourceType.values()) { val expectedJson = "\"" + type.symbol + "\"" - assertEquals(expectedJson, gson!!.toJson(type)) + assertEquals(expectedJson, gson.toJson(type)) } } @@ -29,22 +29,22 @@ class ResourceTypeSerializerTest { fun deserialize_useSymbolForEachType() { for (type in ResourceType.values()) { val typeInJson = "\"" + type.symbol + "\"" - assertEquals(type, gson!!.fromJson(typeInJson, ResourceType::class.java)) + assertEquals(type, gson.fromJson(typeInJson, ResourceType::class.java)) } } @Test fun deserialize_nullFromNull() { - assertNull(gson!!.fromJson("null", ResourceType::class.java)) + assertNull(gson.fromJson("null", ResourceType::class.java)) } @Test(expected = IllegalArgumentException::class) fun deserialize_failsOnEmptyString() { - gson!!.fromJson("\"\"", ResourceType::class.java) + gson.fromJson("\"\"", ResourceType::class.java) } @Test(expected = IllegalArgumentException::class) fun deserialize_failsOnGarbageString() { - gson!!.fromJson("\"thisisgarbage\"", ResourceType::class.java) + gson.fromJson("\"thisisgarbage\"", ResourceType::class.java) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializerTest.kt index 31e53d23..63d8e5c7 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourceTypesSerializerTest.kt @@ -13,8 +13,8 @@ import java.util.ArrayList class ResourceTypesSerializerTest { - private var gson: Gson? = null - + private lateinit var gson: Gson + @Before fun setUp() { gson = GsonBuilder().registerTypeAdapter(createListTypeToken(), ResourceTypesSerializer()).create() @@ -26,20 +26,20 @@ class ResourceTypesSerializerTest { @Test fun serialize_null() { - assertEquals("null", gson!!.toJson(null, createListTypeToken())) + assertEquals("null", gson.toJson(null, createListTypeToken())) } @Test fun serialize_emptyList() { val types = ArrayList<ResourceType>() - assertEquals("\"\"", gson!!.toJson(types, createListTypeToken())) + assertEquals("\"\"", gson.toJson(types, createListTypeToken())) } @Test fun serialize_singleType() { val types = ArrayList<ResourceType>() types.add(ResourceType.WOOD) - assertEquals("\"W\"", gson!!.toJson(types, createListTypeToken())) + assertEquals("\"W\"", gson.toJson(types, createListTypeToken())) } @Test @@ -48,7 +48,7 @@ class ResourceTypesSerializerTest { types.add(ResourceType.WOOD) types.add(ResourceType.WOOD) types.add(ResourceType.WOOD) - assertEquals("\"WWW\"", gson!!.toJson(types, createListTypeToken())) + assertEquals("\"WWW\"", gson.toJson(types, createListTypeToken())) } @Test @@ -57,25 +57,25 @@ class ResourceTypesSerializerTest { types.add(ResourceType.WOOD) types.add(ResourceType.CLAY) types.add(ResourceType.STONE) - assertEquals("\"WCS\"", gson!!.toJson(types, createListTypeToken())) + assertEquals("\"WCS\"", gson.toJson(types, createListTypeToken())) } @Test fun deserialize_null() { - assertNull(gson!!.fromJson("null", createListTypeToken())) + assertNull(gson.fromJson("null", createListTypeToken())) } @Test fun deserialize_emptyList() { val types = ArrayList<ResourceType>() - assertEquals(types, gson!!.fromJson("\"\"", createListTypeToken())) + assertEquals(types, gson.fromJson("\"\"", createListTypeToken())) } @Test fun deserialize_singleType() { val types = ArrayList<ResourceType>() types.add(ResourceType.WOOD) - assertEquals(types, gson!!.fromJson("\"W\"", createListTypeToken())) + assertEquals(types, gson.fromJson("\"W\"", createListTypeToken())) } @Test @@ -84,7 +84,7 @@ class ResourceTypesSerializerTest { types.add(ResourceType.WOOD) types.add(ResourceType.WOOD) types.add(ResourceType.WOOD) - assertEquals(types, gson!!.fromJson("\"WWW\"", createListTypeToken())) + assertEquals(types, gson.fromJson("\"WWW\"", createListTypeToken())) } @Test @@ -93,6 +93,6 @@ class ResourceTypesSerializerTest { types.add(ResourceType.WOOD) types.add(ResourceType.CLAY) types.add(ResourceType.STONE) - assertEquals(types, gson!!.fromJson("\"WCS\"", createListTypeToken())) + assertEquals(types, gson.fromJson("\"WCS\"", createListTypeToken())) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializerTest.kt index 91384922..ba4793c0 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ResourcesSerializerTest.kt @@ -16,7 +16,7 @@ import org.luxons.sevenwonders.game.resources.resourcesOf class ResourcesSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -28,71 +28,71 @@ class ResourcesSerializerTest { @Test fun serialize_null() { - assertEquals("null", gson!!.toJson(null, Resources::class.java)) + assertEquals("null", gson.toJson(null, Resources::class.java)) } @Test fun serialize_emptyResourcesToNull() { val resources = emptyResources() - assertEquals("null", gson!!.toJson(resources)) + assertEquals("null", gson.toJson(resources)) } @Test fun serialize_singleType() { val resources = resourcesOf(WOOD) - assertEquals("\"W\"", gson!!.toJson(resources)) + assertEquals("\"W\"", gson.toJson(resources)) } @Test fun serialize_multipleTimesSameType() { val resources = resourcesOf(WOOD to 3) - assertEquals("\"WWW\"", gson!!.toJson(resources)) + assertEquals("\"WWW\"", gson.toJson(resources)) } @Test fun serialize_mixedTypes() { val resources = resourcesOf(WOOD, STONE, CLAY) - assertEquals("\"WSC\"", gson!!.toJson(resources)) + assertEquals("\"WSC\"", gson.toJson(resources)) } @Test fun serialize_mixedTypes_unordered() { val resources = resourcesOf(CLAY to 1, WOOD to 2, CLAY to 1, STONE to 1) - assertEquals("\"CCWWS\"", gson!!.toJson(resources)) + assertEquals("\"CCWWS\"", gson.toJson(resources)) } @Test fun deserialize_null() { - assertNull(gson!!.fromJson("null", Resources::class.java)) + assertNull(gson.fromJson("null", Resources::class.java)) } @Test fun deserialize_emptyList() { val resources = emptyResources() - assertEquals(resources, gson!!.fromJson("\"\"", Resources::class.java)) + assertEquals(resources, gson.fromJson("\"\"", Resources::class.java)) } @Test fun deserialize_singleType() { val resources = resourcesOf(WOOD) - assertEquals(resources, gson!!.fromJson("\"W\"", Resources::class.java)) + assertEquals(resources, gson.fromJson("\"W\"", Resources::class.java)) } @Test fun deserialize_multipleTimesSameType() { val resources = resourcesOf(WOOD to 3) - assertEquals(resources, gson!!.fromJson("\"WWW\"", Resources::class.java)) + assertEquals(resources, gson.fromJson("\"WWW\"", Resources::class.java)) } @Test fun deserialize_mixedTypes() { val resources = resourcesOf(WOOD, CLAY, STONE) - assertEquals(resources, gson!!.fromJson("\"WCS\"", Resources::class.java)) + assertEquals(resources, gson.fromJson("\"WCS\"", Resources::class.java)) } @Test fun deserialize_mixedTypes_unordered() { val resources = resourcesOf(WOOD to 1, CLAY to 2, STONE to 3) - assertEquals(resources, gson!!.fromJson("\"SCWCSS\"", Resources::class.java)) + assertEquals(resources, gson.fromJson("\"SCWCSS\"", Resources::class.java)) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt index adafced2..75bd5d61 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializerTest.kt @@ -10,9 +10,14 @@ import org.luxons.sevenwonders.game.boards.ScienceType import org.luxons.sevenwonders.game.effects.ScienceProgress import org.luxons.sevenwonders.game.test.createScienceProgress +private const val TABLET_STR = "\"TABLET\"" +private const val COMPASS_STR = "\"COMPASS\"" +private const val WHEEL_STR = "\"WHEEL\"" +private const val JOKER_STR = "\"any\"" + class ScienceProgressSerializerTest { - private var gson: Gson? = null + private lateinit var gson: Gson @Before fun setUp() { @@ -22,126 +27,115 @@ class ScienceProgressSerializerTest { @Test fun serialize_emptyToNull() { val progress = createScienceProgress(0, 0, 0, 0) - val json = gson!!.toJson(progress) + val json = gson.toJson(progress) assertEquals("null", json) } @Test fun serialize_oneCompass() { val progress = createScienceProgress(1, 0, 0, 0) - val json = gson!!.toJson(progress) + val json = gson.toJson(progress) assertEquals(COMPASS_STR, json) } @Test fun serialize_oneWheel() { val progress = createScienceProgress(0, 1, 0, 0) - val json = gson!!.toJson(progress) + val json = gson.toJson(progress) assertEquals(WHEEL_STR, json) } @Test fun serialize_oneTablet() { val progress = createScienceProgress(0, 0, 1, 0) - val json = gson!!.toJson(progress) + val json = gson.toJson(progress) assertEquals(TABLET_STR, json) } @Test fun serialize_oneJoker() { val progress = createScienceProgress(0, 0, 0, 1) - val json = gson!!.toJson(progress) + val json = gson.toJson(progress) assertEquals(JOKER_STR, json) } @Test(expected = UnsupportedOperationException::class) fun serialize_failOnMultipleCompasses() { val progress = createScienceProgress(2, 0, 0, 0) - gson!!.toJson(progress) + gson.toJson(progress) } @Test(expected = UnsupportedOperationException::class) fun serialize_failOnMultipleWheels() { val progress = createScienceProgress(0, 2, 0, 0) - gson!!.toJson(progress) + gson.toJson(progress) } @Test(expected = UnsupportedOperationException::class) fun serialize_failOnMultipleTablets() { val progress = createScienceProgress(0, 0, 2, 0) - gson!!.toJson(progress) + gson.toJson(progress) } @Test(expected = UnsupportedOperationException::class) fun serialize_failOnMultipleJokers() { val progress = createScienceProgress(0, 0, 0, 2) - gson!!.toJson(progress) + gson.toJson(progress) } @Test(expected = UnsupportedOperationException::class) fun serialize_failOnMixedElements() { val progress = createScienceProgress(1, 1, 0, 0) - gson!!.toJson(progress) + gson.toJson(progress) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnEmptyString() { - gson!!.fromJson("\"\"", ScienceProgress::class.java) + gson.fromJson("\"\"", ScienceProgress::class.java) } @Test(expected = IllegalArgumentException::class) fun deserialize_failOnGarbageString() { - gson!!.fromJson("thisisgarbage", ScienceProgress::class.java) + gson.fromJson("thisisgarbage", ScienceProgress::class.java) } @Test fun deserialize_compass() { - val progress = gson!!.fromJson(COMPASS_STR, ScienceProgress::class.java) + val progress = gson.fromJson(COMPASS_STR, ScienceProgress::class.java) assertNotNull(progress.science) - assertEquals(1, progress.science.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(0, progress.science.jokers.toLong()) + assertEquals(1, progress.science.getQuantity(ScienceType.COMPASS)) + assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL)) + assertEquals(0, progress.science.getQuantity(ScienceType.TABLET)) + assertEquals(0, progress.science.jokers) } @Test fun deserialize_wheel() { - val progress = gson!!.fromJson(WHEEL_STR, ScienceProgress::class.java) + val progress = gson.fromJson(WHEEL_STR, ScienceProgress::class.java) assertNotNull(progress.science) - assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(1, progress.science.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(0, progress.science.jokers.toLong()) + assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS)) + assertEquals(1, progress.science.getQuantity(ScienceType.WHEEL)) + assertEquals(0, progress.science.getQuantity(ScienceType.TABLET)) + assertEquals(0, progress.science.jokers) } @Test fun deserialize_tablet() { - val progress = gson!!.fromJson(TABLET_STR, ScienceProgress::class.java) + val progress = gson.fromJson(TABLET_STR, ScienceProgress::class.java) assertNotNull(progress.science) - assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(1, progress.science.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(0, progress.science.jokers.toLong()) + assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS)) + assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL)) + assertEquals(1, progress.science.getQuantity(ScienceType.TABLET)) + assertEquals(0, progress.science.jokers) } @Test fun deserialize_joker() { - val progress = gson!!.fromJson(JOKER_STR, ScienceProgress::class.java) + val progress = gson.fromJson(JOKER_STR, ScienceProgress::class.java) assertNotNull(progress.science) - assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals(0, progress.science.getQuantity(ScienceType.TABLET).toLong()) - assertEquals(1, progress.science.jokers.toLong()) - } - - companion object { - - private val COMPASS_STR = "\"COMPASS\"" - - private val WHEEL_STR = "\"WHEEL\"" - - private val TABLET_STR = "\"TABLET\"" - - private val JOKER_STR = "\"any\"" + assertEquals(0, progress.science.getQuantity(ScienceType.COMPASS)) + assertEquals(0, progress.science.getQuantity(ScienceType.WHEEL)) + assertEquals(0, progress.science.getQuantity(ScienceType.TABLET)) + assertEquals(1, progress.science.jokers) } } 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 38da14f8..535a5a97 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 @@ -18,13 +18,13 @@ import org.luxons.sevenwonders.game.test.testTable @RunWith(Theories::class) class BonusPerBoardElementTest { - private var table: Table? = null - private var player0: Player? = null + private lateinit var table: Table + private lateinit var player0: Player @Before fun setUp() { table = testTable(4) - player0 = SimplePlayer(0, table!!) + player0 = SimplePlayer(0, table) } @Theory @@ -36,12 +36,12 @@ class BonusPerBoardElementTest { gold: Int, color: Color ) { - val board = table!!.getBoard(0, boardPosition) + 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(player0!!).toLong()) + assertEquals(nbCards * points, bonus.computePoints(player0)) } @Theory @@ -51,27 +51,27 @@ class BonusPerBoardElementTest { points: Int, gold: Int ) { - val board = table!!.getBoard(0, boardPosition) - for (i in 0 until nbDefeatTokens) { + val board = table.getBoard(0, boardPosition) + repeat(nbDefeatTokens) { board.military.defeat() } val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.DEFEAT_TOKEN, gold, points, listOf()) - assertEquals((nbDefeatTokens * points).toLong(), bonus.computePoints(player0!!).toLong()) + assertEquals(nbDefeatTokens * points, bonus.computePoints(player0)) } @Theory fun computePoints_countsWonderStages(boardPosition: RelativeBoardPosition, nbStages: Int, points: Int, gold: Int) { - val board = table!!.getBoard(0, boardPosition) - for (i in 0 until nbStages) { + val board = table.getBoard(0, boardPosition) + repeat(nbStages) { board.wonder.placeCard(CardBack("")) } val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.BUILT_WONDER_STAGES, gold, points, listOf()) - assertEquals((nbStages * points).toLong(), bonus.computePoints(player0!!).toLong()) + assertEquals(nbStages * points, bonus.computePoints(player0)) } @Theory @@ -83,46 +83,46 @@ class BonusPerBoardElementTest { gold: Int, color: Color ) { - val board = table!!.getBoard(0, boardPosition) + val board = table.getBoard(0, boardPosition) addCards(board, nbCards, nbOtherCards, color) val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.CARD, gold, points, listOf(color)) - val selfBoard = table!!.getBoard(0) + val selfBoard = table.getBoard(0) val initialGold = selfBoard.gold - bonus.applyTo(player0!!) - assertEquals((initialGold + nbCards * gold).toLong(), selfBoard.gold.toLong()) + bonus.applyTo(player0) + assertEquals(initialGold + nbCards * gold, selfBoard.gold) } @Theory fun apply_countsDefeatTokens(boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int, gold: Int) { - val board = table!!.getBoard(0, boardPosition) - for (i in 0 until nbDefeatTokens) { + val board = table.getBoard(0, boardPosition) + repeat(nbDefeatTokens) { board.military.defeat() } val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.DEFEAT_TOKEN, gold, points, listOf()) - val selfBoard = table!!.getBoard(0) + val selfBoard = table.getBoard(0) val initialGold = selfBoard.gold - bonus.applyTo(player0!!) - assertEquals((initialGold + nbDefeatTokens * gold).toLong(), selfBoard.gold.toLong()) + bonus.applyTo(player0) + assertEquals(initialGold + nbDefeatTokens * gold, selfBoard.gold) } @Theory fun apply_countsWonderStages(boardPosition: RelativeBoardPosition, nbStages: Int, points: Int, gold: Int) { - val board = table!!.getBoard(0, boardPosition) - for (i in 0 until nbStages) { + val board = table.getBoard(0, boardPosition) + repeat(nbStages) { board.wonder.placeCard(CardBack("")) } val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.BUILT_WONDER_STAGES, gold, points, listOf()) - val selfBoard = table!!.getBoard(0) + val selfBoard = table.getBoard(0) val initialGold = selfBoard.gold - bonus.applyTo(player0!!) - assertEquals((initialGold + nbStages * gold).toLong(), selfBoard.gold.toLong()) + bonus.applyTo(player0) + assertEquals(initialGold + nbStages * gold, selfBoard.gold) } companion object { 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 8d22497d..7247ccdc 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 @@ -21,7 +21,7 @@ class DiscountTest { discount.applyTo(board) val transactions = createTransactions(provider, discountedType) - assertEquals(discountedPrice.toLong(), board.tradingRules.computeCost(transactions).toLong()) + assertEquals(discountedPrice, board.tradingRules.computeCost(transactions)) } @Theory @@ -43,13 +43,13 @@ class DiscountTest { val normalPrice = 2 val fromOtherType = createTransactions(provider, otherType) - assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherType).toLong()) + assertEquals(normalPrice, board.tradingRules.computeCost(fromOtherType)) val fromOtherProvider = createTransactions(otherProvider, discountedType) - assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherProvider).toLong()) + assertEquals(normalPrice, board.tradingRules.computeCost(fromOtherProvider)) val fromOtherProviderAndType = createTransactions(otherProvider, otherType) - assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherProviderAndType).toLong()) + assertEquals(normalPrice, board.tradingRules.computeCost(fromOtherProviderAndType)) } companion object { 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 897dcf30..96a4aa2a 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 @@ -20,28 +20,24 @@ class GoldIncreaseTest { goldIncrease.applyTo(board) - assertEquals((initialAmount + goldIncreaseAmount).toLong(), board.gold.toLong()) + assertEquals(initialAmount + goldIncreaseAmount, board.gold) } @Theory fun computePoints_isAlwaysZero(gold: Int) { val goldIncrease = GoldIncrease(gold) val player = SimplePlayer(0, testTable(5)) - assertEquals(0, goldIncrease.computePoints(player).toLong()) + assertEquals(0, goldIncrease.computePoints(player)) } companion object { @JvmStatic @DataPoints - fun goldAmounts(): IntArray { - return intArrayOf(-5, -1, 0, 1, 2, 5, 10) - } + fun goldAmounts(): IntArray = intArrayOf(-5, -1, 0, 1, 2, 5, 10) @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/MilitaryReinforcementsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt index fce3d2bd..7e66fd4b 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 @@ -21,14 +21,14 @@ class MilitaryReinforcementsTest { val reinforcements = MilitaryReinforcements(additionalShields) reinforcements.applyTo(board) - assertEquals((initialShields + additionalShields).toLong(), board.military.nbShields.toLong()) + assertEquals(initialShields + additionalShields, board.military.nbShields) } @Theory fun computePoints_isAlwaysZero(shields: Int) { val reinforcements = MilitaryReinforcements(shields) val player = SimplePlayer(0, testTable(5)) - assertEquals(0, reinforcements.computePoints(player).toLong()) + assertEquals(0, reinforcements.computePoints(player)) } companion object { 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 225ffcbb..d454e12d 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 @@ -61,15 +61,13 @@ class ProductionIncreaseTest { fun computePoints_isAlwaysZero(addedType: ResourceType) { val effect = ProductionIncrease(fixedProduction(addedType), false) val player = SimplePlayer(0, testTable(5)) - assertEquals(0, effect.computePoints(player).toLong()) + assertEquals(0, effect.computePoints(player)) } companion object { @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/RawPointsIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt index 2cdf6781..0867789b 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 @@ -15,7 +15,7 @@ class RawPointsIncreaseTest { fun computePoints_equalsNbOfPoints(points: Int) { val rawPointsIncrease = RawPointsIncrease(points) val player = SimplePlayer(0, testTable(5)) - assertEquals(points.toLong(), rawPointsIncrease.computePoints(player).toLong()) + assertEquals(points, rawPointsIncrease.computePoints(player)) } 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 6b4cd8f3..1223578a 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 @@ -32,10 +32,10 @@ class ScienceProgressTest { val effect = createScienceProgress(compasses, wheels, tablets, jokers) effect.applyTo(board) - assertEquals((initCompasses + compasses).toLong(), board.science.getQuantity(ScienceType.COMPASS).toLong()) - assertEquals((initWheels + wheels).toLong(), board.science.getQuantity(ScienceType.WHEEL).toLong()) - assertEquals((initTablets + tablets).toLong(), board.science.getQuantity(ScienceType.TABLET).toLong()) - assertEquals((initJokers + jokers).toLong(), board.science.jokers.toLong()) + assertEquals(initCompasses + compasses, board.science.getQuantity(ScienceType.COMPASS)) + assertEquals(initWheels + wheels, board.science.getQuantity(ScienceType.WHEEL)) + assertEquals(initTablets + tablets, board.science.getQuantity(ScienceType.TABLET)) + assertEquals(initJokers + jokers, board.science.jokers) } companion object { 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 eeaa5047..7b589bdc 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 @@ -35,7 +35,7 @@ class SpecialAbilityActivationTest { val effect = SpecialAbilityActivation(ability) val player = SimplePlayer(0, testTable(5)) - assertEquals(0, effect.computePoints(player).toLong()) + assertEquals(0, effect.computePoints(player)) } @Theory @@ -49,7 +49,7 @@ class SpecialAbilityActivationTest { player.board.copiedGuild = guildCard val directPointsFromGuildCard = guildCard.effects.stream().mapToInt { e -> e.computePoints(player) }.sum() - assertEquals(directPointsFromGuildCard.toLong(), effect.computePoints(player).toLong()) + assertEquals(directPointsFromGuildCard, effect.computePoints(player)) } @Test(expected = IllegalStateException::class) 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 d1b380e0..62213788 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 @@ -18,7 +18,7 @@ class BuildWonderMoveTest { @Test(expected = InvalidMoveException::class) fun init_failsWhenCardNotInHand() { val table = testTable(3) - val hand = sampleCards(0, 7) + val hand = sampleCards(7) val playerContext = PlayerContext(0, table, hand) val anotherCard = testCard("Card that is not in the hand") createMove(playerContext, anotherCard, MoveType.UPGRADE_WONDER) @@ -28,7 +28,7 @@ class BuildWonderMoveTest { fun init_failsWhenWonderIsCompletelyBuilt() { val settings = testSettings(3) val table = testTable(settings) - val hand = sampleCards(0, 7) + val hand = sampleCards(7) fillPlayerWonderLevels(settings, table, hand) @@ -39,8 +39,8 @@ class BuildWonderMoveTest { private fun fillPlayerWonderLevels(settings: Settings, table: Table, hand: List<Card>) { try { val nbLevels = table.getBoard(0).wonder.stages.size - for (i in 0 until nbLevels) { - buildOneWonderLevel(settings, table, hand, i) + repeat(nbLevels) { + buildOneWonderLevel(settings, table, hand, it) } } catch (e: InvalidMoveException) { fail("Building wonder levels should not fail before being full") @@ -59,7 +59,7 @@ class BuildWonderMoveTest { fun place_increasesWonderLevel() { val settings = testSettings(3) val table = testTable(settings) - val hand = sampleCards(0, 7) + val hand = sampleCards(7) val cardToUse = hand[0] val playerContext = PlayerContext(0, table, hand) val move = createMove(playerContext, cardToUse, MoveType.UPGRADE_WONDER) @@ -71,6 +71,6 @@ class BuildWonderMoveTest { val newStage = table.getBoard(0).wonder.nbBuiltStages // we need to see the level increase before activation so that other players - assertEquals((initialStage + 1).toLong(), newStage.toLong()) + assertEquals(initialStage + 1, newStage) } } 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 2566f32f..95913806 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 @@ -281,12 +281,12 @@ class ProductionTest { fun hashCode_sameWhenSameContent() { val production1 = Production() val production2 = Production() - assertEquals(production1.hashCode().toLong(), production2.hashCode().toLong()) + assertEquals(production1.hashCode(), production2.hashCode()) production1.addFixedResource(GLASS, 1) production2.addFixedResource(GLASS, 1) - assertEquals(production1.hashCode().toLong(), production2.hashCode().toLong()) + assertEquals(production1.hashCode(), production2.hashCode()) production1.addChoice(ORE, WOOD) production2.addChoice(ORE, WOOD) - assertEquals(production1.hashCode().toLong(), production2.hashCode().toLong()) + assertEquals(production1.hashCode(), production2.hashCode()) } } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.kt index 172df278..33d69428 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourceTransactionsTest.kt @@ -5,7 +5,6 @@ import org.junit.Test import org.luxons.sevenwonders.game.resources.ResourceType.CLAY import org.luxons.sevenwonders.game.resources.ResourceType.WOOD import org.luxons.sevenwonders.game.test.createTransaction -import org.luxons.sevenwonders.game.test.of class ResourceTransactionsTest { @@ -23,4 +22,6 @@ class ResourceTransactionsTest { assertEquals(expectedNormalized, transactionMap.toTransactions().toSet()) } + + private infix fun Int.of(type: ResourceType): Resources = resourcesOf(type to this) } diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt index a931949f..db19e025 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/ResourcesTest.kt @@ -13,7 +13,6 @@ import org.luxons.sevenwonders.game.resources.ResourceType.ORE import org.luxons.sevenwonders.game.resources.ResourceType.PAPYRUS import org.luxons.sevenwonders.game.resources.ResourceType.STONE import org.luxons.sevenwonders.game.resources.ResourceType.WOOD -import org.luxons.sevenwonders.game.resources.ResourceType.values import java.util.NoSuchElementException class ResourcesTest { @@ -25,7 +24,7 @@ class ResourcesTest { @Test fun init_shouldBeEmpty() { val resources = emptyResources() - for (resourceType in values()) { + for (resourceType in ResourceType.values()) { assertEquals(0, resources[resourceType]) } assertEquals(0, resources.size) diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt index 3e567493..6da59d5f 100644 --- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt +++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/resources/TradingRulesTest.kt @@ -26,28 +26,28 @@ class TradingRulesTest { val rules = TradingRules(defaultCost) rules.setCost(type, overriddenProvider, overriddenCost) - assertEquals(overriddenCost.toLong(), rules.getCost(type, overriddenProvider).toLong()) - assertEquals(defaultCost.toLong(), rules.getCost(type, provider).toLong()) + assertEquals(overriddenCost, rules.getCost(type, overriddenProvider)) + assertEquals(defaultCost, rules.getCost(type, provider)) } @Theory fun computeCost_zeroForNoResources(defaultCost: Int) { val rules = TradingRules(defaultCost) - assertEquals(0, rules.computeCost(noTransactions()).toLong()) + assertEquals(0, rules.computeCost(noTransactions())) } @Theory fun computeCost_defaultCostWhenNoOverride(defaultCost: Int, provider: Provider, type: ResourceType) { val rules = TradingRules(defaultCost) val transactions = createTransactions(provider, type) - assertEquals(defaultCost.toLong(), rules.computeCost(transactions).toLong()) + assertEquals(defaultCost, rules.computeCost(transactions)) } @Theory fun computeCost_twiceDefaultFor2Resources(defaultCost: Int, provider: Provider, type: ResourceType) { val rules = TradingRules(defaultCost) val transactions = createTransactions(provider, type, type) - assertEquals((2 * defaultCost).toLong(), rules.computeCost(transactions).toLong()) + assertEquals(2 * defaultCost, rules.computeCost(transactions)) } @Theory @@ -55,7 +55,7 @@ class TradingRulesTest { val rules = TradingRules(defaultCost) rules.setCost(type, provider, overriddenCost) val transactions = createTransactions(provider, type) - assertEquals(overriddenCost.toLong(), rules.computeCost(transactions).toLong()) + assertEquals(overriddenCost, rules.computeCost(transactions)) } @Theory @@ -71,7 +71,7 @@ class TradingRulesTest { val rules = TradingRules(defaultCost) rules.setCost(overriddenType, overriddenProvider, overriddenCost) val transactions = createTransactions(provider, type) - assertEquals(defaultCost.toLong(), rules.computeCost(transactions).toLong()) + assertEquals(defaultCost, rules.computeCost(transactions)) } @Theory @@ -86,7 +86,7 @@ class TradingRulesTest { val rules = TradingRules(defaultCost) rules.setCost(overriddenType, provider, overriddenCost) val transactions = createTransactions(provider, overriddenType, type) - assertEquals((defaultCost + overriddenCost).toLong(), rules.computeCost(transactions).toLong()) + assertEquals(defaultCost + overriddenCost, rules.computeCost(transactions)) } @Theory @@ -113,20 +113,14 @@ class TradingRulesTest { @JvmStatic @DataPoints - fun costs(): IntArray { - return intArrayOf(0, 1, 2) - } + fun costs(): IntArray = intArrayOf(0, 1, 2) @JvmStatic @DataPoints - fun providers(): Array<Provider> { - return Provider.values() - } + fun providers(): Array<Provider> = Provider.values() @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/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt index c67a7052..4bf41a8b 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 @@ -23,201 +23,114 @@ import org.luxons.sevenwonders.game.resources.Provider import org.luxons.sevenwonders.game.resources.ResourceTransaction 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.resources.noTransactions import org.luxons.sevenwonders.game.resources.resourcesOf import org.luxons.sevenwonders.game.wonders.Wonder import org.luxons.sevenwonders.game.wonders.WonderStage -import java.util.Arrays private const val SEED: Long = 42 -@JvmOverloads -fun testCustomizableSettings(initialGold: Int = 0): CustomizableSettings { - return CustomizableSettings(randomSeedForTests = SEED).copy(initialGold = initialGold) -} +internal fun testCustomizableSettings(initialGold: Int = 0): CustomizableSettings = + CustomizableSettings(randomSeedForTests = SEED).copy(initialGold = initialGold) -internal fun testSettings(nbPlayers: Int): Settings { - return Settings(nbPlayers, testCustomizableSettings()) -} +internal fun testSettings(nbPlayers: Int = 5, initialGold: Int = 0): Settings = + Settings(nbPlayers, testCustomizableSettings(initialGold)) -fun testTable(nbPlayers: Int): Table { - return testTable(testSettings(nbPlayers)) -} +internal fun testTable(nbPlayers: Int = 5): Table = testTable(testSettings(nbPlayers)) -internal fun testTable(settings: Settings): Table { - return Table(testBoards(settings.nbPlayers, settings)) -} +internal fun testTable(settings: Settings): Table = Table(testBoards(settings.nbPlayers, settings)) -private fun testBoards(count: Int, settings: Settings): List<Board> { - val boards = ArrayList<Board>(count) - for (i in 0 until count) { - boards.add(testBoard(ResourceType.WOOD, settings)) - } - return boards -} +private fun testBoards(count: Int, settings: Settings): List<Board> = List(count) { testBoard(settings) } -private fun testBoard(initialResource: ResourceType, settings: Settings): Board { - val wonder = testWonder(initialResource) - return Board(wonder, 0, settings) -} - -fun testBoard(initialResource: ResourceType): Board { - return testBoard(initialResource, testSettings(5)) -} - -private fun testBoard(initialResource: ResourceType, vararg production: ResourceType): Board { - val board = testBoard(initialResource) +internal fun testBoard( + initialResource: ResourceType = ResourceType.WOOD, + initialGold: Int = 0, + vararg production: ResourceType +): Board { + val settings = testSettings(initialGold = initialGold) + val board = testBoard(settings, initialResource) board.production.addAll(fixedProduction(*production)) return board } -fun testBoard(initialResource: ResourceType, gold: Int, vararg production: ResourceType): Board { - val board = testBoard(initialResource, *production) - board.gold = gold - return board -} - -@JvmOverloads -fun testWonder(initialResource: ResourceType = ResourceType.WOOD): Wonder { - val stage1 = createWonderStage() - val stage2 = createWonderStage() - val stage3 = createWonderStage() - return Wonder("Test Wonder " + initialResource.symbol!!, initialResource, listOf(stage1, stage2, stage3), "") -} +private fun testBoard(settings: Settings, initialResource: ResourceType = ResourceType.WOOD): Board = + Board(testWonder(initialResource), 0, settings) -private fun createWonderStage(vararg effects: Effect): WonderStage { - return WonderStage(Requirements(), Arrays.asList(*effects)) +internal fun testWonder(initialResource: ResourceType = ResourceType.WOOD): Wonder { + val stage1 = WonderStage(Requirements(), emptyList()) + val stage2 = WonderStage(Requirements(), emptyList()) + val stage3 = WonderStage(Requirements(), emptyList()) + return Wonder("Test Wonder ${initialResource.symbol}", initialResource, listOf(stage1, stage2, stage3), "") } -fun fixedProduction(vararg producedTypes: ResourceType): Production { - val production = Production() - production.addAll(resourcesOf(*producedTypes)) - return production -} +internal fun fixedProduction(vararg producedTypes: ResourceType): Production = + Production().apply { addAll(resourcesOf(*producedTypes)) } -infix fun Int.of(type: ResourceType): Resources { - return resourcesOf(type to this) -} +internal fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions = + createTransactions(createTransaction(provider, *resources)) -internal fun createTransactions(provider: Provider, vararg resources: ResourceType): ResourceTransactions { - val transaction = createTransaction(provider, *resources) - return createTransactions(transaction) -} +internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions = transactions.toSet() -internal fun createTransactions(vararg transactions: ResourceTransaction): ResourceTransactions { - return transactions.toSet() -} +internal fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction = + ResourceTransaction(provider, resourcesOf(*resources)) -fun createTransaction(provider: Provider, vararg resources: ResourceType): ResourceTransaction { - return ResourceTransaction(provider, resourcesOf(*resources)) -} +internal fun createRequirements(vararg types: ResourceType): Requirements = Requirements(resources = resourcesOf(*types)) -fun createRequirements(vararg types: ResourceType): Requirements { - val resources = resourcesOf(*types) - return Requirements(resources = resources) -} +internal fun sampleCards(nbCards: Int, fromIndex: Int = 0, color: Color = Color.BLUE): List<Card> = + List(nbCards) { i -> testCard("Test Card ${fromIndex + i}", color) } -fun sampleCards(fromIndex: Int, nbCards: Int): List<Card> { - return List(nbCards) { i -> testCard(i + fromIndex, Color.BLUE) } -} +internal fun createGuildCards(count: Int): List<Card> = List(count) { createGuildCard(it) } -fun testCard(name: String): Card { - return testCard(name, Color.BLUE) -} - -fun testCard(color: Color): Card { - return testCard("Test Card", color) -} - -internal fun testCard(color: Color, effect: Effect): Card { - return testCard("Test Card", color, effect) -} - -private fun testCard(num: Int, color: Color): Card { - return testCard("Test Card $num", color) -} - -fun createGuildCards(count: Int): List<Card> { - return IntRange(0, count).map { createGuildCard(it) } -} - -internal fun createGuildCard(num: Int, effect: Effect? = null): Card { - return testCard("Test Guild $num", Color.PURPLE, effect) -} +internal fun createGuildCard(num: Int, effect: Effect? = null): Card = + testCard("Test Guild $num", Color.PURPLE, effect = effect) internal fun testCard( name: String = "Test Card", color: Color = Color.BLUE, - effect: Effect? = null, - requirements: Requirements = Requirements() + requirements: Requirements = Requirements(), + effect: Effect? = null ): Card { val effects = if (effect == null) emptyList() else listOf(effect) - return Card(name, color, requirements, effects, null, emptyList(), "path/to/card/image", createCardBack()) + return Card(name, color, requirements, effects, null, emptyList(), "path/to/card/image", CardBack("image-III")) } -private fun createCardBack(): CardBack { - return CardBack("image-III") -} - -fun addCards(board: Board, nbCardsOfColor: Int, nbOtherCards: Int, color: Color) { +internal fun addCards(board: Board, nbCardsOfColor: Int, nbOtherCards: Int, color: Color) { addCards(board, nbCardsOfColor, color) - val otherColor = getDifferentColorFrom(color) - addCards(board, nbOtherCards, otherColor) + addCards(board, nbOtherCards, getDifferentColorFrom(color)) } -fun addCards(board: Board, nbCards: Int, color: Color) { - for (i in 0 until nbCards) { - board.addCard(testCard(i, color)) - } +internal fun addCards(board: Board, nbCards: Int, color: Color) { + sampleCards(nbCards, color = color).forEach { board.addCard(it) } } -fun getDifferentColorFrom(vararg colors: Color): Color { - val forbiddenColors = Arrays.asList(*colors) - for (color in Color.values()) { - if (!forbiddenColors.contains(color)) { - return color - } - } - throw IllegalArgumentException("All colors are forbidden!") -} +internal fun getDifferentColorFrom(vararg colors: Color): Color = + Color.values().firstOrNull { it !in colors } ?: throw IllegalArgumentException("All colors are forbidden!") -internal fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress { - return ScienceProgress(createScience(compasses, wheels, tablets, jokers)) -} +internal fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress = + ScienceProgress(createScience(compasses, wheels, tablets, jokers)) -fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Science { - val science = Science() - if (compasses > 0) { - science.add(ScienceType.COMPASS, compasses) - } - if (wheels > 0) { - science.add(ScienceType.WHEEL, wheels) - } - if (tablets > 0) { - science.add(ScienceType.TABLET, tablets) - } - if (jokers > 0) { - science.addJoker(jokers) - } - return science +internal fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Science = Science().apply { + add(ScienceType.COMPASS, compasses) + add(ScienceType.WHEEL, wheels) + add(ScienceType.TABLET, tablets) + addJoker(jokers) } internal fun playCardWithEffect(player: Player, color: Color, effect: Effect) { - val card = testCard(color, effect) + val card = testCard(color = color, effect = effect) player.board.addCard(card) card.applyTo(player, noTransactions()) } -internal fun createMove(context: PlayerContext, card: Card, type: MoveType): Move { - val playerMove = PlayerMove(type, card.name) - return type.create(playerMove, card, context) -} +internal fun createMove(context: PlayerContext, card: Card, type: MoveType): Move = + type.resolve(PlayerMove(type, card.name), card, context) -internal fun singleBoardPlayer(board: Board): Player { - return object : Player { - override val index = 0 - override val board = board - override fun getBoard(relativePosition: RelativeBoardPosition): Board = board +internal fun singleBoardPlayer(board: Board): Player = object : Player { + override val index = 0 + override val board = board + override fun getBoard(relativePosition: RelativeBoardPosition): Board = when (relativePosition) { + RelativeBoardPosition.LEFT -> throw RuntimeException("No LEFT board") + RelativeBoardPosition.SELF -> this.board + RelativeBoardPosition.RIGHT -> throw RuntimeException("No RIGHT 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 6c3b933f..40f45201 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 @@ -11,13 +11,13 @@ class WonderTest { @Test fun buildLevel_increasesNbBuiltStages() { val wonder = testWonder() - assertEquals(0, wonder.nbBuiltStages.toLong()) + assertEquals(0, wonder.nbBuiltStages) wonder.placeCard(CardBack("img")) - assertEquals(1, wonder.nbBuiltStages.toLong()) + assertEquals(1, wonder.nbBuiltStages) wonder.placeCard(CardBack("img")) - assertEquals(2, wonder.nbBuiltStages.toLong()) + assertEquals(2, wonder.nbBuiltStages) wonder.placeCard(CardBack("img")) - assertEquals(3, wonder.nbBuiltStages.toLong()) + assertEquals(3, wonder.nbBuiltStages) } @Test |