]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Grid.hs
6fdbb133a6ee70a4b6a6259493b58aee2d8ab939
[spline3.git] / src / Tests / Grid.hs
1 module Tests.Grid
2 where
3
4 import Data.Maybe (fromJust)
5 import Test.HUnit
6 import Test.QuickCheck
7
8 import Assertions
9 import Cube
10 import Grid
11 import Tetrahedron
12
13
14 instance Arbitrary Grid where
15 arbitrary = do
16 (Positive h') <- arbitrary :: Gen (Positive Double)
17 fvs <- arbitrary :: Gen [[[Double]]]
18 return (make_grid h' fvs)
19
20
21 -- | Values of the function f(x,y,z) = 1 + x + xy + xyz taken at nine
22 -- points (hi, hj, jk) with h = 1. From example one in the paper.
23 -- Used in the next bunch of tests.
24 trilinear :: [[[Double]]]
25 trilinear = [ [ [ 1, 2, 3 ],
26 [ 1, 3, 5 ],
27 [ 1, 4, 7 ] ],
28 [ [ 1, 2, 3 ],
29 [ 1, 4, 7 ],
30 [ 1, 6, 11 ] ],
31 [ [ 1, 2, 3 ],
32 [ 1, 5, 9 ],
33 [ 1, 8, 15 ]]]
34
35 -- | Check the value of c0030 for tetrahedron0 belonging to the
36 -- cube centered on (1,1,1) with a grid constructed from the
37 -- trilinear values. See example one in the paper.
38 test_trilinear_c0030 :: Test
39 test_trilinear_c0030 =
40 TestCase $ assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
41 where
42 g = make_grid 1 trilinear
43 cube = fromJust $ cube_at g 1 1 1
44 t = tetrahedron0 cube
45
46
47 -- | Check the value of c0003 for tetrahedron0 belonging to the
48 -- cube centered on (1,1,1) with a grid constructed from the
49 -- trilinear values. See example one in the paper.
50 test_trilinear_c0003 :: Test
51 test_trilinear_c0003 =
52 TestCase $ assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
53 where
54 g = make_grid 1 trilinear
55 cube = fromJust $ cube_at g 1 1 1
56 t = tetrahedron0 cube
57
58
59 -- | Check the value of c0021 for tetrahedron0 belonging to the
60 -- cube centered on (1,1,1) with a grid constructed from the
61 -- trilinear values. See example one in the paper.
62 test_trilinear_c0021 :: Test
63 test_trilinear_c0021 =
64 TestCase $ assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
65 where
66 g = make_grid 1 trilinear
67 cube = fromJust $ cube_at g 1 1 1
68 t = tetrahedron0 cube
69
70
71 -- | Check the value of c0012 for tetrahedron0 belonging to the
72 -- cube centered on (1,1,1) with a grid constructed from the
73 -- trilinear values. See example one in the paper.
74 test_trilinear_c0012 :: Test
75 test_trilinear_c0012 =
76 TestCase $ assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
77 where
78 g = make_grid 1 trilinear
79 cube = fromJust $ cube_at g 1 1 1
80 t = tetrahedron0 cube
81
82
83 -- | Check the value of c0120 for tetrahedron0 belonging to the
84 -- cube centered on (1,1,1) with a grid constructed from the
85 -- trilinear values. See example one in the paper.
86 test_trilinear_c0120 :: Test
87 test_trilinear_c0120 =
88 TestCase $ assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
89 where
90 g = make_grid 1 trilinear
91 cube = fromJust $ cube_at g 1 1 1
92 t = tetrahedron0 cube
93
94
95 -- | Check the value of c0102 for tetrahedron0 belonging to the
96 -- cube centered on (1,1,1) with a grid constructed from the
97 -- trilinear values. See example one in the paper.
98 test_trilinear_c0102 :: Test
99 test_trilinear_c0102 =
100 TestCase $ assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
101 where
102 g = make_grid 1 trilinear
103 cube = fromJust $ cube_at g 1 1 1
104 t = tetrahedron0 cube
105
106
107 -- | Check the value of c0111 for tetrahedron0 belonging to the
108 -- cube centered on (1,1,1) with a grid constructed from the
109 -- trilinear values. See example one in the paper.
110 test_trilinear_c0111 :: Test
111 test_trilinear_c0111 =
112 TestCase $ assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
113 where
114 g = make_grid 1 trilinear
115 cube = fromJust $ cube_at g 1 1 1
116 t = tetrahedron0 cube
117
118
119 -- | Check the value of c0210 for tetrahedron0 belonging to the
120 -- cube centered on (1,1,1) with a grid constructed from the
121 -- trilinear values. See example one in the paper.
122 test_trilinear_c0210 :: Test
123 test_trilinear_c0210 =
124 TestCase $ assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
125 where
126 g = make_grid 1 trilinear
127 cube = fromJust $ cube_at g 1 1 1
128 t = tetrahedron0 cube
129
130
131 -- | Check the value of c0201 for tetrahedron0 belonging to the
132 -- cube centered on (1,1,1) with a grid constructed from the
133 -- trilinear values. See example one in the paper.
134 test_trilinear_c0201 :: Test
135 test_trilinear_c0201 =
136 TestCase $ assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
137 where
138 g = make_grid 1 trilinear
139 cube = fromJust $ cube_at g 1 1 1
140 t = tetrahedron0 cube
141
142
143 -- | Check the value of c0300 for tetrahedron0 belonging to the
144 -- cube centered on (1,1,1) with a grid constructed from the
145 -- trilinear values. See example one in the paper.
146 test_trilinear_c0300 :: Test
147 test_trilinear_c0300 =
148 TestCase $ assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
149 where
150 g = make_grid 1 trilinear
151 cube = fromJust $ cube_at g 1 1 1
152 t = tetrahedron0 cube
153
154
155 -- | Check the value of c1020 for tetrahedron0 belonging to the
156 -- cube centered on (1,1,1) with a grid constructed from the
157 -- trilinear values. See example one in the paper.
158 test_trilinear_c1020 :: Test
159 test_trilinear_c1020 =
160 TestCase $ assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
161 where
162 g = make_grid 1 trilinear
163 cube = fromJust $ cube_at g 1 1 1
164 t = tetrahedron0 cube
165
166
167 -- | Check the value of c1002 for tetrahedron0 belonging to the
168 -- cube centered on (1,1,1) with a grid constructed from the
169 -- trilinear values. See example one in the paper.
170 test_trilinear_c1002 :: Test
171 test_trilinear_c1002 =
172 TestCase $ assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
173 where
174 g = make_grid 1 trilinear
175 cube = fromJust $ cube_at g 1 1 1
176 t = tetrahedron0 cube
177
178
179 -- | Check the value of c1011 for tetrahedron0 belonging to the
180 -- cube centered on (1,1,1) with a grid constructed from the
181 -- trilinear values. See example one in the paper.
182 test_trilinear_c1011 :: Test
183 test_trilinear_c1011 =
184 TestCase $ assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
185 where
186 g = make_grid 1 trilinear
187 cube = fromJust $ cube_at g 1 1 1
188 t = tetrahedron0 cube
189
190
191 -- | Check the value of c1110 for tetrahedron0 belonging to the
192 -- cube centered on (1,1,1) with a grid constructed from the
193 -- trilinear values. See example one in the paper.
194 test_trilinear_c1110 :: Test
195 test_trilinear_c1110 =
196 TestCase $ assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
197 where
198 g = make_grid 1 trilinear
199 cube = fromJust $ cube_at g 1 1 1
200 t = tetrahedron0 cube
201
202
203 -- | Check the value of c1101 for tetrahedron0 belonging to the
204 -- cube centered on (1,1,1) with a grid constructed from the
205 -- trilinear values. See example one in the paper.
206 test_trilinear_c1101 :: Test
207 test_trilinear_c1101 =
208 TestCase $ assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
209 where
210 g = make_grid 1 trilinear
211 cube = fromJust $ cube_at g 1 1 1
212 t = tetrahedron0 cube
213
214
215 -- | Check the value of c1200 for tetrahedron0 belonging to the
216 -- cube centered on (1,1,1) with a grid constructed from the
217 -- trilinear values. See example one in the paper.
218 test_trilinear_c1200 :: Test
219 test_trilinear_c1200 =
220 TestCase $ assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
221 where
222 g = make_grid 1 trilinear
223 cube = fromJust $ cube_at g 1 1 1
224 t = tetrahedron0 cube
225
226
227 -- | Check the value of c2010 for tetrahedron0 belonging to the
228 -- cube centered on (1,1,1) with a grid constructed from the
229 -- trilinear values. See example one in the paper.
230 test_trilinear_c2010 :: Test
231 test_trilinear_c2010 =
232 TestCase $ assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
233 where
234 g = make_grid 1 trilinear
235 cube = fromJust $ cube_at g 1 1 1
236 t = tetrahedron0 cube
237
238
239 -- | Check the value of c2001 for tetrahedron0 belonging to the
240 -- cube centered on (1,1,1) with a grid constructed from the
241 -- trilinear values. See example one in the paper.
242 test_trilinear_c2001 :: Test
243 test_trilinear_c2001 =
244 TestCase $ assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
245 where
246 g = make_grid 1 trilinear
247 cube = fromJust $ cube_at g 1 1 1
248 t = tetrahedron0 cube
249
250
251 -- | Check the value of c2100 for tetrahedron0 belonging to the
252 -- cube centered on (1,1,1) with a grid constructed from the
253 -- trilinear values. See example one in the paper.
254 test_trilinear_c2100 :: Test
255 test_trilinear_c2100 =
256 TestCase $ assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
257 where
258 g = make_grid 1 trilinear
259 cube = fromJust $ cube_at g 1 1 1
260 t = tetrahedron0 cube
261
262
263 -- | Check the value of c3000 for tetrahedron0 belonging to the
264 -- cube centered on (1,1,1) with a grid constructed from the
265 -- trilinear values. See example one in the paper.
266 test_trilinear_c3000 :: Test
267 test_trilinear_c3000 =
268 TestCase $ assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
269 where
270 g = make_grid 1 trilinear
271 cube = fromJust $ cube_at g 1 1 1
272 t = tetrahedron0 cube
273
274
275 -- | Make sure that v0 of tetrahedron0 belonging to the cube centered
276 -- on (1,1,1) with a grid constructed from the trilinear values
277 -- winds up in the right place. See example one in the paper.
278 test_trilinear_f0_t0_v0 :: Test
279 test_trilinear_f0_t0_v0 =
280 TestCase $ assertEqual "v0 is correct" (v0 t) (1, 1, 1)
281 where
282 g = make_grid 1 trilinear
283 cube = fromJust $ cube_at g 1 1 1
284 t = tetrahedron0 cube
285
286
287 -- | Make sure that v1 of tetrahedron0 belonging to the cube centered
288 -- on (1,1,1) with a grid constructed from the trilinear values
289 -- winds up in the right place. See example one in the paper.
290 test_trilinear_f0_t0_v1 :: Test
291 test_trilinear_f0_t0_v1 =
292 TestCase $ assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
293 where
294 g = make_grid 1 trilinear
295 cube = fromJust $ cube_at g 1 1 1
296 t = tetrahedron0 cube
297
298
299 -- | Make sure that v2 of tetrahedron0 belonging to the cube centered
300 -- on (1,1,1) with a grid constructed from the trilinear values
301 -- winds up in the right place. See example one in the paper.
302 test_trilinear_f0_t0_v2 :: Test
303 test_trilinear_f0_t0_v2 =
304 TestCase $ assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
305 where
306 g = make_grid 1 trilinear
307 cube = fromJust $ cube_at g 1 1 1
308 t = tetrahedron0 cube
309
310
311 -- | Make sure that v3 of tetrahedron0 belonging to the cube centered
312 -- on (1,1,1) with a grid constructed from the trilinear values
313 -- winds up in the right place. See example one in the paper.
314 test_trilinear_f0_t0_v3 :: Test
315 test_trilinear_f0_t0_v3 =
316 TestCase $ assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
317 where
318 g = make_grid 1 trilinear
319 cube = fromJust $ cube_at g 1 1 1
320 t = tetrahedron0 cube
321
322
323 -- | A list of all HUnit tests defined in this module.
324 grid_tests :: [Test]
325 grid_tests =
326 [test_trilinear_c0030,
327 test_trilinear_c0003,
328 test_trilinear_c0021,
329 test_trilinear_c0012,
330 test_trilinear_c0120,
331 test_trilinear_c0102,
332 test_trilinear_c0111,
333 test_trilinear_c0210,
334 test_trilinear_c0201,
335 test_trilinear_c0300,
336 test_trilinear_c1020,
337 test_trilinear_c1002,
338 test_trilinear_c1011,
339 test_trilinear_c1110,
340 test_trilinear_c1101,
341 test_trilinear_c1200,
342 test_trilinear_c2010,
343 test_trilinear_c2001,
344 test_trilinear_c2100,
345 test_trilinear_c3000,
346 test_trilinear_f0_t0_v0,
347 test_trilinear_f0_t0_v1,
348 test_trilinear_f0_t0_v2,
349 test_trilinear_f0_t0_v3]