Skip to content

Commit

Permalink
test(plugin25): verify nextCards result
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Oct 18, 2024
1 parent 80e1ecb commit 0e9d8be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ data class GameState @JvmOverloads constructor(
ExchangeCarrots(-10).takeIf { mayExchangeCarrots(-10, player) },
)

/** Checks which cards of the given player are usable from its current position.
* Does not check validity of a whole move.
*
* Usable means playable on a hare field
* and buyable on a market field.
*
* @return empty array means no cards are usable,
* null means not on a field where cards can be used. */
fun nextCards(player: Hare = currentPlayer): Collection<Array<Card>>? =
when(player.field) {
Field.HARE -> {
Expand Down
6 changes: 5 additions & 1 deletion plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sc.plugin2025

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.*
import io.kotest.matchers.collections.*
import sc.plugin2025.util.HuIConstants

class CardTest: FunSpec({
Expand All @@ -13,10 +14,13 @@ class CardTest: FunSpec({
lastSalad shouldBe HuIConstants.LAST_SALAD
state.currentPlayer.position = lastSalad!!
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
state.currentPlayer.position = lastSalad - 1
state.currentPlayer.position = state.board.getPreviousField(Field.HARE, lastSalad)!!
Card.SWAP_CARROTS.check(state) shouldBe null
state.currentPlayer.addCard(Card.SWAP_CARROTS)
state.nextCards() shouldContainExactly listOf(arrayOf(Card.SWAP_CARROTS))
state.otherPlayer.position = lastSalad
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
state.nextCards().shouldBeEmpty()
}
state.currentPlayer.addCard(Card.SWAP_CARROTS)
test("not repeatable") {
Expand Down

0 comments on commit 0e9d8be

Please sign in to comment.