]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cardinal.hs
907e3d9968ad8fbb838c922f24a6bccd201fe76f
[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 prop_ccwx_rotation_changes_direction :: Cardinal -> Property
52 prop_ccwx_rotation_changes_direction c =
53 -- The front and back faces are unchanged by x-rotation.
54 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
55 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
56 ==> ccwx c /= c
57
58 prop_cwx_rotation_changes_direction :: Cardinal -> Property
59 prop_cwx_rotation_changes_direction c =
60 -- The front and back faces are unchanged by x-rotation.
61 c `elem` [L, R, D, T, FL, FR, FD, FT, BL, BR, BD, BT, LD, LT,
62 RD, RT, FLD, FLT, FRD, FRT, BLD, BLT, BRD, BRT]
63 ==> cwx c /= c
64
65 -- | If you rotate a cardinal direction four times in the clockwise
66 -- (with respect to x) direction, you should wind up with the same
67 -- direction.
68 prop_four_cwx_is_identity :: Cardinal -> Bool
69 prop_four_cwx_is_identity c =
70 (cwx . cwx . cwx . cwx) c == c
71
72 -- | If you rotate a cardinal direction four times in the
73 -- counter-clockwise (with respect to x) direction, you should wind up
74 -- with the same direction.
75 prop_four_ccwx_is_identity :: Cardinal -> Bool
76 prop_four_ccwx_is_identity c =
77 (ccwx . ccwx . ccwx . ccwx) c == c
78
79 -- | If you rotate a cardinal direction four times in the clockwise
80 -- (with respect to y) direction, you should wind up with the same
81 -- direction.
82 prop_four_cwy_is_identity :: Cardinal -> Bool
83 prop_four_cwy_is_identity c =
84 (cwy . cwy . cwy . cwy) c == c
85
86 -- | If you rotate a cardinal direction four times in the counter-clockwise
87 -- (with respect to y) direction, you should wind up with the same
88 -- direction.
89 prop_four_ccwy_is_identity :: Cardinal -> Bool
90 prop_four_ccwy_is_identity c =
91 (ccwy . ccwy . ccwy . ccwy) c == c
92
93 -- | If you rotate a cardinal direction four times in the clockwise
94 -- (with respect to z) direction, you should wind up with the same
95 -- direction.
96 prop_four_cwz_is_identity :: Cardinal -> Bool
97 prop_four_cwz_is_identity c =
98 (cwz . cwz . cwz . cwz) c == c
99
100 -- | If you rotate a cardinal direction four times in the
101 -- counter-clockwise (with respect to z) direction, you should wind up
102 -- with the same direction.
103 prop_four_ccwz_is_identity :: Cardinal -> Bool
104 prop_four_ccwz_is_identity c =
105 (ccwz . ccwz . ccwz . ccwz) c == c