25 #ifndef WDATASETTIMESERIES_TEST_H
26 #define WDATASETTIMESERIES_TEST_H
34 #include <cxxtest/TestSuite.h>
36 #include "../../common/WLimits.h"
37 #include "../../common/WLogger.h"
38 #include "../WDataSetTimeSeries.h"
61 double data[] = { 1.0, 2.0, 3.0 };
91 std::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
98 std::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
100 std::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
101 d.push_back( std::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
110 std::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
111 std::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
112 d.push_back( std::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
118 double data[] = { 1.0, 2.0 };
134 t[ 1 ] = 0.0f / 0.0f;
148 std::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, 4 ) );
155 std::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
157 std::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
158 d.push_back( std::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
167 std::shared_ptr< std::vector< float > > v2(
new std::vector< float >( 27, 4 ) );
168 std::shared_ptr< WValueSet< float > > vs2(
new WValueSet< float >( 0, 1, v2, W_DT_FLOAT ) );
169 d.push_back( std::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs2, d.front()->getGrid() ) ) );
175 double data[] = { 1.0 };
191 t[ 0 ] = -0.0f / 0.0f;
197 double data[] = { 1.0, 2.0, 3.0 };
202 std::swap( t[ 1 ], t[ 2 ] );
205 TS_ASSERT_EQUALS( d[ 0 ], ts.
m_dataSets[ 0 ].first );
206 TS_ASSERT_EQUALS( d[ 2 ], ts.
m_dataSets[ 1 ].first );
207 TS_ASSERT_EQUALS( d[ 1 ], ts.
m_dataSets[ 2 ].first );
216 double data[] = { 1.0, 2.0, 3.0 };
245 double data[] = { 1.0, 2.0, 3.0 };
257 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
274 TS_ASSERT( !ts.
isTimeSlice( std::numeric_limits< float >::infinity() ) );
288 double data[] = { 1.0, 2.0, 3.0 };
296 TS_ASSERT_EQUALS( 0.0, f );
298 TS_ASSERT_EQUALS( 0.0, f );
300 TS_ASSERT_EQUALS( 0.0, f );
302 TS_ASSERT_EQUALS( 0.0, f );
304 TS_ASSERT_EQUALS( 0.0, f );
306 TS_ASSERT_EQUALS( 0.0, f );
308 TS_ASSERT_EQUALS( 0.0, f );
310 TS_ASSERT_EQUALS( 0.0, f );
312 TS_ASSERT_EQUALS( 0.0, f );
314 TS_ASSERT_EQUALS( 1.0, f );
316 TS_ASSERT_EQUALS( 1.0, f );
318 TS_ASSERT_EQUALS( 1.0, f );
320 TS_ASSERT_EQUALS( 1.0, f );
322 TS_ASSERT_EQUALS( 2.0f, f );
324 TS_ASSERT_EQUALS( 2.0f, f );
326 TS_ASSERT_EQUALS( 2.0f, f );
335 double data[] = { 1.0, 2.0, 3.0 };
342 std::shared_ptr< WDataSetScalar const >
null;
360 double data[] = { 1.0, 2.0, 3.0 };
367 std::shared_ptr< WDataSetScalar const >
null;
368 std::shared_ptr< WDataSetScalar const > ds;
369 std::string name(
"a name" );
372 TS_ASSERT_EQUALS( ds,
null );
375 TS_ASSERT_EQUALS( ds,
null );
378 TS_ASSERT_EQUALS( ds,
null );
381 TS_ASSERT_EQUALS( ds,
null );
384 TS_ASSERT_EQUALS( ds, d[ 0 ] );
387 TS_ASSERT_EQUALS( ds, d[ 1 ] );
390 TS_ASSERT_EQUALS( ds, d[ 2 ] );
393 std::vector< double > v( 27, 1.35 );
396 std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
398 for( std::size_t k = 0; k < v.size(); ++k )
404 std::vector< double > v( 27, 1.99 );
407 std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
409 for( std::size_t k = 0; k < v.size(); ++k )
415 std::vector< double > v( 27, 2.598 );
418 std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
420 for( std::size_t k = 0; k < v.size(); ++k )
432 double data[] = { 1.0, 2.0, 3.0 };
439 float inf = std::numeric_limits< float >::infinity();
447 TS_ASSERT( !success );
449 TS_ASSERT( !success );
451 TS_ASSERT( !success );
453 TS_ASSERT( !success );
455 TS_ASSERT( !success );
460 h = ts.
interpolate<
double >( pos, time, &success );
461 TS_ASSERT( !success );
465 h = ts.
interpolate<
double >( pos, time, &success );
466 TS_ASSERT( success );
477 double data[] = { 1.0, 2.0, 3.0 };
484 float neginf = -std::numeric_limits< float >::infinity();
510 double data[] = { 1.0, 2.0, 3.0 };
517 float inf = std::numeric_limits< float >::infinity();
557 std::shared_ptr< WGridRegular3D > g(
new WGridRegular3D( 3, 3, 3, transform ) );
559 for(
int i = 0; i < number; ++i )
561 std::shared_ptr< std::vector< double > > v(
new std::vector< double >( 27, data[i] ) );
562 std::shared_ptr< WValueSet< double > > vs(
new WValueSet< double >( 0, 1, v, W_DT_DOUBLE ) );
563 dsets.push_back( std::shared_ptr< WDataSetScalar const >(
new WDataSetScalar( vs, g ) ) );
564 times.push_back(
static_cast< float >( i ) );
This data set type contains scalars as values.
Unit tests the time series class.
void testInterpolate()
Interpolation of values should be correct.
void testUBTime()
Test the upper bound time helper routine.
void testConstruction()
The input should be sorted correctly and all data should be stored correctly.
std::vector< std::shared_ptr< WDataSetScalar const > > DataSetPtrVector
a typedef
void testGetDataSetPtrAtTimeSlice()
Provided datasets should be returned for provided time slices.
void setUp()
Setup logger and other stuff for each test.
void createData(double *data, int number, DataSetPtrVector &dsets, TimesVector ×)
A helper function that creates some input data.
void testTimeMinMax()
The correct minimum and maximum times should be returned.
void testInterpolatedDataSets()
Interpolated datasets need to be correct.
void testGetNearestTimeSlice()
The nearest time slices should be calculated correctly.
void testIsTimeSlice()
Times that were provided on construction should be found.
std::vector< float > TimesVector
a typdef
void testLBTime()
Test the lower bound time helper routine.
A dataset that stores a time series.
float getLBTimeSlice(float time) const
Find the largest time slice position that is smaller than or equal to time, or return -inf,...
std::vector< TimeSlice > m_dataSets
the datasets that compose the time series
float getMinTime() const
Get the first point of time in the time series.
float getMaxTime() const
Get the last point of time in the time series.
float findNearestTimeSlice(float time) const
Find the nearest time slice for a given time.
std::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...
Data_T interpolate(WVector3d const &pos, float time, bool *success) const
Interpolate a value for a single point in space and time.
std::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.
bool isTimeSlice(float time) const
Check if there exists a predefined dataset at the given point in time, i.e.
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...
A grid that has parallelepiped cells which all have the same proportion.
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.
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
Base Class for all value set types.
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.