]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Tetrahedron.hs
Move all of the trilinear coefficient tests into the Tests.Grid module.
[spline3.git] / src / Tests / Tetrahedron.hs
1 module Tests.Tetrahedron
2 where
3
4 import Test.HUnit
5 import Test.QuickCheck
6
7 import Assertions
8 import Comparisons
9 import Point
10 import FunctionValues
11 import Misc
12 import Tests.FunctionValues()
13 import Tetrahedron
14 import ThreeDimensional
15
16 instance Arbitrary Tetrahedron where
17 arbitrary = do
18 rnd_v0 <- arbitrary :: Gen Point
19 rnd_v1 <- arbitrary :: Gen Point
20 rnd_v2 <- arbitrary :: Gen Point
21 rnd_v3 <- arbitrary :: Gen Point
22 rnd_fv <- arbitrary :: Gen FunctionValues
23 return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3)
24
25 -- HUnit Tests
26
27 -- Since p0, p1, p2 are in clockwise order, we expect the volume here
28 -- to be negative.
29 test_volume1 :: Test
30 test_volume1 =
31 TestCase $ assertEqual "volume is correct" True (vol ~= (-1/3))
32 where
33 p0 = (0, -0.5, 0)
34 p1 = (0, 0.5, 0)
35 p2 = (2, 0, 0)
36 p3 = (1, 0, 1)
37 t = Tetrahedron { v0 = p0,
38 v1 = p1,
39 v2 = p2,
40 v3 = p3,
41 fv = empty_values }
42 vol = volume t
43
44
45 -- Now, p0, p1, and p2 are in counter-clockwise order. The volume
46 -- should therefore be positive.
47 test_volume2 :: Test
48 test_volume2 =
49 TestCase $ assertEqual "volume is correct" True (vol ~= (1/3))
50 where
51 p0 = (0, -0.5, 0)
52 p1 = (2, 0, 0)
53 p2 = (0, 0.5, 0)
54 p3 = (1, 0, 1)
55 t = Tetrahedron { v0 = p0,
56 v1 = p1,
57 v2 = p2,
58 v3 = p3,
59 fv = empty_values }
60 vol = volume t
61
62 test_contains_point1 :: Test
63 test_contains_point1 =
64 TestCase $ assertEqual "contains an inner point" True (contains_point t inner_point)
65 where
66 p0 = (0, -0.5, 0)
67 p1 = (0, 0.5, 0)
68 p2 = (2, 0, 0)
69 p3 = (1, 0, 1)
70 inner_point = (1, 0, 0.5)
71 t = Tetrahedron { v0 = p0,
72 v1 = p1,
73 v2 = p2,
74 v3 = p3,
75 fv = empty_values }
76
77
78 test_doesnt_contain_point1 :: Test
79 test_doesnt_contain_point1 =
80 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
81 where
82 p0 = (0, -0.5, 0)
83 p1 = (0, 0.5, 0)
84 p2 = (2, 0, 0)
85 p3 = (1, 0, 1)
86 exterior_point = (5, 2, -9.0212)
87 t = Tetrahedron { v0 = p0,
88 v1 = p1,
89 v2 = p2,
90 v3 = p3,
91 fv = empty_values }
92
93
94 test_doesnt_contain_point2 :: Test
95 test_doesnt_contain_point2 =
96 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
97 where
98 p0 = (0, 1, 1)
99 p1 = (1, 1, 1)
100 p2 = (0.5, 0.5, 1)
101 p3 = (0.5, 0.5, 0.5)
102 exterior_point = (0, 0, 0)
103 t = Tetrahedron { v0 = p0,
104 v1 = p1,
105 v2 = p2,
106 v3 = p3,
107 fv = empty_values }
108
109 test_doesnt_contain_point3 :: Test
110 test_doesnt_contain_point3 =
111 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
112 where
113 p0 = (1, 1, 1)
114 p1 = (1, 0, 1)
115 p2 = (0.5, 0.5, 1)
116 p3 = (0.5, 0.5, 0.5)
117 exterior_point = (0, 0, 0)
118 t = Tetrahedron { v0 = p0,
119 v1 = p1,
120 v2 = p2,
121 v3 = p3,
122 fv = empty_values }
123
124 test_doesnt_contain_point4 :: Test
125 test_doesnt_contain_point4 =
126 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
127 where
128 p0 = (1, 0, 1)
129 p1 = (0, 0, 1)
130 p2 = (0.5, 0.5, 1)
131 p3 = (0.5, 0.5, 0.5)
132 exterior_point = (0, 0, 0)
133 t = Tetrahedron { v0 = p0,
134 v1 = p1,
135 v2 = p2,
136 v3 = p3,
137 fv = empty_values }
138
139 test_doesnt_contain_point5 :: Test
140 test_doesnt_contain_point5 =
141 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
142 where
143 p0 = (0, 0, 1)
144 p1 = (0, 1, 1)
145 p2 = (0.5, 0.5, 1)
146 p3 = (0.5, 0.5, 0.5)
147 exterior_point = (0, 0, 0)
148 t = Tetrahedron { v0 = p0,
149 v1 = p1,
150 v2 = p2,
151 v3 = p3,
152 fv = empty_values }
153
154 tetrahedron_tests :: [Test]
155 tetrahedron_tests = [test_volume1,
156 test_volume2,
157 test_contains_point1,
158 test_doesnt_contain_point1,
159 test_doesnt_contain_point2,
160 test_doesnt_contain_point3,
161 test_doesnt_contain_point4,
162 test_doesnt_contain_point5 ]
163
164 prop_b0_v0_always_unity :: Tetrahedron -> Property
165 prop_b0_v0_always_unity t =
166 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
167
168 prop_b0_v1_always_zero :: Tetrahedron -> Property
169 prop_b0_v1_always_zero t =
170 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
171
172 prop_b0_v2_always_zero :: Tetrahedron -> Property
173 prop_b0_v2_always_zero t =
174 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
175
176 prop_b0_v3_always_zero :: Tetrahedron -> Property
177 prop_b0_v3_always_zero t =
178 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
179
180 prop_b1_v1_always_unity :: Tetrahedron -> Property
181 prop_b1_v1_always_unity t =
182 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
183
184 prop_b1_v0_always_zero :: Tetrahedron -> Property
185 prop_b1_v0_always_zero t =
186 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
187
188 prop_b1_v2_always_zero :: Tetrahedron -> Property
189 prop_b1_v2_always_zero t =
190 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
191
192 prop_b1_v3_always_zero :: Tetrahedron -> Property
193 prop_b1_v3_always_zero t =
194 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
195
196 prop_b2_v2_always_unity :: Tetrahedron -> Property
197 prop_b2_v2_always_unity t =
198 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
199
200 prop_b2_v0_always_zero :: Tetrahedron -> Property
201 prop_b2_v0_always_zero t =
202 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
203
204 prop_b2_v1_always_zero :: Tetrahedron -> Property
205 prop_b2_v1_always_zero t =
206 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
207
208 prop_b2_v3_always_zero :: Tetrahedron -> Property
209 prop_b2_v3_always_zero t =
210 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
211
212 prop_b3_v3_always_unity :: Tetrahedron -> Property
213 prop_b3_v3_always_unity t =
214 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
215
216 prop_b3_v0_always_zero :: Tetrahedron -> Property
217 prop_b3_v0_always_zero t =
218 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
219
220 prop_b3_v1_always_zero :: Tetrahedron -> Property
221 prop_b3_v1_always_zero t =
222 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
223
224 prop_b3_v2_always_zero :: Tetrahedron -> Property
225 prop_b3_v2_always_zero t =
226 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
227
228
229 -- Used for convenience in the next few tests.
230 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
231 p t i j k l = (polynomial t) (xi t i j k l)
232
233 -- | Given in Sorokina and Zeilfelder, p. 78.
234 prop_c3000_identity :: Tetrahedron -> Property
235 prop_c3000_identity t =
236 (volume t) > 0 ==>
237 c t 3 0 0 0 ~= p t 3 0 0 0
238
239 -- | Given in Sorokina and Zeilfelder, p. 78.
240 prop_c2100_identity :: Tetrahedron -> Property
241 prop_c2100_identity t =
242 (volume t) > 0 ==>
243 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
244 where
245 term1 = (1/3)*(p t 0 3 0 0)
246 term2 = (5/6)*(p t 3 0 0 0)
247 term3 = 3*(p t 2 1 0 0)
248 term4 = (3/2)*(p t 1 2 0 0)
249
250 -- | Given in Sorokina and Zeilfelder, p. 78.
251 prop_c1110_identity :: Tetrahedron -> Property
252 prop_c1110_identity t =
253 (volume t) > 0 ==>
254 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
255 where
256 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
257 term2 = (9/2)*(p t 1 1 1 0)
258 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
259 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))