Skip to content

Commit f270383

Browse files
committed
test(plugin): add another shape transformation test
1 parent 2472c48 commit f270383

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

plugin/src/test/sc/plugin2021/ManualGameTest.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sc.plugin2021.Game
44
import sc.plugin2021.Move
55
import sc.plugin2021.SetMove
66
import sc.plugin2021.helper.MoveParser
7+
import sc.plugin2021.util.printShapes
78
import kotlin.concurrent.fixedRateTimer
89
import kotlin.system.exitProcess
910

@@ -46,8 +47,10 @@ fun loop() {
4647
current = game.gameState.getOpponent(current)!!
4748
} catch (e: Exception) {
4849
println(e)
49-
if (move is SetMove)
50-
println("Piece was ${move.piece.coordinates}")
50+
if (move is SetMove) {
51+
println("Piece was:")
52+
printShapes(move.piece.shape)
53+
}
5154
}
5255
}
5356
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,37 @@ class PieceTest: StringSpec({
9191
}
9292
}
9393
}
94+
"Test Set transformation arithmetic (TETRO_L)" {
95+
val shape = PieceShape.TETRO_L
96+
val TID = listOf("NN", "RN", "MN", "LN", "NY", "RY", "MY", "LY")
97+
val SHOULD = (TID zip listOf(
98+
setOf(Coordinates(0, 0), Coordinates(0, 1), Coordinates(0, 2), Coordinates(1, 2)),
99+
setOf(Coordinates(0, 0), Coordinates(0, 1), Coordinates(1, 0), Coordinates(2, 0)),
100+
setOf(Coordinates(0, 0), Coordinates(1, 0), Coordinates(1, 1), Coordinates(1, 2)),
101+
setOf(Coordinates(0, 1), Coordinates(1, 1), Coordinates(2, 1), Coordinates(2, 0)),
102+
setOf(Coordinates(1, 0), Coordinates(1, 1), Coordinates(1, 2), Coordinates(0, 2)),
103+
setOf(Coordinates(0, 0), Coordinates(1, 0), Coordinates(2, 0), Coordinates(2, 1)),
104+
setOf(Coordinates(1, 0), Coordinates(0, 0), Coordinates(0, 1), Coordinates(0, 2)),
105+
setOf(Coordinates(0, 0), Coordinates(0, 1), Coordinates(1, 1), Coordinates(2, 1))
106+
)).toMap()
107+
val transformations = (TID zip (
108+
(Rotation.values() zip List(Rotation.values().size) {false}) +
109+
(Rotation.values() zip List(Rotation.values().size) {true})
110+
)).toMap()
111+
val IS = transformations.map {
112+
it.key to shape.transform(it.value.first, it.value.second)
113+
}.toMap()
114+
115+
TID.forEach {
116+
try {
117+
IS[it] shouldBe SHOULD[it]
118+
} catch (e: AssertionFailedError) {
119+
println("Expected: $it Actual:")
120+
printShapes(SHOULD.getValue(it), IS.getValue(it))
121+
throw e
122+
}
123+
}
124+
}
94125
"Piece coordination calculation" {
95126
val position = Coordinates(2, 2)
96127
val coordinates = setOf(Coordinates(2, 3), Coordinates(3, 3), Coordinates(3, 2))

0 commit comments

Comments
 (0)