]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
Add a Cardinal test, computed manually and from Sorokina and Zeilfelder, p. 87.
[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_c_tilde_2100_rotation_correct]
79
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]
85
86
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
89 -- direction.
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]
94 ==> ccwx c /= c
95
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]
103 ==> cwx c /= c
104
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
107 -- direction.
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]
112 ==> ccwy c /= c
113
114
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]
121 ==> cwy c /= c
122
123
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
126 -- direction.
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]
131 ==> ccwz c /= c
132
133
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]
140 ==> cwz c /= c
141
142
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
150
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,
153 -- produces c.
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
158
159
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
167
168
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,
171 -- produces c.
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
176
177
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
185
186
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,
189 -- produces c.
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
194
195
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
198 -- direction.
199 prop_four_cwx_is_identity :: Cardinal -> Bool
200 prop_four_cwx_is_identity c =
201 (cwx . cwx . cwx . cwx) c == c
202
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
209
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
212 -- direction.
213 prop_four_cwy_is_identity :: Cardinal -> Bool
214 prop_four_cwy_is_identity c =
215 (cwy . cwy . cwy . cwy) c == c
216
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
219 -- direction.
220 prop_four_ccwy_is_identity :: Cardinal -> Bool
221 prop_four_ccwy_is_identity c =
222 (ccwy . ccwy . ccwy . ccwy) c == c
223
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
226 -- direction.
227 prop_four_cwz_is_identity :: Cardinal -> Bool
228 prop_four_cwz_is_identity c =
229 (cwz . cwz . cwz . cwz) c == c
230
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