]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
0d8d592e7d37a75c233547421c404fa03a53d380
[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.QuickCheck
7
8 import Cardinal
9
10
11
12 instance Arbitrary Cardinal where
13 arbitrary = oneof [f,b,l,r,d,t,fl,fr,fd,ft,bl,br,bd,bt,ld,lt,
14 rd,rt,fld,flt,frd,frt,bld,blt,brd,brt,i,
15 scalar,csum,cdiff,cprod,cquot]
16 where
17 f = return F
18 b = return B
19 l = return L
20 r = return R
21 d = return D
22 t = return T
23 fl = return FL
24 fr = return FR
25 fd = return FD
26 ft = return FT
27 bl = return BL
28 br = return BR
29 bd = return BD
30 bt = return BT
31 ld = return LD
32 lt = return LT
33 rd = return RD
34 rt = return RT
35 fld = return FLD
36 flt = return FLT
37 frd = return FRD
38 frt = return FRT
39 bld = return BLD
40 blt = return BLT
41 brd = return BRD
42 brt = return BRT
43 i = return I
44 scalar = liftM Scalar arbitrary
45 csum = liftM2 Sum arbitrary arbitrary
46 cdiff = liftM2 Difference arbitrary arbitrary
47 cprod = liftM2 Product arbitrary arbitrary
48 cquot = liftM2 Quotient arbitrary arbitrary
49
50
51 -- | A list of all directions, sans the interior and composite types.
52 all_directions :: [Cardinal]
53 all_directions = [L, R, F, B, D, T, FL, FR, FD, FT,
54 BL, BR, BD, BT, LD, LT, RD, RT, FLD,
55 FLT, FRD, FRT, BLD, BLT, BRD, BRT]
56
57
58 -- | If we rotate a direction (other than front or back)
59 -- counter-clockwise with respect to the x-axis, we should get a new
60 -- direction.
61 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
62 prop_ccwx_rotation_changes_direction c =
63 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
64 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
65 ==> ccwx c /= c
66
67 -- | If we rotate a direction (other than front or back) clockwise
68 -- with respect to the x-axis, we should get a new direction.
69 prop_cwx_rotation_changes_direction :: Cardinal -> Property
70 prop_cwx_rotation_changes_direction c =
71 -- The front and back faces are unchanged by x-rotation.
72 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
73 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
74 ==> cwx c /= c
75
76 -- | If we rotate a direction (other than left or right)
77 -- counter-clockwise with respect to the y-axis, we should get a new
78 -- direction.
79 prop_ccwy_rotation_changes_direction :: Cardinal -> Property
80 prop_ccwy_rotation_changes_direction c =
81 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
82 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
83 ==> ccwy c /= c
84
85
86 -- | If we rotate a direction (other than left or right) clockwise
87 -- with respect to the y-axis, we should get a new direction.
88 prop_cwy_rotation_changes_direction :: Cardinal -> Property
89 prop_cwy_rotation_changes_direction c =
90 c `elem` [F, B, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
91 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
92 ==> cwy c /= c
93
94
95 -- | If we rotate a direction (other than top or down)
96 -- counter-clockwise with respect to the z-axis, we should get a new
97 -- direction.
98 prop_ccwz_rotation_changes_direction :: Cardinal -> Property
99 prop_ccwz_rotation_changes_direction c =
100 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
101 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
102 ==> ccwz c /= c
103
104
105 -- | If we rotate a direction (other than top or down) clockwise with
106 -- respect to the z-axis, we should get a new direction.
107 prop_cwz_rotation_changes_direction :: Cardinal -> Property
108 prop_cwz_rotation_changes_direction c =
109 c `elem` [L, R, F, B, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
110 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
111 ==> cwz c /= c
112
113
114 -- | If we are given a direction c, there should only be one direction
115 -- d which, when rotated counter-clockwise with respect to the
116 -- x-axis, produces c.
117 prop_ccwx_rotation_result_unique :: Cardinal -> Property
118 prop_ccwx_rotation_result_unique c =
119 c `elem` all_directions ==>
120 (length [ d | d <- all_directions, ccwx d == c ]) == 1
121
122 -- | If we are given a direction c, there should only be one direction
123 -- d which, when rotated clockwise with respect to the x-axis,
124 -- produces c.
125 prop_cwx_rotation_result_unique :: Cardinal -> Property
126 prop_cwx_rotation_result_unique c =
127 c `elem` all_directions ==>
128 (length [ d | d <- all_directions, cwx d == c ]) == 1
129
130
131 -- | If we are given a direction c, there should only be one direction
132 -- d which, when rotated counter-clockwise with respect to the
133 -- y-axis, produces c.
134 prop_ccwy_rotation_result_unique :: Cardinal -> Property
135 prop_ccwy_rotation_result_unique c =
136 c `elem` all_directions ==>
137 (length [ d | d <- all_directions, ccwy d == c ]) == 1
138
139
140 -- | If we are given a direction c, there should only be one direction
141 -- d which, when rotated clockwise with respect to the y-axis,
142 -- produces c.
143 prop_cwy_rotation_result_unique :: Cardinal -> Property
144 prop_cwy_rotation_result_unique c =
145 c `elem` all_directions ==>
146 (length [ d | d <- all_directions, cwy d == c ]) == 1
147
148
149 -- | If we are given a direction c, there should only be one direction
150 -- d which, when rotated counter-clockwise with respect to the
151 -- z-axis, produces c.
152 prop_ccwz_rotation_result_unique :: Cardinal -> Property
153 prop_ccwz_rotation_result_unique c =
154 c `elem` all_directions ==>
155 (length [ d | d <- all_directions, ccwz d == c ]) == 1
156
157
158 -- | If we are given a direction c, there should only be one direction
159 -- d which, when rotated clockwise with respect to the z-axis,
160 -- produces c.
161 prop_cwz_rotation_result_unique :: Cardinal -> Property
162 prop_cwz_rotation_result_unique c =
163 c `elem` all_directions ==>
164 (length [ d | d <- all_directions, cwz d == c ]) == 1
165
166
167 -- | If you rotate a cardinal direction four times in the clockwise
168 -- (with respect to x) direction, you should wind up with the same
169 -- direction.
170 prop_four_cwx_is_identity :: Cardinal -> Bool
171 prop_four_cwx_is_identity c =
172 (cwx . cwx . cwx . cwx) c == c
173
174 -- | If you rotate a cardinal direction four times in the
175 -- counter-clockwise (with respect to x) direction, you should wind up
176 -- with the same direction.
177 prop_four_ccwx_is_identity :: Cardinal -> Bool
178 prop_four_ccwx_is_identity c =
179 (ccwx . ccwx . ccwx . ccwx) c == c
180
181 -- | If you rotate a cardinal direction four times in the clockwise
182 -- (with respect to y) direction, you should wind up with the same
183 -- direction.
184 prop_four_cwy_is_identity :: Cardinal -> Bool
185 prop_four_cwy_is_identity c =
186 (cwy . cwy . cwy . cwy) c == c
187
188 -- | If you rotate a cardinal direction four times in the counter-clockwise
189 -- (with respect to y) direction, you should wind up with the same
190 -- direction.
191 prop_four_ccwy_is_identity :: Cardinal -> Bool
192 prop_four_ccwy_is_identity c =
193 (ccwy . ccwy . ccwy . ccwy) c == c
194
195 -- | If you rotate a cardinal direction four times in the clockwise
196 -- (with respect to z) direction, you should wind up with the same
197 -- direction.
198 prop_four_cwz_is_identity :: Cardinal -> Bool
199 prop_four_cwz_is_identity c =
200 (cwz . cwz . cwz . cwz) c == c
201
202 -- | If you rotate a cardinal direction four times in the
203 -- counter-clockwise (with respect to z) direction, you should wind up
204 -- with the same direction.
205 prop_four_ccwz_is_identity :: Cardinal -> Bool
206 prop_four_ccwz_is_identity c =
207 (ccwz . ccwz . ccwz . ccwz) c == c