1
1
package sc.plugin2025
2
2
3
- import io.kotest.core.spec.style.WordSpec
3
+ import io.kotest.assertions.throwables.shouldThrow
4
+ import io.kotest.core.spec.style.FunSpec
4
5
import io.kotest.matchers.*
5
6
import sc.api.plugins.Team
6
7
import sc.helpers.shouldSerializeTo
8
+ import sc.shared.InvalidMoveException
7
9
8
- class GameStateTest : WordSpec ({
9
- " GameState" should {
10
- " clone correctly" {
11
- val state = GameState ()
12
- val clone = state.clone()
13
- state.currentPlayer.getCards().size shouldBe 0
14
- clone.currentPlayer.addCard(Card .EAT_SALAD )
15
- state.currentPlayer.getCards().size shouldBe 0
16
- }
17
- val state = GameState (
18
- Board (arrayOf(Field .START , Field .MARKET , Field .CARROTS , Field .SALAD , Field .HARE , Field .GOAL )),
19
- lastMove = Advance (5, Card .EAT_SALAD ),
20
- turn = 1,
21
- players = listOf(
22
- Hare (Team .TWO , cards = arrayListOf(Card .SWAP_CARROTS ), lastAction = Advance (5)),
23
- Hare (Team .ONE , position = 3, lastAction = Card .EAT_SALAD )
24
- )
10
+ class GameStateTest : FunSpec ({
11
+ test("clone correctly") {
12
+ val state = GameState ()
13
+ val clone = state.clone()
14
+ state.currentPlayer.getCards().size shouldBe 0
15
+ clone.currentPlayer.addCard(Card .EAT_SALAD )
16
+ state.currentPlayer.getCards().size shouldBe 0
17
+ }
18
+ val state = GameState (
19
+ Board (arrayOf(Field .START , Field .MARKET , Field .CARROTS , Field .SALAD , Field .HARE , Field .GOAL )),
20
+ lastMove = Advance (5, Card .EAT_SALAD ),
21
+ turn = 1,
22
+ players = listOf(
23
+ Hare (Team .TWO , cards = arrayListOf(Card .SWAP_CARROTS ), lastAction = Advance (5), carrots = 0, salads = 0),
24
+ Hare (Team .ONE , position = 3, lastAction = Card .EAT_SALAD )
25
25
)
26
- " behave properly" {
27
- state.currentTeam shouldBe Team .ONE
28
- state.currentField shouldBe Field .SALAD
29
- state.currentPlayer.team shouldBe Team .ONE
30
- state.currentPlayer.lastAction shouldBe Card .EAT_SALAD
31
- state.mayEatSalad() shouldBe true
32
- state.currentPlayer.lastAction = EatSalad
33
- state.mayEatSalad() shouldBe false
26
+ )
27
+ test("behave properly") {
28
+ state.isOver shouldBe false
29
+ state.currentTeam shouldBe Team .ONE
30
+ state.currentField shouldBe Field .SALAD
31
+ state.currentPlayer.team shouldBe Team .ONE
32
+ state.currentPlayer.lastAction shouldBe Card .EAT_SALAD
33
+ state.mayEatSalad() shouldBe true
34
+ state.currentPlayer.lastAction = EatSalad
35
+ state.mayEatSalad() shouldBe false
36
+ }
37
+ context("allow follow-up Move ") {
38
+ state.players.first().clone() shouldBe state.otherPlayer
39
+ state.players.first().position = state.board.size - 1
40
+ state.turn shouldBe 1
41
+ state.isOver shouldBe false
42
+ test("winner") {
43
+ shouldThrow<InvalidMoveException > {
44
+ state.performMoveDirectly(Advance (1))
45
+ }.mistake shouldBe HuIMoveMistake .MUST_EAT_SALAD
46
+ state.turn shouldBe 1
47
+
48
+ state.performMoveDirectly(EatSalad )
49
+ state.turn shouldBe 2
50
+ state.isOver shouldBe true
51
+ }
52
+ test("tie") {
53
+ state.currentPlayer.run {
54
+ lastAction = EatSalad
55
+ carrots = 13
56
+ salads = 0
57
+ }
58
+ state.performMoveDirectly(Advance (2))
59
+ state.turn shouldBe 2
60
+ state.isOver shouldBe true
34
61
}
35
- " produce nice XML" {
36
- Hare (Team .TWO , lastAction = EatSalad ) shouldSerializeTo """
62
+ }
63
+ test("produce nice XML ") {
64
+ Hare (Team .TWO , lastAction = EatSalad ) shouldSerializeTo """
37
65
<hare team="TWO" position="0" salads="5" carrots="68">
38
66
<lastAction class="eatsalad"/>
39
67
<cards/>
40
68
</hare>
41
69
""" .trimIndent()
42
- Hare (Team .TWO , cards = arrayListOf(Card .HURRY_AHEAD )) shouldSerializeTo """
70
+ Hare (Team .TWO , cards = arrayListOf(Card .HURRY_AHEAD )) shouldSerializeTo """
43
71
<hare team="TWO" position="0" salads="5" carrots="68">
44
72
<cards>
45
73
<card>HURRY_AHEAD</card>
46
74
</cards>
47
75
</hare>
48
76
""" .trimIndent()
49
-
50
- Board (arrayOf(Field .START )) shouldSerializeTo """
77
+
78
+ Board (arrayOf(Field .START )) shouldSerializeTo """
51
79
<board>
52
80
<field>START</field>
53
81
</board>
54
82
""" .trimIndent()
55
-
56
- state shouldSerializeTo """
83
+
84
+ state shouldSerializeTo """
57
85
<state startTeam="TWO" turn="1">
58
86
<board>
59
87
<field>START</field>
@@ -63,7 +91,7 @@ class GameStateTest: WordSpec({
63
91
<field>HARE</field>
64
92
<field>GOAL</field>
65
93
</board>
66
- <hare team="TWO" position="0" salads="5 " carrots="68 ">
94
+ <hare team="TWO" position="0" salads="0 " carrots="0 ">
67
95
<lastAction class="advance" distance="5"/>
68
96
<cards>
69
97
<card>SWAP_CARROTS</card>
@@ -78,6 +106,5 @@ class GameStateTest: WordSpec({
78
106
</lastMove>
79
107
</state>
80
108
""" .trimIndent()
81
- }
82
109
}
83
110
})
0 commit comments