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_c_tilde_2100_rotation_correct]
80 -- | A list of all directions, sans the interior and composite types.
81 all_directions :: [Cardinal]
82 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
83 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
84 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
87 -- | If we rotate a direction (other than front or back)
88 -- counter-clockwise with respect to the x-axis, we should get a new
90 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
91 prop_ccwx_rotation_changes_direction c =
92 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
93 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
96 -- | If we rotate a direction (other than front or back) clockwise
97 -- with respect to the x-axis, we should get a new direction.
98 prop_cwx_rotation_changes_direction :: Cardinal -> Property
99 prop_cwx_rotation_changes_direction c =
100 -- The front and back faces are unchanged by x-rotation.
101 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
102 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
105 -- | If we rotate a direction (other than left or right)
106 -- counter-clockwise with respect to the y-axis, we should get a new
108 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
109 prop_ccwy_rotation_changes_direction c =
110 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
111 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
115 -- | If we rotate a direction (other than left or right) clockwise
116 -- with respect to the y-axis, we should get a new direction.
117 prop_cwy_rotation_changes_direction :: Cardinal -> Property
118 prop_cwy_rotation_changes_direction c =
119 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
120 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
124 -- | If we rotate a direction (other than top or down)
125 -- counter-clockwise with respect to the z-axis, we should get a new
127 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
128 prop_ccwz_rotation_changes_direction c =
129 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
130 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
134 -- | If we rotate a direction (other than top or down) clockwise with
135 -- respect to the z-axis, we should get a new direction.
136 prop_cwz_rotation_changes_direction :: Cardinal -> Property
137 prop_cwz_rotation_changes_direction c =
138 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
139 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
143 -- | If we are given a direction c, there should only be one direction
144 -- d which, when rotated counter-clockwise with respect to the
145 -- x-axis, produces c.
146 prop_ccwx_rotation_result_unique :: Cardinal -> Property
147 prop_ccwx_rotation_result_unique c =
148 c `elem` all_directions ==>
149 (length [ d | d <- all_directions, ccwx d == c ]) == 1
151 -- | If we are given a direction c, there should only be one direction
152 -- d which, when rotated clockwise with respect to the x-axis,
154 prop_cwx_rotation_result_unique :: Cardinal -> Property
155 prop_cwx_rotation_result_unique c =
156 c `elem` all_directions ==>
157 (length [ d | d <- all_directions, cwx d == c ]) == 1
160 -- | If we are given a direction c, there should only be one direction
161 -- d which, when rotated counter-clockwise with respect to the
162 -- y-axis, produces c.
163 prop_ccwy_rotation_result_unique :: Cardinal -> Property
164 prop_ccwy_rotation_result_unique c =
165 c `elem` all_directions ==>
166 (length [ d | d <- all_directions, ccwy d == c ]) == 1
169 -- | If we are given a direction c, there should only be one direction
170 -- d which, when rotated clockwise with respect to the y-axis,
172 prop_cwy_rotation_result_unique :: Cardinal -> Property
173 prop_cwy_rotation_result_unique c =
174 c `elem` all_directions ==>
175 (length [ d | d <- all_directions, cwy d == c ]) == 1
178 -- | If we are given a direction c, there should only be one direction
179 -- d which, when rotated counter-clockwise with respect to the
180 -- z-axis, produces c.
181 prop_ccwz_rotation_result_unique :: Cardinal -> Property
182 prop_ccwz_rotation_result_unique c =
183 c `elem` all_directions ==>
184 (length [ d | d <- all_directions, ccwz d == c ]) == 1
187 -- | If we are given a direction c, there should only be one direction
188 -- d which, when rotated clockwise with respect to the z-axis,
190 prop_cwz_rotation_result_unique :: Cardinal -> Property
191 prop_cwz_rotation_result_unique c =
192 c `elem` all_directions ==>
193 (length [ d | d <- all_directions, cwz d == c ]) == 1
196 -- | If you rotate a cardinal direction four times in the clockwise
197 -- (with respect to x) direction, you should wind up with the same
199 prop_four_cwx_is_identity :: Cardinal -> Bool
200 prop_four_cwx_is_identity c =
201 (cwx . cwx . cwx . cwx) c == c
203 -- | If you rotate a cardinal direction four times in the
204 -- counter-clockwise (with respect to x) direction, you should wind up
205 -- with the same direction.
206 prop_four_ccwx_is_identity :: Cardinal -> Bool
207 prop_four_ccwx_is_identity c =
208 (ccwx . ccwx . ccwx . ccwx) c == c
210 -- | If you rotate a cardinal direction four times in the clockwise
211 -- (with respect to y) direction, you should wind up with the same
213 prop_four_cwy_is_identity :: Cardinal -> Bool
214 prop_four_cwy_is_identity c =
215 (cwy . cwy . cwy . cwy) c == c
217 -- | If you rotate a cardinal direction four times in the counter-clockwise
218 -- (with respect to y) direction, you should wind up with the same
220 prop_four_ccwy_is_identity :: Cardinal -> Bool
221 prop_four_ccwy_is_identity c =
222 (ccwy . ccwy . ccwy . ccwy) c == c
224 -- | If you rotate a cardinal direction four times in the clockwise
225 -- (with respect to z) direction, you should wind up with the same
227 prop_four_cwz_is_identity :: Cardinal -> Bool
228 prop_four_cwz_is_identity c =
229 (cwz . cwz . cwz . cwz) c == c
231 -- | If you rotate a cardinal direction four times in the
232 -- counter-clockwise (with respect to z) direction, you should wind up
233 -- with the same direction.
234 prop_four_ccwz_is_identity :: Cardinal -> Bool
235 prop_four_ccwz_is_identity c =
236 (ccwz . ccwz . ccwz . ccwz) c == c