LCOV - code coverage report
Current view: top level - src/Numeric/Interpolator - Test.cpp (source / functions) Hit Total Coverage
Test: coverage_merged.info Lines: 27 27 100.0 %
Date: 2024-11-18 05:28:54 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "Test.H"
       2             : #include "Linear.H"
       3             : #include "Util/Util.H"
       4             : #include "Set/Set.H"
       5             : #include "Util/Color.H"
       6             : 
       7             : namespace Numeric
       8             : {
       9             : namespace Interpolator
      10             : {
      11             : 
      12             : template<>
      13           2 : int Test<Linear<Set::Scalar> >::Match(int verbose)
      14             : {
      15             :     // Test function:
      16             :     //
      17             :     // y(x) = { -1           x  < -1
      18             :         //        { 2*x + 1      -1 < x  < 0
      19             :     //        { 1-x          0  < x  < 1
      20             :     //        { 0            1  < x
      21             : 
      22           4 :     std::vector<Set::Scalar> xs;
      23           4 :     std::vector<Set::Scalar> ys;
      24           2 :     xs.push_back(-1.0); ys.push_back(-1.0);
      25           2 :     xs.push_back(0.0);  ys.push_back(1.0);
      26           2 :     xs.push_back(1.0);  ys.push_back(0.0);
      27             : 
      28           6 :     Linear<Set::Scalar> interp(ys,xs);
      29             : 
      30           2 :     Set::Scalar normsq = 0.0;
      31           2 :     const Set::Scalar dx = 0.01;
      32         202 :     for (Set::Scalar x = -2.0; x < -1.0; x+=dx)
      33             :     {
      34         200 :         Set::Scalar exact = -1.0;
      35         200 :         normsq += pow((interp(x) - exact)/dx,2.0);
      36         200 :         if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
      37             :     }
      38         202 :     for (Set::Scalar x = -1.0; x < -0; x+=dx)
      39             :     {
      40         200 :         Set::Scalar exact = 2*x + 1;
      41         200 :         normsq += pow((interp(x) - exact)/dx,2.0);
      42         200 :         if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
      43             :     }
      44         202 :     for (Set::Scalar x = 0; x < 1.0; x+=dx)
      45             :     {
      46         200 :         Set::Scalar exact = 1.0 - x;
      47         200 :         normsq += pow((interp(x) - exact)/dx,2.0);
      48         200 :         if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
      49             :     }
      50         202 :     for (Set::Scalar x = 1.0; x < 2.0; x+=dx)
      51             :     {
      52         200 :         Set::Scalar exact = 0.0;
      53         200 :         normsq += pow((interp(x) - exact)/dx,2.0);
      54         200 :         if (verbose>0) Util::Message(INFO,(normsq>1E-8 ? Color::FG::Red : Color::Reset), "x = ", x , "\texact = ", exact, "\tinterp = ", interp(x), " normsq = ", normsq,Color::Reset);
      55             :     }
      56             : 
      57           2 :     if (normsq > 1E-8) return 1;
      58           2 :     else return 0;
      59             : }
      60             : }
      61             : }

Generated by: LCOV version 1.14