Skip to content

Commit 83fbe4a

Browse files
committed
Update Connect4Test
1 parent 904e1b0 commit 83fbe4a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

games-server/src/test/kotlin/net/zomis/games/server2/Connect4Test.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import java.net.URI
1111

1212
class Connect4Test {
1313

14+
data class Connect4Move(val playerIndex: Int, val x: Int, val y: Int)
15+
1416
private val logger = KLoggers.logger(this)
1517

1618
var server: Server2? = null
@@ -49,15 +51,20 @@ class Connect4Test {
4951
}
5052

5153
sendAndExpect(p1, p2, listOf(
52-
Pair(1, 3), Pair(2, 4), Pair(1, 2), Pair(2, 5), Pair(1, 1), Pair(2, 6)
54+
Connect4Move(1, 3, 5),
55+
Connect4Move(2, 4, 5),
56+
Connect4Move(1, 2, 5),
57+
Connect4Move(2, 5, 5),
58+
Connect4Move(1, 1, 5),
59+
Connect4Move(2, 6, 5)
5360
))
5461

5562
// Try to cheat - wrong player
56-
p2.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 6 }""")
63+
p2.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": { "x": 6, "y": 5 } }""")
5764
p2.takeUntilJson { it.getText("type") == "IllegalMove" }
5865

5966
// Win the game
60-
p1.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 0 }""")
67+
p1.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": { "x": 0, "y": 5 } }""")
6168
var obj = p1.takeUntilJson { it.getText("type") == "PlayerEliminated" }
6269
assert(obj.getText("gameType") == "Connect4")
6370
assert(obj.getInt("player") == 0)
@@ -86,20 +93,13 @@ class Connect4Test {
8693
p2.close()
8794
}
8895

89-
private fun sendAndExpect(p1: WSClient, p2: WSClient, pairs: List<Pair<Int, Int>>) {
96+
private fun sendAndExpect(p1: WSClient, p2: WSClient, pairs: List<Connect4Move>) {
9097
pairs.forEach({
91-
val cl = if (it.first == 1) p1 else p2
92-
cl.send("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": ${it.second} }""")
98+
val cl = if (it.playerIndex == 1) p1 else p2
99+
cl.send("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": {"x": ${it.x}, "y": ${it.y} } }""")
93100
p1.expectJsonObject { true }
94101
p2.expectJsonObject { true }
95102
})
96-
97-
// p1.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 3 }""")
98-
// p2.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 4 }""")
99-
// p1.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 2 }""")
100-
// p2.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 5 }""")
101-
// p1.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 1 }""")
102-
// p2.sendAndExpectResponse("""v1:{ "game": "Connect4", "gameId": "1", "type": "move", "move": 6 }""")
103103
}
104104

105105
}

0 commit comments

Comments
 (0)