From 7ef4fd07b20cde731a914189bac4d37b552def21 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 5 May 2020 17:35:05 +0200 Subject: Move tests to their proper place --- .../luxons/sevenwonders/engine/boards/TableTest.kt | 71 ++++++++++++++++++ .../sevenwonders/engine/converters/BoardsKtTest.kt | 84 +++++++++++++++++++++ .../org/luxons/sevenwonders/model/BoardsKtTest.kt | 86 ---------------------- .../org/luxons/sevenwonders/model/TableTest.kt | 71 ------------------ 4 files changed, 155 insertions(+), 157 deletions(-) create mode 100644 sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/TableTest.kt create mode 100644 sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/converters/BoardsKtTest.kt delete mode 100644 sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/BoardsKtTest.kt delete mode 100644 sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/TableTest.kt (limited to 'sw-engine/src/test/kotlin') diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/TableTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/TableTest.kt new file mode 100644 index 00000000..c37b71e1 --- /dev/null +++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/boards/TableTest.kt @@ -0,0 +1,71 @@ +package org.luxons.sevenwonders.engine.boards + +import org.junit.Assume.assumeTrue +import org.junit.experimental.theories.DataPoints +import org.junit.experimental.theories.Theories +import org.junit.experimental.theories.Theory +import org.junit.runner.RunWith +import org.luxons.sevenwonders.model.boards.RelativeBoardPosition +import org.luxons.sevenwonders.engine.test.createGuildCards +import org.luxons.sevenwonders.engine.test.testTable +import kotlin.test.assertEquals + +@RunWith(Theories::class) +class TableTest { + + @Theory + fun getBoard_wrapLeft(nbPlayers: Int) { + assumeTrue(nbPlayers >= 2) + val table = testTable(nbPlayers) + val last = nbPlayers - 1 + assertEquals(table.getBoard(last), table.getBoard(0, RelativeBoardPosition.LEFT)) + assertEquals(table.getBoard(0), table.getBoard(0, RelativeBoardPosition.SELF)) + assertEquals(table.getBoard(1), table.getBoard(0, RelativeBoardPosition.RIGHT)) + } + + @Theory + fun getBoard_wrapRight(nbPlayers: Int) { + assumeTrue(nbPlayers >= 2) + val table = testTable(nbPlayers) + val last = nbPlayers - 1 + assertEquals(table.getBoard(last - 1), table.getBoard(last, RelativeBoardPosition.LEFT)) + assertEquals(table.getBoard(last), table.getBoard(last, RelativeBoardPosition.SELF)) + assertEquals(table.getBoard(0), table.getBoard(last, RelativeBoardPosition.RIGHT)) + } + + @Theory + fun getBoard_noWrap(nbPlayers: Int) { + assumeTrue(nbPlayers >= 3) + val table = testTable(nbPlayers) + assertEquals(table.getBoard(0), table.getBoard(1, RelativeBoardPosition.LEFT)) + assertEquals(table.getBoard(1), table.getBoard(1, RelativeBoardPosition.SELF)) + assertEquals(table.getBoard(2), table.getBoard(1, RelativeBoardPosition.RIGHT)) + } + + @Theory + fun getNeighbourGuildCards(nbPlayers: Int) { + assumeTrue(nbPlayers >= 4) + val table = testTable(nbPlayers) + val guildCards = createGuildCards(4) + table.getBoard(0).addCard(guildCards[0]) + table.getBoard(0).addCard(guildCards[1]) + table.getBoard(1).addCard(guildCards[2]) + table.getBoard(2).addCard(guildCards[3]) + + val neighbourCards0 = table.getNeighbourGuildCards(0) + assertEquals(listOf(guildCards[2]), neighbourCards0) + + val neighbourCards1 = table.getNeighbourGuildCards(1) + assertEquals(guildCards - guildCards[2], neighbourCards1) + + val neighbourCards2 = table.getNeighbourGuildCards(2) + assertEquals(listOf(guildCards[2]), neighbourCards2) + } + + companion object { + + @JvmStatic + @DataPoints + fun nbPlayers(): IntArray = intArrayOf(2, 3, 4, 5, 6, 7, 8) + } +} diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/converters/BoardsKtTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/converters/BoardsKtTest.kt new file mode 100644 index 00000000..96c5e500 --- /dev/null +++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/converters/BoardsKtTest.kt @@ -0,0 +1,84 @@ +package org.luxons.sevenwonders.engine.converters + +import org.luxons.sevenwonders.engine.test.testCard +import org.luxons.sevenwonders.model.cards.Color +import org.luxons.sevenwonders.model.cards.TableCard +import kotlin.test.Test +import kotlin.test.assertEquals + +class BoardsKtTest { + + @Test + fun `toColumns on empty list should return no cols`() { + val cols = emptyList().toColumns() + assertEquals(emptyList(), cols) + } + + @Test + fun `toColumns with single resource should return a single column`() { + val card = testCard(color = Color.BROWN).toTableCard() + val cols = listOf(card).toColumns() + assertEquals(listOf(listOf(card)), cols) + } + + @Test + fun `toColumns with single non-resource should return a single column`() { + val card = testCard(color = Color.BLUE).toTableCard() + val cols = listOf(card).toColumns() + assertEquals(listOf(listOf(card)), cols) + } + + @Test + fun `toColumns with two same-color cards should return a single column`() { + val card1 = testCard(color = Color.BLUE).toTableCard() + val card2 = testCard(color = Color.BLUE).toTableCard() + val cards = listOf(card1, card2) + val cols = cards.toColumns() + assertEquals(listOf(cards), cols) + } + + @Test + fun `toColumns with two resource cards should return a single column`() { + val card1 = testCard(color = Color.BROWN).toTableCard() + val card2 = testCard(color = Color.GREY).toTableCard() + val cards = listOf(card1, card2) + val cols = cards.toColumns() + assertEquals(listOf(cards), cols) + } + + @Test + fun `toColumns with 2 different non-resource cards should return 2 columns`() { + val card1 = testCard(color = Color.BLUE).toTableCard() + val card2 = testCard(color = Color.GREEN).toTableCard() + val cards = listOf(card1, card2) + val cols = cards.toColumns() + assertEquals(listOf(listOf(card1), listOf(card2)), cols) + } + + @Test + fun `toColumns with 1 res and 1 non-res card should return 2 columns`() { + val card1 = testCard(color = Color.BROWN).toTableCard() + val card2 = testCard(color = Color.GREEN).toTableCard() + val cards = listOf(card1, card2) + val cols = cards.toColumns() + assertEquals(listOf(listOf(card1), listOf(card2)), cols) + } + + @Test + fun `toColumns should return 1 col for res cards and 1 for each other color`() { + val res1 = testCard(color = Color.BROWN).toTableCard() + val res2 = testCard(color = Color.BROWN).toTableCard() + val res3 = testCard(color = Color.GREY).toTableCard() + val blue1 = testCard(color = Color.BLUE).toTableCard() + val green1 = testCard(color = Color.GREEN).toTableCard() + val green2 = testCard(color = Color.GREEN).toTableCard() + val cards = listOf(res1, green1, green2, res2, blue1, res3) + val cols = cards.toColumns() + val expectedCols = listOf( + listOf(res1, res2, res3), + listOf(blue1), + listOf(green1, green2) + ) + assertEquals(expectedCols, cols) + } +} diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/BoardsKtTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/BoardsKtTest.kt deleted file mode 100644 index 1dd19704..00000000 --- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/BoardsKtTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -package org.luxons.sevenwonders.model - -import org.luxons.sevenwonders.engine.converters.toColumns -import org.luxons.sevenwonders.engine.converters.toTableCard -import org.luxons.sevenwonders.engine.test.testCard -import org.luxons.sevenwonders.model.cards.Color -import org.luxons.sevenwonders.model.cards.TableCard -import kotlin.test.Test -import kotlin.test.assertEquals - -class BoardsKtTest { - - @Test - fun `toColumns on empty list should return no cols`() { - val cols = emptyList().toColumns() - assertEquals(emptyList(), cols) - } - - @Test - fun `toColumns with single resource should return a single column`() { - val card = testCard(color = Color.BROWN).toTableCard() - val cols = listOf(card).toColumns() - assertEquals(listOf(listOf(card)), cols) - } - - @Test - fun `toColumns with single non-resource should return a single column`() { - val card = testCard(color = Color.BLUE).toTableCard() - val cols = listOf(card).toColumns() - assertEquals(listOf(listOf(card)), cols) - } - - @Test - fun `toColumns with two same-color cards should return a single column`() { - val card1 = testCard(color = Color.BLUE).toTableCard() - val card2 = testCard(color = Color.BLUE).toTableCard() - val cards = listOf(card1, card2) - val cols = cards.toColumns() - assertEquals(listOf(cards), cols) - } - - @Test - fun `toColumns with two resource cards should return a single column`() { - val card1 = testCard(color = Color.BROWN).toTableCard() - val card2 = testCard(color = Color.GREY).toTableCard() - val cards = listOf(card1, card2) - val cols = cards.toColumns() - assertEquals(listOf(cards), cols) - } - - @Test - fun `toColumns with 2 different non-resource cards should return 2 columns`() { - val card1 = testCard(color = Color.BLUE).toTableCard() - val card2 = testCard(color = Color.GREEN).toTableCard() - val cards = listOf(card1, card2) - val cols = cards.toColumns() - assertEquals(listOf(listOf(card1), listOf(card2)), cols) - } - - @Test - fun `toColumns with 1 res and 1 non-res card should return 2 columns`() { - val card1 = testCard(color = Color.BROWN).toTableCard() - val card2 = testCard(color = Color.GREEN).toTableCard() - val cards = listOf(card1, card2) - val cols = cards.toColumns() - assertEquals(listOf(listOf(card1), listOf(card2)), cols) - } - - @Test - fun `toColumns should return 1 col for res cards and 1 for each other color`() { - val res1 = testCard(color = Color.BROWN).toTableCard() - val res2 = testCard(color = Color.BROWN).toTableCard() - val res3 = testCard(color = Color.GREY).toTableCard() - val blue1 = testCard(color = Color.BLUE).toTableCard() - val green1 = testCard(color = Color.GREEN).toTableCard() - val green2 = testCard(color = Color.GREEN).toTableCard() - val cards = listOf(res1, green1, green2, res2, blue1, res3) - val cols = cards.toColumns() - val expectedCols = listOf( - listOf(res1, res2, res3), - listOf(blue1), - listOf(green1, green2) - ) - assertEquals(expectedCols, cols) - } -} diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/TableTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/TableTest.kt deleted file mode 100644 index dc461c4d..00000000 --- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/model/TableTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.luxons.sevenwonders.model - -import org.junit.Assume.assumeTrue -import org.junit.experimental.theories.DataPoints -import org.junit.experimental.theories.Theories -import org.junit.experimental.theories.Theory -import org.junit.runner.RunWith -import org.luxons.sevenwonders.model.boards.RelativeBoardPosition -import org.luxons.sevenwonders.engine.test.createGuildCards -import org.luxons.sevenwonders.engine.test.testTable -import kotlin.test.assertEquals - -@RunWith(Theories::class) -class TableTest { - - @Theory - fun getBoard_wrapLeft(nbPlayers: Int) { - assumeTrue(nbPlayers >= 2) - val table = testTable(nbPlayers) - val last = nbPlayers - 1 - assertEquals(table.getBoard(last), table.getBoard(0, RelativeBoardPosition.LEFT)) - assertEquals(table.getBoard(0), table.getBoard(0, RelativeBoardPosition.SELF)) - assertEquals(table.getBoard(1), table.getBoard(0, RelativeBoardPosition.RIGHT)) - } - - @Theory - fun getBoard_wrapRight(nbPlayers: Int) { - assumeTrue(nbPlayers >= 2) - val table = testTable(nbPlayers) - val last = nbPlayers - 1 - assertEquals(table.getBoard(last - 1), table.getBoard(last, RelativeBoardPosition.LEFT)) - assertEquals(table.getBoard(last), table.getBoard(last, RelativeBoardPosition.SELF)) - assertEquals(table.getBoard(0), table.getBoard(last, RelativeBoardPosition.RIGHT)) - } - - @Theory - fun getBoard_noWrap(nbPlayers: Int) { - assumeTrue(nbPlayers >= 3) - val table = testTable(nbPlayers) - assertEquals(table.getBoard(0), table.getBoard(1, RelativeBoardPosition.LEFT)) - assertEquals(table.getBoard(1), table.getBoard(1, RelativeBoardPosition.SELF)) - assertEquals(table.getBoard(2), table.getBoard(1, RelativeBoardPosition.RIGHT)) - } - - @Theory - fun getNeighbourGuildCards(nbPlayers: Int) { - assumeTrue(nbPlayers >= 4) - val table = testTable(nbPlayers) - val guildCards = createGuildCards(4) - table.getBoard(0).addCard(guildCards[0]) - table.getBoard(0).addCard(guildCards[1]) - table.getBoard(1).addCard(guildCards[2]) - table.getBoard(2).addCard(guildCards[3]) - - val neighbourCards0 = table.getNeighbourGuildCards(0) - assertEquals(listOf(guildCards[2]), neighbourCards0) - - val neighbourCards1 = table.getNeighbourGuildCards(1) - assertEquals(guildCards - guildCards[2], neighbourCards1) - - val neighbourCards2 = table.getNeighbourGuildCards(2) - assertEquals(listOf(guildCards[2]), neighbourCards2) - } - - companion object { - - @JvmStatic - @DataPoints - fun nbPlayers(): IntArray = intArrayOf(2, 3, 4, 5, 6, 7, 8) - } -} -- cgit