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 :: Assertion
57 test_c_tilde_2100_rotation_correct =
58 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 -- | A list of all directions, sans the interior and composite types.
79 all_directions :: [Cardinal]
80 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
81 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
82 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
85 -- | If we rotate a direction (other than front or back)
86 -- counter-clockwise with respect to the x-axis, we should get a new
88 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
89 prop_ccwx_rotation_changes_direction c =
90 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
91 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
94 -- | If we rotate a direction (other than front or back) clockwise
95 -- with respect to the x-axis, we should get a new direction.
96 prop_cwx_rotation_changes_direction :: Cardinal -> Property
97 prop_cwx_rotation_changes_direction c =
98 -- The front and back faces are unchanged by x-rotation.
99 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
100 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
103 -- | If we rotate a direction (other than left or right)
104 -- counter-clockwise with respect to the y-axis, we should get a new
106 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
107 prop_ccwy_rotation_changes_direction c =
108 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
109 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
113 -- | If we rotate a direction (other than left or right) clockwise
114 -- with respect to the y-axis, we should get a new direction.
115 prop_cwy_rotation_changes_direction :: Cardinal -> Property
116 prop_cwy_rotation_changes_direction c =
117 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
118 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
122 -- | If we rotate a direction (other than top or down)
123 -- counter-clockwise with respect to the z-axis, we should get a new
125 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
126 prop_ccwz_rotation_changes_direction c =
127 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
128 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
132 -- | If we rotate a direction (other than top or down) clockwise with
133 -- respect to the z-axis, we should get a new direction.
134 prop_cwz_rotation_changes_direction :: Cardinal -> Property
135 prop_cwz_rotation_changes_direction c =
136 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
137 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
141 -- | If we are given a direction c, there should only be one direction
142 -- d which, when rotated counter-clockwise with respect to the
143 -- x-axis, produces c.
144 prop_ccwx_rotation_result_unique :: Cardinal -> Property
145 prop_ccwx_rotation_result_unique c =
146 c `elem` all_directions ==>
147 (length [ d | d <- all_directions, ccwx d == c ]) == 1
149 -- | If we are given a direction c, there should only be one direction
150 -- d which, when rotated clockwise with respect to the x-axis,
152 prop_cwx_rotation_result_unique :: Cardinal -> Property
153 prop_cwx_rotation_result_unique c =
154 c `elem` all_directions ==>
155 (length [ d | d <- all_directions, cwx d == c ]) == 1
158 -- | If we are given a direction c, there should only be one direction
159 -- d which, when rotated counter-clockwise with respect to the
160 -- y-axis, produces c.
161 prop_ccwy_rotation_result_unique :: Cardinal -> Property
162 prop_ccwy_rotation_result_unique c =
163 c `elem` all_directions ==>
164 (length [ d | d <- all_directions, ccwy d == c ]) == 1
167 -- | If we are given a direction c, there should only be one direction
168 -- d which, when rotated clockwise with respect to the y-axis,
170 prop_cwy_rotation_result_unique :: Cardinal -> Property
171 prop_cwy_rotation_result_unique c =
172 c `elem` all_directions ==>
173 (length [ d | d <- all_directions, cwy d == c ]) == 1
176 -- | If we are given a direction c, there should only be one direction
177 -- d which, when rotated counter-clockwise with respect to the
178 -- z-axis, produces c.
179 prop_ccwz_rotation_result_unique :: Cardinal -> Property
180 prop_ccwz_rotation_result_unique c =
181 c `elem` all_directions ==>
182 (length [ d | d <- all_directions, ccwz d == c ]) == 1
185 -- | If we are given a direction c, there should only be one direction
186 -- d which, when rotated clockwise with respect to the z-axis,
188 prop_cwz_rotation_result_unique :: Cardinal -> Property
189 prop_cwz_rotation_result_unique c =
190 c `elem` all_directions ==>
191 (length [ d | d <- all_directions, cwz d == c ]) == 1
194 -- | If you rotate a cardinal direction four times in the clockwise
195 -- (with respect to x) direction, you should wind up with the same
197 prop_four_cwx_is_identity :: Cardinal -> Bool
198 prop_four_cwx_is_identity c =
199 (cwx . cwx . cwx . cwx) c == c
201 -- | If you rotate a cardinal direction four times in the
202 -- counter-clockwise (with respect to x) direction, you should wind up
203 -- with the same direction.
204 prop_four_ccwx_is_identity :: Cardinal -> Bool
205 prop_four_ccwx_is_identity c =
206 (ccwx . ccwx . ccwx . ccwx) c == c
208 -- | If you rotate a cardinal direction four times in the clockwise
209 -- (with respect to y) direction, you should wind up with the same
211 prop_four_cwy_is_identity :: Cardinal -> Bool
212 prop_four_cwy_is_identity c =
213 (cwy . cwy . cwy . cwy) c == c
215 -- | If you rotate a cardinal direction four times in the counter-clockwise
216 -- (with respect to y) direction, you should wind up with the same
218 prop_four_ccwy_is_identity :: Cardinal -> Bool
219 prop_four_ccwy_is_identity c =
220 (ccwy . ccwy . ccwy . ccwy) c == c
222 -- | If you rotate a cardinal direction four times in the clockwise
223 -- (with respect to z) direction, you should wind up with the same
225 prop_four_cwz_is_identity :: Cardinal -> Bool
226 prop_four_cwz_is_identity c =
227 (cwz . cwz . cwz . cwz) c == c
229 -- | If you rotate a cardinal direction four times in the
230 -- counter-clockwise (with respect to z) direction, you should wind up
231 -- with the same direction.
232 prop_four_ccwz_is_identity :: Cardinal -> Bool
233 prop_four_ccwz_is_identity c =
234 (ccwz . ccwz . ccwz . ccwz) c == c