Skip to content

Commit 157a417

Browse files
committed
test(plugin): verify that lastMove tracks SkipMoves
Closes #390
1 parent 44f29b7 commit 157a417

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

plugin/src/test/sc/plugin2021/GameStateTest.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ package sc.plugin2021
33
import io.kotest.assertions.throwables.shouldNotThrow
44
import io.kotest.assertions.throwables.shouldThrow
55
import io.kotest.core.spec.style.WordSpec
6+
import io.kotest.matchers.should
67
import io.kotest.matchers.shouldBe
78
import io.kotest.matchers.shouldNotBe
9+
import io.kotest.matchers.string.shouldContain
10+
import io.kotest.matchers.types.beInstanceOf
811
import sc.helpers.testXStream
912
import sc.plugin2021.util.Constants
1013
import sc.plugin2021.util.GameRuleLogic
14+
import sc.plugin2021.util.MoveMistake
1115
import sc.shared.InvalidMoveException
1216

1317
class GameStateTest: WordSpec({
@@ -80,14 +84,21 @@ class GameStateTest: WordSpec({
8084
shouldNotThrow<InvalidMoveException> {
8185
GameRuleLogic.performMove(state, move)
8286
}
83-
state.advance(4)
87+
state.advance(3)
88+
state.currentColor shouldBe Color.BLUE
8489
state.undeployedPieceShapes(Color.BLUE).size shouldBe 20
8590
"throw an InvalidMoveException" {
86-
shouldThrow<InvalidMoveException> {
91+
val ex = shouldThrow<InvalidMoveException> {
8792
GameRuleLogic.performMove(state, move)
8893
}
94+
ex.mistake shouldBe MoveMistake.DUPLICATE_SHAPE
95+
state.undeployedPieceShapes(Color.BLUE).size shouldBe 20
96+
}
97+
"allow a SkipMove" {
98+
GameRuleLogic.performMove(state, SkipMove(Color.BLUE))
99+
state.lastMove should beInstanceOf<SkipMove>()
100+
testXStream.toXML(state) shouldContain Regex("lastMove.*SkipMove")
89101
}
90-
state.undeployedPieceShapes(Color.BLUE).size shouldBe 20
91102
}
92103
"serialised and deserialised" should {
93104
val xStream = testXStream

plugin/src/test/sc/plugin2021/GameTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import io.kotest.assertions.throwables.shouldThrow
55
import io.kotest.core.spec.IsolationMode
66
import io.kotest.core.spec.style.WordSpec
77
import io.kotest.matchers.collections.shouldContainExactly
8+
import io.kotest.matchers.should
89
import io.kotest.matchers.shouldBe
910
import io.kotest.matchers.shouldNotBe
11+
import io.kotest.matchers.types.beInstanceOf
1012
import sc.api.plugins.IGameState
1113
import sc.api.plugins.exceptions.GameLogicException
1214
import sc.api.plugins.host.IGameListener
@@ -103,7 +105,9 @@ class GameTest: WordSpec({
103105
shouldThrow<GameLogicException> {
104106
game.onAction(state.currentPlayer, SkipMove(state.currentColor))
105107
}
106-
108+
"end with a SkipMove" {
109+
state.lastMove should beInstanceOf<SkipMove>()
110+
}
107111
"end in a draw" {
108112
game.playerScores shouldContainExactly List(2) {
109113
PlayerScore(ScoreCause.REGULAR, "", Constants.DRAW_SCORE, 10)

0 commit comments

Comments
 (0)