4 import Control.Monad (liftM, liftM2)
5 import Prelude hiding (LT)
13 instance Arbitrary Cardinal where
14 arbitrary = oneof [f,b,l,r,d,t,fl,fr,fd,ft,bl,br,bd,bt,ld,lt,
15 rd,rt,fld,flt,frd,frt,bld,blt,brd,brt,i,
16 scalar,csum,cdiff,cprod,cquot]
45 scalar = liftM Scalar arbitrary
46 csum = liftM2 Sum arbitrary arbitrary
47 cdiff = liftM2 Difference arbitrary arbitrary
48 cprod = liftM2 Product arbitrary arbitrary
49 cquot = liftM2 Quotient arbitrary arbitrary
52 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
53 -- Zeilfelder, p. 87. This test checks that the directions are
54 -- rotated properly. The order of the letters has to be just right
55 -- since I haven't defined a proper Eq instance for Cardinals.
56 test_c_tilde_2100_rotation_correct :: Test
57 test_c_tilde_2100_rotation_correct =
58 TestCase $ assertEqual "auto-rotate equals manual rotate" ((ccwz . ccwz . cwy) expr1) expr2
62 (1/12)*(T + R + L + D) +
63 (1/64)*(FT + FR + FL + FD) +
66 (1/96)*(RT + LD + LT + RD) +
67 (1/192)*(BT + BR + BL + BD)
71 (1/12)*(F + L + R + B) +
72 (1/64)*(FT + LT + RT + BT) +
75 (1/96)*(FL + BR + FR + BL) +
76 (1/192)*(FD + LD + RD + BD)
78 cardinal_tests :: [Test]
79 cardinal_tests = [test_c_tilde_2100_rotation_correct]
81 -- | A list of all directions, sans the interior and composite types.
82 all_directions :: [Cardinal]
83 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
84 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
85 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
88 -- | If we rotate a direction (other than front or back)
89 -- counter-clockwise with respect to the x-axis, we should get a new
91 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
92 prop_ccwx_rotation_changes_direction c =
93 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
94 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
97 -- | If we rotate a direction (other than front or back) clockwise
98 -- with respect to the x-axis, we should get a new direction.
99 prop_cwx_rotation_changes_direction :: Cardinal -> Property
100 prop_cwx_rotation_changes_direction c =
101 -- The front and back faces are unchanged by x-rotation.
102 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
103 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
106 -- | If we rotate a direction (other than left or right)
107 -- counter-clockwise with respect to the y-axis, we should get a new
109 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
110 prop_ccwy_rotation_changes_direction c =
111 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
112 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
116 -- | If we rotate a direction (other than left or right) clockwise
117 -- with respect to the y-axis, we should get a new direction.
118 prop_cwy_rotation_changes_direction :: Cardinal -> Property
119 prop_cwy_rotation_changes_direction c =
120 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
121 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
125 -- | If we rotate a direction (other than top or down)
126 -- counter-clockwise with respect to the z-axis, we should get a new
128 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
129 prop_ccwz_rotation_changes_direction c =
130 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
131 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
135 -- | If we rotate a direction (other than top or down) clockwise with
136 -- respect to the z-axis, we should get a new direction.
137 prop_cwz_rotation_changes_direction :: Cardinal -> Property
138 prop_cwz_rotation_changes_direction c =
139 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
140 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
144 -- | If we are given a direction c, there should only be one direction
145 -- d which, when rotated counter-clockwise with respect to the
146 -- x-axis, produces c.
147 prop_ccwx_rotation_result_unique :: Cardinal -> Property
148 prop_ccwx_rotation_result_unique c =
149 c `elem` all_directions ==>
150 (length [ d | d <- all_directions, ccwx d == c ]) == 1
152 -- | If we are given a direction c, there should only be one direction
153 -- d which, when rotated clockwise with respect to the x-axis,
155 prop_cwx_rotation_result_unique :: Cardinal -> Property
156 prop_cwx_rotation_result_unique c =
157 c `elem` all_directions ==>
158 (length [ d | d <- all_directions, cwx d == c ]) == 1
161 -- | If we are given a direction c, there should only be one direction
162 -- d which, when rotated counter-clockwise with respect to the
163 -- y-axis, produces c.
164 prop_ccwy_rotation_result_unique :: Cardinal -> Property
165 prop_ccwy_rotation_result_unique c =
166 c `elem` all_directions ==>
167 (length [ d | d <- all_directions, ccwy d == c ]) == 1
170 -- | If we are given a direction c, there should only be one direction
171 -- d which, when rotated clockwise with respect to the y-axis,
173 prop_cwy_rotation_result_unique :: Cardinal -> Property
174 prop_cwy_rotation_result_unique c =
175 c `elem` all_directions ==>
176 (length [ d | d <- all_directions, cwy d == c ]) == 1
179 -- | If we are given a direction c, there should only be one direction
180 -- d which, when rotated counter-clockwise with respect to the
181 -- z-axis, produces c.
182 prop_ccwz_rotation_result_unique :: Cardinal -> Property
183 prop_ccwz_rotation_result_unique c =
184 c `elem` all_directions ==>
185 (length [ d | d <- all_directions, ccwz d == c ]) == 1
188 -- | If we are given a direction c, there should only be one direction
189 -- d which, when rotated clockwise with respect to the z-axis,
191 prop_cwz_rotation_result_unique :: Cardinal -> Property
192 prop_cwz_rotation_result_unique c =
193 c `elem` all_directions ==>
194 (length [ d | d <- all_directions, cwz d == c ]) == 1
197 -- | If you rotate a cardinal direction four times in the clockwise
198 -- (with respect to x) direction, you should wind up with the same
200 prop_four_cwx_is_identity :: Cardinal -> Bool
201 prop_four_cwx_is_identity c =
202 (cwx . cwx . cwx . cwx) c == c
204 -- | If you rotate a cardinal direction four times in the
205 -- counter-clockwise (with respect to x) direction, you should wind up
206 -- with the same direction.
207 prop_four_ccwx_is_identity :: Cardinal -> Bool
208 prop_four_ccwx_is_identity c =
209 (ccwx . ccwx . ccwx . ccwx) c == c
211 -- | If you rotate a cardinal direction four times in the clockwise
212 -- (with respect to y) direction, you should wind up with the same
214 prop_four_cwy_is_identity :: Cardinal -> Bool
215 prop_four_cwy_is_identity c =
216 (cwy . cwy . cwy . cwy) c == c
218 -- | If you rotate a cardinal direction four times in the counter-clockwise
219 -- (with respect to y) direction, you should wind up with the same
221 prop_four_ccwy_is_identity :: Cardinal -> Bool
222 prop_four_ccwy_is_identity c =
223 (ccwy . ccwy . ccwy . ccwy) c == c
225 -- | If you rotate a cardinal direction four times in the clockwise
226 -- (with respect to z) direction, you should wind up with the same
228 prop_four_cwz_is_identity :: Cardinal -> Bool
229 prop_four_cwz_is_identity c =
230 (cwz . cwz . cwz . cwz) c == c
232 -- | If you rotate a cardinal direction four times in the
233 -- counter-clockwise (with respect to z) direction, you should wind up
234 -- with the same direction.
235 prop_four_ccwz_is_identity :: Cardinal -> Bool
236 prop_four_ccwz_is_identity c =
237 (ccwz . ccwz . ccwz . ccwz) c == c