1
2
3
4
5
6
7
8
9
10 package org.lcsim.math.interpolation;
11
12 import junit.framework.*;
13
14
15
16
17
18 public class BilinearInterpolatorTest extends TestCase
19 {
20
21
22
23
24 public void testInterpolateValueAt()
25 {
26 double[] a = {-2, -1, 0, 1, 2};
27 double[] b = {-2, -1, 0, 1, 2};
28 double[][] vals = new double[a.length][b.length];
29
30 for(int i=0; i<a.length; ++i)
31 {
32 for(int j =0; j<b.length; ++j)
33 {
34 vals[i][j] = a[i]*a[i]+b[j]*b[j];
35 }
36 }
37
38 BilinearInterpolator instance = new BilinearInterpolator(a, b, vals);
39
40 double x = 0.0;
41 double y = 0.0;
42
43 for(int i=0; i<a.length; ++i)
44 {
45 for(int j=0; j<b.length; ++j)
46 {
47
48
49 assertEquals(instance.interpolateValueAt(a[i],b[j]), vals[i][j]);
50 }
51 }
52
53 for(double i=a[0]; i<a[a.length-1]; i+=.2)
54 {
55 for(double j=b[0]; j<b[b.length-1]; j+=.2)
56 {
57 double pred = instance.interpolateValueAt(i,j);
58 double real = i*i+j*j;
59
60
61 assertEquals(real, pred ,.5);
62 }
63 }
64 }
65 }