Skip to content
Snippets Groups Projects
Commit 453ee258 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

TEST: test the limit cases

parent c08a077b
Branches
Tags
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cmath>
#include "otb/HermiteInterpolator.h" #include "otb/HermiteInterpolator.h"
int ossimpluginsHermiteInterpolationTest(int argc, char * argv[]) int ossimpluginsHermiteInterpolationTest(int argc, char * argv[])
{ {
double epsilon = 0.0000001;
double xref[11]; double xref[11];
xref[0] = 56640.0; xref[0] = 56640.0;
xref[1] = 56700.0; xref[1] = 56700.0;
...@@ -54,13 +74,39 @@ int ossimpluginsHermiteInterpolationTest(int argc, char * argv[]) ...@@ -54,13 +74,39 @@ int ossimpluginsHermiteInterpolationTest(int argc, char * argv[])
std::cout << " *** Test y and dy ***" << std::endl; std::cout << " *** Test y and dy ***" << std::endl;
ossimplugins::HermiteInterpolator* interp = new ossimplugins::HermiteInterpolator(11, xref, yref, dyref); ossimplugins::HermiteInterpolator* interp = new ossimplugins::HermiteInterpolator(11, xref, yref, dyref);
double yExpected = -1154600.87561283;
double dyExpected = 1568.49913322402;
double y = 0; double y = 0;
double dy = 0; double dy = 0;
interp->Interpolate(x, y, dy); interp->Interpolate(x, y, dy);
std::cout << std::setprecision(15) << "Value at " << x << " : " << y << " (derivative " << dy << ")\n"; std::cout << std::setprecision(15) << "Value at " << x << " : " << y << " (derivative " << dy << ")\n";
std::cout << "- Should be : -1154600.87561283 (derivative 1568.49913322402)" << std::endl; std::cout << "- Should be : " << yExpected << " (derivative " << dyExpected << ")" << std::endl;
if ( std::isnan(y) || ( (y - yExpected)/yExpected > epsilon)) return EXIT_FAILURE;
if ( std::isnan(dy) || ( (dy - dyExpected)/dyExpected > epsilon)) return EXIT_FAILURE;
//Test limit situation
x = 56640.0;
yExpected = -1556122.3685;
dyExpected = 1042.82980;
interp->Interpolate(x, y, dy);
std::cout << std::setprecision(15) << "Value at " << x << " : " << y << " (derivative " << dy << ")\n";
std::cout << "- Should be : " << yExpected << " (derivative " << dyExpected << ")" << std::endl;
if ( std::isnan(y) || ( (y - yExpected)/yExpected > epsilon)) return EXIT_FAILURE;
if ( std::isnan(dy) || ( (dy - dyExpected)/dyExpected > epsilon)) return EXIT_FAILURE;
x = 56700.0;
yExpected = -1489827.1436;
dyExpected = 1165.61122;
interp->Interpolate(x, y, dy);
std::cout << std::setprecision(15) << "Value at " << x << " : " << y << " (derivative " << dy << ")\n";
std::cout << "- Should be : " << yExpected << " (derivative " << dyExpected << ")" << std::endl;
if ( std::isnan(y) || ( (y - yExpected)/yExpected > epsilon)) return EXIT_FAILURE;
if ( std::isnan(dy) || ( (dy - dyExpected)/dyExpected > epsilon)) return EXIT_FAILURE;
//Performance test //Performance test
int nTest = 1000000; int nTest = 1000000;
...@@ -87,7 +133,6 @@ int ossimpluginsHermiteInterpolationTest(int argc, char * argv[]) ...@@ -87,7 +133,6 @@ int ossimpluginsHermiteInterpolationTest(int argc, char * argv[])
std::cout << std::setprecision(15) << "Value at " << x << " : " << y2 << "\n"; std::cout << std::setprecision(15) << "Value at " << x << " : " << y2 << "\n";
std::cout << "- Should be : -1154600.87561283" << std::endl; std::cout << "- Should be : -1154600.87561283" << std::endl;
//Performance test //Performance test
clock_gettime(CLOCK_REALTIME, &startClock); clock_gettime(CLOCK_REALTIME, &startClock);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment