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