]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
A bunch more test cleanup.
[spline3.git] / src / Tests / Cardinal.hs
1 module Tests.Cardinal
2 where
3
4 import Prelude hiding (LT)
5 import Test.HUnit
6 import Test.QuickCheck (Property, (==>))
7
8 import Cardinal
9
10 -- | We know what (c t6 2 1 0 0) should be from Sorokina and
11 -- Zeilfelder, p. 87. This test checks that the directions are
12 -- rotated properly. The order of the letters has to be just right
13 -- since I haven't defined a proper Eq instance for Cardinals.
14 test_c_tilde_2100_rotation_correct :: Assertion
15 test_c_tilde_2100_rotation_correct =
16 assertEqual "auto-rotate equals manual rotate" ((ccwz . ccwz . cwy) expr1) expr2
17 where
18 expr1 =
19 (3/8)*I +
20 (1/12)*(T + R + L + D) +
21 (1/64)*(FT + FR + FL + FD) +
22 (7/48)*F +
23 (1/48)*B +
24 (1/96)*(RT + LD + LT + RD) +
25 (1/192)*(BT + BR + BL + BD)
26
27 expr2 =
28 (3/8)*I +
29 (1/12)*(F + L + R + B) +
30 (1/64)*(FT + LT + RT + BT) +
31 (7/48)*T +
32 (1/48)*D +
33 (1/96)*(FL + BR + FR + BL) +
34 (1/192)*(FD + LD + RD + BD)
35
36 -- | A list of all directions, sans the interior and composite types.
37 all_directions :: [Cardinal]
38 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
39 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
40 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
41
42
43 -- | If we rotate a direction (other than front or back)
44 -- counter-clockwise with respect to the x-axis, we should get a new
45 -- direction.
46 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
47 prop_ccwx_rotation_changes_direction c =
48 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
49 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
50 ==> ccwx c /= c
51
52 -- | If we rotate a direction (other than front or back) clockwise
53 -- with respect to the x-axis, we should get a new direction.
54 prop_cwx_rotation_changes_direction :: Cardinal -> Property
55 prop_cwx_rotation_changes_direction c =
56 -- The front and back faces are unchanged by x-rotation.
57 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
58 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
59 ==> cwx c /= c
60
61 -- | If we rotate a direction (other than left or right)
62 -- counter-clockwise with respect to the y-axis, we should get a new
63 -- direction.
64 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
65 prop_ccwy_rotation_changes_direction c =
66 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
67 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
68 ==> ccwy c /= c
69
70
71 -- | If we rotate a direction (other than left or right) clockwise
72 -- with respect to the y-axis, we should get a new direction.
73 prop_cwy_rotation_changes_direction :: Cardinal -> Property
74 prop_cwy_rotation_changes_direction c =
75 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
76 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
77 ==> cwy c /= c
78
79
80 -- | If we rotate a direction (other than top or down)
81 -- counter-clockwise with respect to the z-axis, we should get a new
82 -- direction.
83 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
84 prop_ccwz_rotation_changes_direction c =
85 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
86 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
87 ==> ccwz c /= c
88
89
90 -- | If we rotate a direction (other than top or down) clockwise with
91 -- respect to the z-axis, we should get a new direction.
92 prop_cwz_rotation_changes_direction :: Cardinal -> Property
93 prop_cwz_rotation_changes_direction c =
94 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
95 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
96 ==> cwz c /= c
97
98
99 -- | If we are given a direction c, there should only be one direction
100 -- d which, when rotated counter-clockwise with respect to the
101 -- x-axis, produces c.
102 prop_ccwx_rotation_result_unique :: Cardinal -> Property
103 prop_ccwx_rotation_result_unique c =
104 c `elem` all_directions ==>
105 (length [ d | d <- all_directions, ccwx d == c ]) == 1
106
107 -- | If we are given a direction c, there should only be one direction
108 -- d which, when rotated clockwise with respect to the x-axis,
109 -- produces c.
110 prop_cwx_rotation_result_unique :: Cardinal -> Property
111 prop_cwx_rotation_result_unique c =
112 c `elem` all_directions ==>
113 (length [ d | d <- all_directions, cwx d == c ]) == 1
114
115
116 -- | If we are given a direction c, there should only be one direction
117 -- d which, when rotated counter-clockwise with respect to the
118 -- y-axis, produces c.
119 prop_ccwy_rotation_result_unique :: Cardinal -> Property
120 prop_ccwy_rotation_result_unique c =
121 c `elem` all_directions ==>
122 (length [ d | d <- all_directions, ccwy d == c ]) == 1
123
124
125 -- | If we are given a direction c, there should only be one direction
126 -- d which, when rotated clockwise with respect to the y-axis,
127 -- produces c.
128 prop_cwy_rotation_result_unique :: Cardinal -> Property
129 prop_cwy_rotation_result_unique c =
130 c `elem` all_directions ==>
131 (length [ d | d <- all_directions, cwy d == c ]) == 1
132
133
134 -- | If we are given a direction c, there should only be one direction
135 -- d which, when rotated counter-clockwise with respect to the
136 -- z-axis, produces c.
137 prop_ccwz_rotation_result_unique :: Cardinal -> Property
138 prop_ccwz_rotation_result_unique c =
139 c `elem` all_directions ==>
140 (length [ d | d <- all_directions, ccwz d == c ]) == 1
141
142
143 -- | If we are given a direction c, there should only be one direction
144 -- d which, when rotated clockwise with respect to the z-axis,
145 -- produces c.
146 prop_cwz_rotation_result_unique :: Cardinal -> Property
147 prop_cwz_rotation_result_unique c =
148 c `elem` all_directions ==>
149 (length [ d | d <- all_directions, cwz d == c ]) == 1
150
151
152 -- | If you rotate a cardinal direction four times in the clockwise
153 -- (with respect to x) direction, you should wind up with the same
154 -- direction.
155 prop_four_cwx_is_identity :: Cardinal -> Bool
156 prop_four_cwx_is_identity c =
157 (cwx . cwx . cwx . cwx) c == c
158
159 -- | If you rotate a cardinal direction four times in the
160 -- counter-clockwise (with respect to x) direction, you should wind up
161 -- with the same direction.
162 prop_four_ccwx_is_identity :: Cardinal -> Bool
163 prop_four_ccwx_is_identity c =
164 (ccwx . ccwx . ccwx . ccwx) c == c
165
166 -- | If you rotate a cardinal direction four times in the clockwise
167 -- (with respect to y) direction, you should wind up with the same
168 -- direction.
169 prop_four_cwy_is_identity :: Cardinal -> Bool
170 prop_four_cwy_is_identity c =
171 (cwy . cwy . cwy . cwy) c == c
172
173 -- | If you rotate a cardinal direction four times in the counter-clockwise
174 -- (with respect to y) direction, you should wind up with the same
175 -- direction.
176 prop_four_ccwy_is_identity :: Cardinal -> Bool
177 prop_four_ccwy_is_identity c =
178 (ccwy . ccwy . ccwy . ccwy) c == c
179
180 -- | If you rotate a cardinal direction four times in the clockwise
181 -- (with respect to z) direction, you should wind up with the same
182 -- direction.
183 prop_four_cwz_is_identity :: Cardinal -> Bool
184 prop_four_cwz_is_identity c =
185 (cwz . cwz . cwz . cwz) c == c
186
187 -- | If you rotate a cardinal direction four times in the
188 -- counter-clockwise (with respect to z) direction, you should wind up
189 -- with the same direction.
190 prop_four_ccwz_is_identity :: Cardinal -> Bool
191 prop_four_ccwz_is_identity c =
192 (ccwz . ccwz . ccwz . ccwz) c == c