Revision 2167

trunk/tests/gtests/Makefile (revision 2167)
25 25
 test_df_file.cpp\
26 26
 test_param_init_bounded_number_vector.cpp\
27 27
 test_param_init_d3array.cpp\
28
 test_spline.cpp\
28 29
 main.cpp
29 30

  
30 31
##Need to debug this
trunk/tests/gtests/test_spline.cpp (revision 2167)
1
#include <gtest/gtest.h>
2
#include <admodel.h>
3

  
4
class interpret_spline
5
{
6
 /* class to make a function to do a smooth transition
7
    from the value a to the value b centered at c and having width e.
8
    The derivatives at each end point are 0.
9
 */
10
  dvector coffs;
11
  double a;
12
  double b;
13
  double c;
14
  double e;
15
public:
16
  interpret_spline(double a,double b,double c,double e);
17
  double operator()(double x);
18
};
19

  
20
interpret_spline::interpret_spline(double _a,double _b,double _c,double _e)
21
{
22
  a=_a;
23
  b=_b;
24
  c=_c;
25
  e=_e;
26

  
27
  double e_1=-e; double e_2=e;
28
  dmatrix A(1,4,1,4);
29
  A(1,1)=1; A(1,2)=e_1; A(1,3)=e_1*e_1; A(1,4)=e_1*e_1*e_1; 
30
  A(2,1)=0; A(2,2)=1;   A(2,3)=2.0*e_1; A(2,4)=3.0*e_1*e_1; 
31
  A(3,1)=1; A(3,2)=e_2; A(3,3)=e_2*e_2; A(3,4)=e_2*e_2*e_2; 
32
  A(4,1)=0; A(4,2)=1;   A(4,3)=2.0*e_2; A(4,4)=3.0*e_2*e_2; 
33

  
34
  dvector v(1,4);
35
  v(1)=a; v(2)=0.0; v(3)=b; v(4)=0.0;
36
  coffs=solve(A,v);
37
}
38

  
39
double interpret_spline::operator()(double x)
40
{
41
  double y=x-c; 
42
  if (y<-e)
43
  {
44
    return a;
45
  }
46
  else if (y>e)
47
  {
48
    return b;
49
  }
50
  else
51
  {
52
    return  ((coffs(4)*y+coffs(3))*y+coffs(2))*y+coffs(1);
53
  }
54
}
55

  
56
class test_spline: public ::testing::Test {};
57

  
58
TEST_F(test_spline, main)
59
{
60
  double a=2.0;
61
  double b=4.0;
62
  double c=3.5;
63
  double e=0.25;
64

  
65
  interpret_spline sp(a,b,c,e);
66

  
67
  for (double x=c-1.0;x<=c+1.0;x+=.01)
68
  {
69
    cout << x << " " << sp(x) << endl;
70
  }
71
}

Also available in: Unified diff