@@ -13,6 +13,8 @@ import sc.api.plugins.Team
13
13
import sc.helpers.checkSerialization
14
14
import sc.helpers.shouldSerializeTo
15
15
import sc.helpers.testXStream
16
+ import sc.plugin2024.actions.Acceleration
17
+ import sc.plugin2024.actions.Advance
16
18
import sc.plugin2024.util.PluginConstants
17
19
18
20
class BoardTest : FunSpec ({
@@ -101,6 +103,21 @@ class BoardTest: FunSpec({
101
103
turningBoard.doesFieldHaveCurrent(cubeCoordinates) shouldBe (cubeCoordinates in current)
102
104
}
103
105
}
106
+
107
+ test("current preserved across serialization") {
108
+ val commonBoard = Board (listOf(Segment .empty(),
109
+ Segment .empty(CubeCoordinates (4, 0)),
110
+ Segment (CubeDirection .UP_RIGHT , CubeCoordinates (8, -4), generateSegment(true, arrayOf()))))
111
+ val state = GameState (commonBoard)
112
+ state.ships.first().run {
113
+ position = CubeCoordinates (1,-1)
114
+ speed = 2
115
+ movement = 2
116
+ }
117
+
118
+ state.getPossibleMoves(1) shouldContainAll state.copy(Board (commonBoard.segments.subList(0, 2), nextDirection = CubeDirection .UP_RIGHT )).getPossibleMoves(1)
119
+ state.performMove(Move (Acceleration (3), Advance (4)))
120
+ }
104
121
105
122
context("pickupPassenger") {
106
123
test("should decrease passenger count of the neighbouring field and increase passenger count of the ship") {
@@ -157,7 +174,7 @@ class BoardTest: FunSpec({
157
174
}
158
175
159
176
context("XML Serialization of") {
160
- test("single segment ") {
177
+ test("few segments ") {
161
178
// TODO column rather than field-array
162
179
val serializedSegment = """
163
180
<segment direction="RIGHT">
@@ -194,17 +211,23 @@ class BoardTest: FunSpec({
194
211
val serialized = """
195
212
<board nextDirection="RIGHT">$serializedSegment
196
213
</board>"""
197
- val segment = Segment ( CubeDirection . RIGHT , CubeCoordinates .ORIGIN , generateSegment(false, arrayOf()) )
214
+ val segment = Segment .empty( CubeCoordinates .ORIGIN )
198
215
val singleSegmentBoard = Board (listOf(segment))
216
+
199
217
singleSegmentBoard shouldSerializeTo serialized
200
- checkSerialization(testXStream, Board (listOf(segment, segment), 1), serialized.trimIndent()) { _, deserialized ->
218
+ checkSerialization(testXStream,
219
+ Board (listOf(segment, segment), 1),
220
+ serialized.trimIndent()) { _, deserialized ->
201
221
deserialized shouldBe singleSegmentBoard
202
222
}
203
- Board (listOf(segment, segment), 2).also {
204
- it.nextDirection = CubeDirection .UP_RIGHT
205
- } shouldSerializeTo """
223
+ checkSerialization(testXStream,
224
+ Board (listOf(segment, segment, Segment ( CubeDirection .UP_RIGHT , CubeCoordinates (8, -4), generateSegment(true, arrayOf()))), 2, CubeDirection . UP_LEFT ),
225
+ """
206
226
<board nextDirection="UP_RIGHT ">$serializedSegment$serializedSegment
207
- </board>"""
227
+ </board>""".trimIndent()) { original, deserialized ->
228
+ deserialized shouldBe Board (listOf(segment, segment), nextDirection = CubeDirection .UP_RIGHT )
229
+ GameState (original).getPossibleMoves(1) shouldBe GameState (deserialized).getPossibleMoves(1)
230
+ }
208
231
}
209
232
test("random Board has correct length") {
210
233
testXStream.toXML(board) shouldHaveLineCount 64
0 commit comments