Skip to content

Commit ac741c5

Browse files
committed
test(plugin26): curious xstream issues
1 parent 4bd3456 commit ac741c5

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

plugin2026/src/main/kotlin/sc/plugin2026/Board.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class Board(
3333
return map.toString()
3434
}
3535

36-
override fun clone(): Board =
37-
Board(gameField.deepCopy())
36+
override fun clone(): Board {
37+
println(gameField::class.java)
38+
return Board(gameField.deepCopy())
39+
}
3840

3941
fun getTeam(pos: Coordinates): Team? =
4042
this[pos].team

plugin2026/src/test/kotlin/sc/plugin2026/BoardTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package sc.plugin2026
33
import io.kotest.core.spec.style.FunSpec
44
import io.kotest.matchers.*
55
import io.kotest.matchers.string.shouldHaveLineCount
6+
import io.kotest.matchers.types.shouldBeSameInstanceAs
7+
import sc.helpers.shouldSerializeTo
68
import sc.helpers.testXStream
79

810
class BoardTest: FunSpec({
@@ -15,6 +17,25 @@ class BoardTest: FunSpec({
1517
context("serialization") {
1618
test("board") {
1719
testXStream.toXML(board) shouldHaveLineCount 122
20+
21+
FieldState.ONE_L shouldSerializeTo "<field>ONE_L</field>"
22+
testXStream.fromXML(testXStream.toXML(FieldState.ONE_L)) shouldBeSameInstanceAs FieldState.ONE_L
23+
24+
board.clone() shouldBe board
25+
testXStream.toXML(board.clone()) shouldHaveLineCount 122
26+
27+
Board(arrayOf(arrayOf(FieldState.ONE_S, FieldState.ONE_M, FieldState.ONE_L))) shouldSerializeTo """
28+
<board>
29+
<row class="field-array">
30+
<field>ONE_S</field>
31+
<field>ONE_M</field>
32+
<field>ONE_L</field>
33+
</row>
34+
</board>""".trimIndent()
35+
36+
val xml = testXStream.toXML(board)
37+
val reboard = testXStream.fromXML(xml)
38+
//(reboard as Board).clone() shouldBe board
1839
}
1940
}
2041
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package sc.plugin2026
2+
3+
import io.kotest.assertions.throwables.shouldThrow
4+
import io.kotest.core.spec.style.FunSpec
5+
import io.kotest.matchers.shouldBe
6+
import io.kotest.matchers.shouldNotBe
7+
import io.kotest.matchers.string.shouldHaveLineCount
8+
import sc.api.plugins.Coordinates
9+
import sc.api.plugins.Direction
10+
import sc.api.plugins.Team
11+
import sc.helpers.testXStream
12+
import sc.shared.InvalidMoveException
13+
14+
class GameStateTest: FunSpec({
15+
test("cloning") {
16+
val state = GameState()
17+
state.clone() shouldBe state
18+
}
19+
context("XML Serialization") {
20+
test("deserialization") {
21+
val state = GameState()
22+
val xml = testXStream.toXML(state)
23+
xml shouldHaveLineCount 124
24+
val restate = testXStream.fromXML(xml) as GameState
25+
restate.startTeam shouldBe Team.ONE
26+
restate.currentTeam shouldBe Team.ONE
27+
restate shouldBe state
28+
restate.board.toString() shouldBe state.board.toString()
29+
30+
val startMove = Move(Coordinates(0, 1), Direction.RIGHT)
31+
state.performMoveDirectly(startMove)
32+
restate shouldNotBe state
33+
restate.board.clone()
34+
//val clone = restate.clone()
35+
//clone shouldBe state
36+
restate.performMoveDirectly(startMove)
37+
restate shouldBe state
38+
//clone shouldNotBe state
39+
restate.performMoveDirectly(Move(Coordinates(1, 0), Direction.RIGHT))
40+
shouldThrow<InvalidMoveException> {
41+
restate.performMoveDirectly(startMove)
42+
}.mistake shouldBe PiranhaMoveMistake.WRONG_START
43+
}
44+
}
45+
})

0 commit comments

Comments
 (0)