25 #ifndef WDATASETTIMESERIES_TEST_H
26 #define WDATASETTIMESERIES_TEST_H
34 #include <boost/shared_ptr.hpp>
36 #include <cxxtest/TestSuite.h>
38 #include "../../common/WLimits.h"
39 #include "../../common/WLogger.h"
41 #include "../WDataSetTimeSeries.h"
64 double data[] = { 1.0, 2.0, 3.0 };
94 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
101 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
103 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
104 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
113 boost::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
114 boost::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
115 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
121 double data[] = { 1.0, 2.0 };
137 t[ 1 ] = 0.0f / 0.0f;
151 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
158 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
160 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
161 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
170 boost::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
171 boost::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
172 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
178 double data[] = { 1.0 };
194 t[ 0 ] = -0.0f / 0.0f;
200 double data[] = { 1.0, 2.0, 3.0 };
205 std::swap( t[ 1 ], t[ 2 ] );
208 TS_ASSERT_EQUALS( d[ 0 ], ts.
m_dataSets[ 0 ].first );
209 TS_ASSERT_EQUALS( d[ 2 ], ts.
m_dataSets[ 1 ].first );
210 TS_ASSERT_EQUALS( d[ 1 ], ts.
m_dataSets[ 2 ].first );
219 double data[] = { 1.0, 2.0, 3.0 };
248 double data[] = { 1.0, 2.0, 3.0 };
260 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
277 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
291 double data[] = { 1.0, 2.0, 3.0 };
299 TS_ASSERT_EQUALS( 0.0, f );
301 TS_ASSERT_EQUALS( 0.0, f );
303 TS_ASSERT_EQUALS( 0.0, f );
305 TS_ASSERT_EQUALS( 0.0, f );
307 TS_ASSERT_EQUALS( 0.0, f );
309 TS_ASSERT_EQUALS( 0.0, f );
311 TS_ASSERT_EQUALS( 0.0, f );
313 TS_ASSERT_EQUALS( 0.0, f );
315 TS_ASSERT_EQUALS( 0.0, f );
317 TS_ASSERT_EQUALS( 1.0, f );
319 TS_ASSERT_EQUALS( 1.0, f );
321 TS_ASSERT_EQUALS( 1.0, f );
323 TS_ASSERT_EQUALS( 1.0, f );
325 TS_ASSERT_EQUALS( 2.0f, f );
327 TS_ASSERT_EQUALS( 2.0f, f );
329 TS_ASSERT_EQUALS( 2.0f, f );
338 double data[] = { 1.0, 2.0, 3.0 };
345 boost::shared_ptr< WDataSetScalar const > null;
363 double data[] = { 1.0, 2.0, 3.0 };
370 boost::shared_ptr< WDataSetScalar const > null;
371 boost::shared_ptr< WDataSetScalar const > ds;
372 std::string name(
"a name" );
375 TS_ASSERT_EQUALS( ds, null );
378 TS_ASSERT_EQUALS( ds, null );
381 TS_ASSERT_EQUALS( ds, null );
384 TS_ASSERT_EQUALS( ds, null );
387 TS_ASSERT_EQUALS( ds, d[ 0 ] );
390 TS_ASSERT_EQUALS( ds, d[ 1 ] );
393 TS_ASSERT_EQUALS( ds, d[ 2 ] );
396 std::vector< double > v( 27, 1.35 );
399 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
401 for( std::size_t k = 0; k < v.size(); ++k )
407 std::vector< double > v( 27, 1.99 );
410 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
412 for( std::size_t k = 0; k < v.size(); ++k )
418 std::vector< double > v( 27, 2.598 );
421 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
423 for( std::size_t k = 0; k < v.size(); ++k )
435 double data[] = { 1.0, 2.0, 3.0 };
442 float inf = std::numeric_limits< float >::infinity();
450 TS_ASSERT( !success );
452 TS_ASSERT( !success );
454 TS_ASSERT( !success );
456 TS_ASSERT( !success );
458 TS_ASSERT( !success );
463 h = ts.
interpolate<
double >( pos, time, &success );
464 TS_ASSERT( !success );
468 h = ts.
interpolate<
double >( pos, time, &success );
469 TS_ASSERT( success );
480 double data[] = { 1.0, 2.0, 3.0 };
487 float neginf = -std::numeric_limits< float >::infinity();
513 double data[] = { 1.0, 2.0, 3.0 };
520 float inf = std::numeric_limits< float >::infinity();
548 void createData(
double* data,
int number, DataSetPtrVector& dsets, TimesVector& times )
560 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
562 for(
int i = 0; i < number; ++i )
564 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, data[i] ) );
565 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
566 dsets.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
567 times.push_back( static_cast< float >( i ) );
580 #endif // WDATASETTIMESERIES_TEST_H
A grid that has parallelepiped cells which all have the same proportion.
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
A dataset that stores a time series.
void testGetDataSetPtrAtTimeSlice()
Provided datasets should be returned for provided time slices.
void createData(double *data, int number, DataSetPtrVector &dsets, TimesVector ×)
A helper function that creates some input data.
void testUBTime()
Test the upper bound time helper routine.
float getUBTimeSlice(float time) const
Find the smallest time slice position that is larger than time, or return inf, if there is no such ti...
void testLBTime()
Test the lower bound time helper routine.
void setUp()
Setup logger and other stuff for each test.
void testInterpolate()
Interpolation of values should be correct.
void testInterpolatedDataSets()
Interpolated datasets need to be correct.
float getLBTimeSlice(float time) const
Find the largest time slice position that is smaller than or equal to time, or return -inf...
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
boost::shared_ptr< WDataSetScalar const > getDataSetPtrAtTimeSlice(float time) const
Get a pointer to the dataset at a given time or a NULL-pointer, if there was no dataset given for tha...
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
void testGetNearestTimeSlice()
The nearest time slices should be calculated correctly.
float findNearestTimeSlice(float time) const
Find the nearest time slice for a given time.
Unit tests the time series class.
void testIsTimeSlice()
Times that were provided on construction should be found.
std::vector< float > TimesVector
a typdef
void testConstruction()
The input should be sorted correctly and all data should be stored correctly.
Base Class for all value set types.
bool isTimeSlice(float time) const
Check if there exists a predefined dataset at the given point in time, i.e.
std::vector< boost::shared_ptr< WDataSetScalar const > > DataSetPtrVector
a typedef
std::vector< TimeSlice > m_dataSets
the datasets that compose the time series
This data set type contains scalars as values.
float getMaxTime() const
Get the last point of time in the time series.
Data_T interpolate(WVector3d const &pos, float time, bool *success) const
Interpolate a value for a single point in space and time.
boost::shared_ptr< WDataSetScalar const > calcDataSetAtTime(float time, std::string const &name) const
Calculates a new dataset with values interpolated between the two nearest time slices.
void testTimeMinMax()
The correct minimum and maximum times should be returned.
float getMinTime() const
Get the first point of time in the time series.