@@ -4,6 +4,7 @@ import com.thoughtworks.xstream.XStream
4
4
import io.kotlintest.inspectors.forAll
5
5
import io.kotlintest.shouldBe
6
6
import io.kotlintest.specs.StringSpec
7
+ import org.opentest4j.AssertionFailedError
7
8
import sc.plugin2021.util.*
8
9
9
10
@@ -31,22 +32,64 @@ class PieceTest: StringSpec({
31
32
shape.flip(true).flip() shouldBe shape
32
33
}
33
34
}
34
- " Test Set transformation arithmetic" {
35
+ " Test Set transformation arithmetic (PENTO_W)" {
36
+ val TID = listOf("NN ", "RN ", "MN ", "LN ", "NY ", "RY ", "MY ", "LY ")
37
+ val shape = PieceShape .PENTO_W
35
38
val shapes = listOf(
36
39
setOf(Coordinates (0, 0), Coordinates (0, 1), Coordinates (1, 1), Coordinates (1, 2), Coordinates (2, 2)),
37
40
setOf(Coordinates (0, 2), Coordinates (0, 1), Coordinates (1, 1), Coordinates (1, 0), Coordinates (2, 0)),
38
41
setOf(Coordinates (0, 0), Coordinates (1, 0), Coordinates (1, 1), Coordinates (2, 1), Coordinates (2, 2)),
39
42
setOf(Coordinates (0, 2), Coordinates (1, 2), Coordinates (1, 1), Coordinates (2, 1), Coordinates (2, 0))
40
43
)
41
-
42
- PieceShape .PENTO_W .transform(Rotation .NONE , false) shouldBe shapes[0 ]
43
- PieceShape .PENTO_W .transform(Rotation .RIGHT , false) shouldBe shapes[1 ]
44
- PieceShape .PENTO_W .transform(Rotation .MIRROR , false) shouldBe shapes[2 ]
45
- PieceShape .PENTO_W .transform(Rotation .LEFT , false) shouldBe shapes[3 ]
46
- PieceShape .PENTO_W .transform(Rotation .NONE , true) shouldBe shapes[3 ]
47
- PieceShape .PENTO_W .transform(Rotation .RIGHT , true) shouldBe shapes[2 ]
48
- PieceShape .PENTO_W .transform(Rotation .MIRROR , true) shouldBe shapes[1 ]
49
- PieceShape .PENTO_W .transform(Rotation .LEFT , true) shouldBe shapes[0 ]
44
+ val SHOULD = (TID zip (shapes + shapes.asReversed())).toMap()
45
+ val transformations = (TID zip (
46
+ (Rotation .values() zip List (Rotation .values().size) {false}) +
47
+ (Rotation .values() zip List (Rotation .values().size) {true})
48
+ )).toMap()
49
+ val IS = transformations.map {
50
+ it.key to shape.transform(it.value.first, it.value.second)
51
+ }.toMap()
52
+
53
+ TID .forEach {
54
+ try {
55
+ IS [it] shouldBe SHOULD [it]
56
+ } catch (e: AssertionFailedError ) {
57
+ println("Expected : $it Actual :")
58
+ printShapes(SHOULD .getValue(it), IS .getValue(it))
59
+ throw e
60
+ }
61
+ }
62
+ }
63
+ " Test Set transformation arithmetic (PENTO_R)" {
64
+ val shape = PieceShape .PENTO_R
65
+ val TID = listOf("NN ", "RN ", "MN ", "LN ", "NY ", "RY ", "MY ", "LY ")
66
+ val SHOULD = (TID zip listOf(
67
+ setOf(Coordinates (0, 1), Coordinates (1, 2), Coordinates (1, 1), Coordinates (2, 1), Coordinates (2, 0)),
68
+ setOf(Coordinates (0, 1), Coordinates (1, 0), Coordinates (1, 1), Coordinates (1, 2), Coordinates (2, 2)),
69
+ setOf(Coordinates (0, 2), Coordinates (0, 1), Coordinates (1, 1), Coordinates (1, 0), Coordinates (2, 1)),
70
+ setOf(Coordinates (0, 0), Coordinates (1, 0), Coordinates (1, 1), Coordinates (1, 2), Coordinates (2, 1)),
71
+ setOf(Coordinates (0, 0), Coordinates (0, 1), Coordinates (1, 1), Coordinates (1, 2), Coordinates (2, 1)),
72
+ setOf(Coordinates (0, 2), Coordinates (1, 2), Coordinates (1, 1), Coordinates (1, 0), Coordinates (2, 1)),
73
+ setOf(Coordinates (0, 1), Coordinates (1, 0), Coordinates (1, 1), Coordinates (2, 1), Coordinates (2, 2)),
74
+ setOf(Coordinates (0, 1), Coordinates (1, 2), Coordinates (1, 1), Coordinates (1, 0), Coordinates (2, 0))
75
+ )).toMap()
76
+ val transformations = (TID zip (
77
+ (Rotation .values() zip List (Rotation .values().size) {false}) +
78
+ (Rotation .values() zip List (Rotation .values().size) {true})
79
+ )).toMap()
80
+ val IS = transformations.map {
81
+ it.key to shape.transform(it.value.first, it.value.second)
82
+ }.toMap()
83
+
84
+ TID .forEach {
85
+ try {
86
+ IS [it] shouldBe SHOULD [it]
87
+ } catch (e: AssertionFailedError ) {
88
+ println("Expected : $it Actual :")
89
+ printShapes(SHOULD .getValue(it), IS .getValue(it))
90
+ throw e
91
+ }
92
+ }
50
93
}
51
94
" Piece coordination calculation" {
52
95
val position = Coordinates (2, 2)
0 commit comments