]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
Finish moving the tests to test-framework.
[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 :: Assertion
57 test_c_tilde_2100_rotation_correct =
58 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 -- | 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]
83
84
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
87 -- direction.
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]
92 ==> ccwx c /= c
93
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]
101 ==> cwx c /= c
102
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
105 -- direction.
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]
110 ==> ccwy c /= c
111
112
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]
119 ==> cwy c /= c
120
121
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
124 -- direction.
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]
129 ==> ccwz c /= c
130
131
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]
138 ==> cwz c /= c
139
140
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
148
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,
151 -- produces c.
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
156
157
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
165
166
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,
169 -- produces c.
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
174
175
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
183
184
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,
187 -- produces c.
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
192
193
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
196 -- direction.
197 prop_four_cwx_is_identity :: Cardinal -> Bool
198 prop_four_cwx_is_identity c =
199 (cwx . cwx . cwx . cwx) c == c
200
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
207
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
210 -- direction.
211 prop_four_cwy_is_identity :: Cardinal -> Bool
212 prop_four_cwy_is_identity c =
213 (cwy . cwy . cwy . cwy) c == c
214
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
217 -- direction.
218 prop_four_ccwy_is_identity :: Cardinal -> Bool
219 prop_four_ccwy_is_identity c =
220 (ccwy . ccwy . ccwy . ccwy) c == c
221
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
224 -- direction.
225 prop_four_cwz_is_identity :: Cardinal -> Bool
226 prop_four_cwz_is_identity c =
227 (cwz . cwz . cwz . cwz) c == c
228
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