Skip to content

Commit 0e9d8be

Browse files
committed
test(plugin25): verify nextCards result
1 parent 80e1ecb commit 0e9d8be

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ data class GameState @JvmOverloads constructor(
122122
ExchangeCarrots(-10).takeIf { mayExchangeCarrots(-10, player) },
123123
)
124124

125+
/** Checks which cards of the given player are usable from its current position.
126+
* Does not check validity of a whole move.
127+
*
128+
* Usable means playable on a hare field
129+
* and buyable on a market field.
130+
*
131+
* @return empty array means no cards are usable,
132+
* null means not on a field where cards can be used. */
125133
fun nextCards(player: Hare = currentPlayer): Collection<Array<Card>>? =
126134
when(player.field) {
127135
Field.HARE -> {

plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sc.plugin2025
22

33
import io.kotest.core.spec.style.FunSpec
44
import io.kotest.matchers.*
5+
import io.kotest.matchers.collections.*
56
import sc.plugin2025.util.HuIConstants
67

78
class CardTest: FunSpec({
@@ -13,10 +14,13 @@ class CardTest: FunSpec({
1314
lastSalad shouldBe HuIConstants.LAST_SALAD
1415
state.currentPlayer.position = lastSalad!!
1516
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
16-
state.currentPlayer.position = lastSalad - 1
17+
state.currentPlayer.position = state.board.getPreviousField(Field.HARE, lastSalad)!!
1718
Card.SWAP_CARROTS.check(state) shouldBe null
19+
state.currentPlayer.addCard(Card.SWAP_CARROTS)
20+
state.nextCards() shouldContainExactly listOf(arrayOf(Card.SWAP_CARROTS))
1821
state.otherPlayer.position = lastSalad
1922
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
23+
state.nextCards().shouldBeEmpty()
2024
}
2125
state.currentPlayer.addCard(Card.SWAP_CARROTS)
2226
test("not repeatable") {

0 commit comments

Comments
 (0)