25 #ifndef WDATASETTIMESERIES_TEST_H
26 #define WDATASETTIMESERIES_TEST_H
33 #include <boost/shared_ptr.hpp>
34 #include <cxxtest/TestSuite.h>
36 #include "../../common/WLimits.h"
37 #include "../../common/WLogger.h"
39 #include "../WDataSetTimeSeries.h"
62 double data[] = { 1.0, 2.0, 3.0 };
92 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
99 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
101 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
102 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
111 boost::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
112 boost::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
113 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
119 double data[] = { 1.0, 2.0 };
135 t[ 1 ] = 0.0f / 0.0f;
149 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
156 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
158 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
159 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
168 boost::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
169 boost::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
170 d.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
176 double data[] = { 1.0 };
192 t[ 0 ] = -0.0f / 0.0f;
198 double data[] = { 1.0, 2.0, 3.0 };
203 std::swap( t[ 1 ], t[ 2 ] );
206 TS_ASSERT_EQUALS( d[ 0 ], ts.
m_dataSets[ 0 ].first );
207 TS_ASSERT_EQUALS( d[ 2 ], ts.
m_dataSets[ 1 ].first );
208 TS_ASSERT_EQUALS( d[ 1 ], ts.
m_dataSets[ 2 ].first );
217 double data[] = { 1.0, 2.0, 3.0 };
246 double data[] = { 1.0, 2.0, 3.0 };
258 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
275 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
289 double data[] = { 1.0, 2.0, 3.0 };
297 TS_ASSERT_EQUALS( 0.0, f );
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( 1.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( 2.0f, f );
325 TS_ASSERT_EQUALS( 2.0f, f );
327 TS_ASSERT_EQUALS( 2.0f, f );
336 double data[] = { 1.0, 2.0, 3.0 };
343 boost::shared_ptr< WDataSetScalar const > null;
361 double data[] = { 1.0, 2.0, 3.0 };
368 boost::shared_ptr< WDataSetScalar const > null;
369 boost::shared_ptr< WDataSetScalar const > ds;
370 std::string name(
"a name" );
373 TS_ASSERT_EQUALS( ds, null );
376 TS_ASSERT_EQUALS( ds, null );
379 TS_ASSERT_EQUALS( ds, null );
382 TS_ASSERT_EQUALS( ds, null );
385 TS_ASSERT_EQUALS( ds, d[ 0 ] );
388 TS_ASSERT_EQUALS( ds, d[ 1 ] );
391 TS_ASSERT_EQUALS( ds, d[ 2 ] );
394 std::vector< double > v( 27, 1.35 );
397 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
399 for( std::size_t k = 0; k < v.size(); ++k )
405 std::vector< double > v( 27, 1.99 );
408 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
410 for( std::size_t k = 0; k < v.size(); ++k )
416 std::vector< double > v( 27, 2.598 );
419 boost::shared_ptr< WValueSet< double > > vs = boost::dynamic_pointer_cast<
WValueSet< double > >( ds->getValueSet() );
421 for( std::size_t k = 0; k < v.size(); ++k )
433 double data[] = { 1.0, 2.0, 3.0 };
440 float inf = std::numeric_limits< float >::infinity();
448 TS_ASSERT( !success );
450 TS_ASSERT( !success );
452 TS_ASSERT( !success );
454 TS_ASSERT( !success );
456 TS_ASSERT( !success );
461 h = ts.
interpolate<
double >( pos, time, &success );
462 TS_ASSERT( !success );
466 h = ts.
interpolate<
double >( pos, time, &success );
467 TS_ASSERT( success );
478 double data[] = { 1.0, 2.0, 3.0 };
485 float neginf = -std::numeric_limits< float >::infinity();
511 double data[] = { 1.0, 2.0, 3.0 };
518 float inf = std::numeric_limits< float >::infinity();
546 void createData(
double* data,
int number, DataSetPtrVector& dsets, TimesVector& times )
558 boost::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
560 for(
int i = 0; i < number; ++i )
562 boost::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, data[i] ) );
563 boost::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
564 dsets.push_back( boost::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
565 times.push_back( static_cast< float >( i ) );
578 #endif // WDATASETTIMESERIES_TEST_H
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
A grid that has parallelepiped cells which all have the same proportion.
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.