4 #include <UnitTest++.h>
9 #define NUMVALS(a) sizeof(a)/sizeof((a)[0])
12 static double xvals1[] = {0.0,1.0},
14 xvals2[] = {0.0,1.0,2.0,3.0,4.0},
15 yvals2[] = {0.0,1.0,4.0,9.0,16.0},
16 xvals3[] = {0.0,1.0, 2.0,3.0,4.0,5.0,6.0},
17 yvals3[] = {0.0,1.0,-1.0,2.0,1.0,1.0,0.0};
18 struct MonoInterpFixture
22 MonoInterpFixture () :
23 m1(xvals1,yvals1,
NUMVALS(xvals1)),
24 m2(xvals2,yvals2,
NUMVALS(xvals2)),
25 m3(xvals3,yvals3,
NUMVALS(xvals3))
27 ~MonoInterpFixture () {}
29 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpLimits)
34 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpInterp)
40 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpExtrap)
45 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpQuad)
47 for (
unsigned int i=0; i<
NUMVALS(xvals2); ++i)
48 CHECK(
fp_equal(yvals2[i],m2(xvals2[i])) );
49 CHECK_CLOSE(1.5*1.5,m2(1.5),5e-2);
50 CHECK_CLOSE(1.1*1.1,m2(1.1),5e-2);
51 CHECK_CLOSE(1.9*1.9,m2(1.9),5e-2);
53 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpQuadExtrap)
55 CHECK(
fp_equal(yvals2[0],m2(-0.5)) );
58 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpJump)
60 for (
unsigned int i=0; i<
NUMVALS(xvals3); ++i)
61 CHECK(
fp_equal(yvals3[i],m3(xvals3[i])) );
63 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpJumpExtrap)
65 CHECK(
fp_equal(yvals3[0],m3(-0.5)) );
68 TEST_FIXTURE(MonoInterpFixture,TestMonoInterpJumpMonotonic)
70 const double eps=1e-5;
71 for (
unsigned int i=0; i<
NUMVALS(xvals3)-1; ++i)
73 CHECK((yvals3[i]-m3(xvals3[i]+eps))*(yvals3[i+1]-m3(xvals3[i]+eps))<=0);
74 CHECK((yvals3[i]-m3(xvals3[i+1]-eps))
75 *(yvals3[i+1]-m3(xvals3[i+1]-eps))<=0);
bool fp_equal(sys_float x, sys_float y, int n=3)