4 import Prelude hiding (LT)
6 import Test.QuickCheck (Property, (==>))
10 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
11 -- Zeilfelder, p. 87. This test checks that the directions are
12 -- rotated properly. The order of the letters has to be just right
13 -- since I haven't defined a proper Eq instance for Cardinals.
14 test_c_tilde_2100_rotation_correct :: Assertion
15 test_c_tilde_2100_rotation_correct =
16 assertEqual "auto-rotate equals manual rotate" ((ccwz . ccwz . cwy) expr1) expr2
20 (1/12)*(T + R + L + D) +
21 (1/64)*(FT + FR + FL + FD) +
24 (1/96)*(RT + LD + LT + RD) +
25 (1/192)*(BT + BR + BL + BD)
29 (1/12)*(F + L + R + B) +
30 (1/64)*(FT + LT + RT + BT) +
33 (1/96)*(FL + BR + FR + BL) +
34 (1/192)*(FD + LD + RD + BD)
36 -- | A list of all directions, sans the interior and composite types.
37 all_directions :: [Cardinal]
38 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
39 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
40 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
43 -- | If we rotate a direction (other than front or back)
44 -- counter-clockwise with respect to the x-axis, we should get a new
46 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
47 prop_ccwx_rotation_changes_direction c =
48 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
49 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
52 -- | If we rotate a direction (other than front or back) clockwise
53 -- with respect to the x-axis, we should get a new direction.
54 prop_cwx_rotation_changes_direction :: Cardinal -> Property
55 prop_cwx_rotation_changes_direction c =
56 -- The front and back faces are unchanged by x-rotation.
57 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
58 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
61 -- | If we rotate a direction (other than left or right)
62 -- counter-clockwise with respect to the y-axis, we should get a new
64 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
65 prop_ccwy_rotation_changes_direction c =
66 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
67 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
71 -- | If we rotate a direction (other than left or right) clockwise
72 -- with respect to the y-axis, we should get a new direction.
73 prop_cwy_rotation_changes_direction :: Cardinal -> Property
74 prop_cwy_rotation_changes_direction c =
75 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
76 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
80 -- | If we rotate a direction (other than top or down)
81 -- counter-clockwise with respect to the z-axis, we should get a new
83 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
84 prop_ccwz_rotation_changes_direction c =
85 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
86 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
90 -- | If we rotate a direction (other than top or down) clockwise with
91 -- respect to the z-axis, we should get a new direction.
92 prop_cwz_rotation_changes_direction :: Cardinal -> Property
93 prop_cwz_rotation_changes_direction c =
94 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
95 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
99 -- | If we are given a direction c, there should only be one direction
100 -- d which, when rotated counter-clockwise with respect to the
101 -- x-axis, produces c.
102 prop_ccwx_rotation_result_unique :: Cardinal -> Property
103 prop_ccwx_rotation_result_unique c =
104 c `elem` all_directions ==>
105 (length [ d | d <- all_directions, ccwx d == c ]) == 1
107 -- | If we are given a direction c, there should only be one direction
108 -- d which, when rotated clockwise with respect to the x-axis,
110 prop_cwx_rotation_result_unique :: Cardinal -> Property
111 prop_cwx_rotation_result_unique c =
112 c `elem` all_directions ==>
113 (length [ d | d <- all_directions, cwx d == c ]) == 1
116 -- | If we are given a direction c, there should only be one direction
117 -- d which, when rotated counter-clockwise with respect to the
118 -- y-axis, produces c.
119 prop_ccwy_rotation_result_unique :: Cardinal -> Property
120 prop_ccwy_rotation_result_unique c =
121 c `elem` all_directions ==>
122 (length [ d | d <- all_directions, ccwy d == c ]) == 1
125 -- | If we are given a direction c, there should only be one direction
126 -- d which, when rotated clockwise with respect to the y-axis,
128 prop_cwy_rotation_result_unique :: Cardinal -> Property
129 prop_cwy_rotation_result_unique c =
130 c `elem` all_directions ==>
131 (length [ d | d <- all_directions, cwy d == c ]) == 1
134 -- | If we are given a direction c, there should only be one direction
135 -- d which, when rotated counter-clockwise with respect to the
136 -- z-axis, produces c.
137 prop_ccwz_rotation_result_unique :: Cardinal -> Property
138 prop_ccwz_rotation_result_unique c =
139 c `elem` all_directions ==>
140 (length [ d | d <- all_directions, ccwz d == c ]) == 1
143 -- | If we are given a direction c, there should only be one direction
144 -- d which, when rotated clockwise with respect to the z-axis,
146 prop_cwz_rotation_result_unique :: Cardinal -> Property
147 prop_cwz_rotation_result_unique c =
148 c `elem` all_directions ==>
149 (length [ d | d <- all_directions, cwz d == c ]) == 1
152 -- | If you rotate a cardinal direction four times in the clockwise
153 -- (with respect to x) direction, you should wind up with the same
155 prop_four_cwx_is_identity :: Cardinal -> Bool
156 prop_four_cwx_is_identity c =
157 (cwx . cwx . cwx . cwx) c == c
159 -- | If you rotate a cardinal direction four times in the
160 -- counter-clockwise (with respect to x) direction, you should wind up
161 -- with the same direction.
162 prop_four_ccwx_is_identity :: Cardinal -> Bool
163 prop_four_ccwx_is_identity c =
164 (ccwx . ccwx . ccwx . ccwx) c == c
166 -- | If you rotate a cardinal direction four times in the clockwise
167 -- (with respect to y) direction, you should wind up with the same
169 prop_four_cwy_is_identity :: Cardinal -> Bool
170 prop_four_cwy_is_identity c =
171 (cwy . cwy . cwy . cwy) c == c
173 -- | If you rotate a cardinal direction four times in the counter-clockwise
174 -- (with respect to y) direction, you should wind up with the same
176 prop_four_ccwy_is_identity :: Cardinal -> Bool
177 prop_four_ccwy_is_identity c =
178 (ccwy . ccwy . ccwy . ccwy) c == c
180 -- | If you rotate a cardinal direction four times in the clockwise
181 -- (with respect to z) direction, you should wind up with the same
183 prop_four_cwz_is_identity :: Cardinal -> Bool
184 prop_four_cwz_is_identity c =
185 (cwz . cwz . cwz . cwz) c == c
187 -- | If you rotate a cardinal direction four times in the
188 -- counter-clockwise (with respect to z) direction, you should wind up
189 -- with the same direction.
190 prop_four_ccwz_is_identity :: Cardinal -> Bool
191 prop_four_ccwz_is_identity c =
192 (ccwz . ccwz . ccwz . ccwz) c == c