Skip to content

Commit e7e2bbd

Browse files
committed
test(plugin25): expand CardTest
1 parent 0e9d8be commit e7e2bbd

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,39 @@ package sc.plugin2025
33
import io.kotest.core.spec.style.FunSpec
44
import io.kotest.matchers.*
55
import io.kotest.matchers.collections.*
6+
import io.kotest.matchers.nulls.*
67
import sc.plugin2025.util.HuIConstants
78

89
class CardTest: FunSpec({
910
context(Card.SWAP_CARROTS.name) {
1011
val state = GameState()
12+
Card.SWAP_CARROTS.check(state) shouldBe null
13+
state.currentPlayer.addCard(Card.SWAP_CARROTS)
14+
15+
val lastSalad = state.board.getPreviousField(Field.SALAD).shouldNotBeNull()
16+
lastSalad shouldBe HuIConstants.LAST_SALAD
17+
1118
test("allowed only before last salad") {
12-
Card.SWAP_CARROTS.check(state) shouldBe null
13-
val lastSalad = state.board.getPreviousField(Field.SALAD)
14-
lastSalad shouldBe HuIConstants.LAST_SALAD
15-
state.currentPlayer.position = lastSalad!!
19+
state.currentPlayer.position = lastSalad
1620
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
17-
state.currentPlayer.position = state.board.getPreviousField(Field.HARE, lastSalad)!!
21+
}
22+
test("generate correct moves") {
23+
val previousHare = state.board.getPreviousField(Field.HARE, lastSalad).shouldNotBeNull()
24+
state.currentPlayer.position = previousHare - 1
25+
state.possibleCardMoves(1) shouldContainExactly listOf(Advance(1, Card.SWAP_CARROTS))
26+
state.currentPlayer.position = previousHare
1827
Card.SWAP_CARROTS.check(state) shouldBe null
19-
state.currentPlayer.addCard(Card.SWAP_CARROTS)
2028
state.nextCards() shouldContainExactly listOf(arrayOf(Card.SWAP_CARROTS))
29+
30+
val nextHare = state.board.getNextField(Field.HARE, previousHare).shouldNotBeNull()
31+
state.possibleCardMoves(nextHare - previousHare).shouldBeEmpty()
32+
2133
state.otherPlayer.position = lastSalad
2234
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD
2335
state.nextCards().shouldBeEmpty()
2436
}
25-
state.currentPlayer.addCard(Card.SWAP_CARROTS)
2637
test("not repeatable") {
27-
Card.SWAP_CARROTS.check(state) shouldBe null
28-
state.currentPlayer.position = state.board.getNextField(Field.HARE)!! - 1
38+
state.currentPlayer.position = state.board.getNextField(Field.HARE).shouldNotBeNull() - 1
2939
state.performMoveDirectly(Advance(1, Card.SWAP_CARROTS))
3040
Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_ALREADY_PLAYED
3141
state.performMoveDirectly(state.getSensibleMoves().first())

0 commit comments

Comments
 (0)