]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
c3f60e58c274c41555c1f8d4217c9ab890469223
[spline3.git] / src / Tests / Cardinal.hs
1 module Tests.Cardinal
2 where
3
4 import Control.Monad (liftM, liftM2)
5 import Prelude hiding (LT)
6 import Test.HUnit
7 import Test.QuickCheck
8
9 import Cardinal
10
11
12
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]
17 where
18 f = return F
19 b = return B
20 l = return L
21 r = return R
22 d = return D
23 t = return T
24 fl = return FL
25 fr = return FR
26 fd = return FD
27 ft = return FT
28 bl = return BL
29 br = return BR
30 bd = return BD
31 bt = return BT
32 ld = return LD
33 lt = return LT
34 rd = return RD
35 rt = return RT
36 fld = return FLD
37 flt = return FLT
38 frd = return FRD
39 frt = return FRT
40 bld = return BLD
41 blt = return BLT
42 brd = return BRD
43 brt = return BRT
44 i = return I
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
50
51
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
59 where
60 expr1 =
61 (3/8)*I +
62 (1/12)*(T + R + L + D) +
63 (1/64)*(FT + FR + FL + FD) +
64 (7/48)*F +
65 (1/48)*B +
66 (1/96)*(RT + LD + LT + RD) +
67 (1/192)*(BT + BR + BL + BD)
68
69 expr2 =
70 (3/8)*I +
71 (1/12)*(F + L + R + B) +
72 (1/64)*(FT + LT + RT + BT) +
73 (7/48)*T +
74 (1/48)*D +
75 (1/96)*(FL + BR + FR + BL) +
76 (1/192)*(FD + LD + RD + BD)
77
78 cardinal_tests :: [Test]
79 cardinal_tests = [test_c_tilde_2100_rotation_correct]
80
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]
86
87
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
90 -- direction.
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]
95 ==> ccwx c /= c
96
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]
104 ==> cwx c /= c
105
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
108 -- direction.
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]
113 ==> ccwy c /= c
114
115
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]
122 ==> cwy c /= c
123
124
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
127 -- direction.
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]
132 ==> ccwz c /= c
133
134
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]
141 ==> cwz c /= c
142
143
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
151
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,
154 -- produces c.
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
159
160
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
168
169
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,
172 -- produces c.
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
177
178
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
186
187
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,
190 -- produces c.
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
195
196
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
199 -- direction.
200 prop_four_cwx_is_identity :: Cardinal -> Bool
201 prop_four_cwx_is_identity c =
202 (cwx . cwx . cwx . cwx) c == c
203
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
210
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
213 -- direction.
214 prop_four_cwy_is_identity :: Cardinal -> Bool
215 prop_four_cwy_is_identity c =
216 (cwy . cwy . cwy . cwy) c == c
217
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
220 -- direction.
221 prop_four_ccwy_is_identity :: Cardinal -> Bool
222 prop_four_ccwy_is_identity c =
223 (ccwy . ccwy . ccwy . ccwy) c == c
224
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
227 -- direction.
228 prop_four_cwz_is_identity :: Cardinal -> Bool
229 prop_four_cwz_is_identity c =
230 (cwz . cwz . cwz . cwz) c == c
231
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