Skip to content

Commit 65d6b5c

Browse files
committed
test(plugin): base test on table driven approach
1 parent 8ae8328 commit 65d6b5c

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package sc.plugin2021
22

3+
import io.kotlintest.data.forall
34
import io.kotlintest.matchers.maps.shouldContain
45
import io.kotlintest.matchers.maps.shouldContainExactly
56
import io.kotlintest.shouldBe
67
import io.kotlintest.specs.StringSpec
8+
import io.kotlintest.tables.row
79
import org.opentest4j.AssertionFailedError
810
import sc.plugin2021.util.*
911

@@ -162,39 +164,33 @@ class PieceTest: StringSpec({
162164
piece.coordinates shouldBe coordinates
163165
}
164166
"XML conversion" {
165-
val pieces = listOf(
166-
Piece(Color.YELLOW, PieceShape.TETRO_O, Rotation.RIGHT, false),
167-
Piece(Color.RED, PieceShape.PENTO_Y, Rotation.LEFT, false),
168-
Piece(Color.BLUE, PieceShape.PENTO_P, Rotation.MIRROR, true),
169-
Piece(Color.GREEN, PieceShape.TRIO_L, Rotation.NONE, true, Coordinates(5, 9))
170-
)
171-
172-
Configuration.xStream.toXML(pieces[0]) shouldBe """
173-
<piece color="YELLOW" kind="TETRO_O" rotation="RIGHT" isFlipped="false">
174-
<position x="0" y="0"/>
175-
</piece>
176-
""".trimIndent()
177-
Configuration.xStream.toXML(pieces[1]) shouldBe """
178-
<piece color="RED" kind="PENTO_Y" rotation="LEFT" isFlipped="false">
179-
<position x="0" y="0"/>
180-
</piece>
181-
""".trimIndent()
182-
Configuration.xStream.toXML(pieces[2]) shouldBe """
183-
<piece color="BLUE" kind="PENTO_P" rotation="MIRROR" isFlipped="true">
184-
<position x="0" y="0"/>
185-
</piece>
186-
""".trimIndent()
187-
Configuration.xStream.toXML(pieces[3]) shouldBe """
188-
<piece color="GREEN" kind="TRIO_L" rotation="NONE" isFlipped="true">
189-
<position x="5" y="9"/>
190-
</piece>
191-
""".trimIndent()
192-
193-
pieces.forEach{
194-
val xml = Configuration.xStream.toXML(it)
195-
val converted = Configuration.xStream.fromXML(xml) as Piece
196-
converted.toString() shouldBe it.toString()
197-
converted shouldBe it
167+
forall(
168+
row(Piece(Color.YELLOW, PieceShape.TETRO_O, Rotation.RIGHT, false), """
169+
<piece color="YELLOW" kind="TETRO_O" rotation="RIGHT" isFlipped="false">
170+
<position x="0" y="0"/>
171+
</piece>
172+
""".trimIndent()),
173+
row(Piece(Color.RED, PieceShape.PENTO_Y, Rotation.LEFT, false), """
174+
<piece color="RED" kind="PENTO_Y" rotation="LEFT" isFlipped="false">
175+
<position x="0" y="0"/>
176+
</piece>
177+
""".trimIndent()),
178+
row(Piece(Color.BLUE, PieceShape.PENTO_P, Rotation.MIRROR, true), """
179+
<piece color="BLUE" kind="PENTO_P" rotation="MIRROR" isFlipped="true">
180+
<position x="0" y="0"/>
181+
</piece>
182+
""".trimIndent()),
183+
row(Piece(Color.GREEN, PieceShape.TRIO_L, Rotation.NONE, true, Coordinates(5, 9)), """
184+
<piece color="GREEN" kind="TRIO_L" rotation="NONE" isFlipped="true">
185+
<position x="5" y="9"/>
186+
</piece>
187+
""".trimIndent())
188+
) {piece, xml ->
189+
Configuration.xStream.toXML(piece) shouldBe xml
190+
191+
val converted = Configuration.xStream.fromXML(Configuration.xStream.toXML(piece)) as Piece
192+
converted.toString() shouldBe piece.toString()
193+
converted shouldBe piece
198194
}
199195
}
200196
"Piece transformation calculation" {

0 commit comments

Comments
 (0)