OpenWalnut  1.5.0dev
WDataSetTimeSeries_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WDATASETTIMESERIES_TEST_H
26 #define WDATASETTIMESERIES_TEST_H
27 
28 #include <algorithm>
29 #include <limits>
30 #include <memory>
31 #include <string>
32 #include <vector>
33 
34 #include <cxxtest/TestSuite.h>
35 
36 #include "../../common/WLimits.h"
37 #include "../../common/WLogger.h"
38 #include "../WDataSetTimeSeries.h"
39 
40 
41 /**
42  * Unit tests the time series class.
43  */
44 class WDataSetTimeSeriesTest : public CxxTest::TestSuite
45 {
46  //! a typedef
47  typedef std::vector< std::shared_ptr< WDataSetScalar const > > DataSetPtrVector;
48 
49  //! a typdef
50  typedef std::vector< float > TimesVector;
51 
52 public:
53  /**
54  * The input should be sorted correctly and all data should be stored correctly.
55  * Also there should be only one grid for all datasets.
56  */
58  {
59  // test with 3 time slices
60  {
61  double data[] = { 1.0, 2.0, 3.0 };
63  TimesVector t;
64 
65  // test what happens when the input is empty
66  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
67 
68  // test what happens when the vector sizes don't match
69  createData( data, 3, d, t );
70  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
71  t.push_back( 4.0f );
72  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
73 
74  // test what happens when there is an invalid time value
75  t.resize( 3 );
76  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
77  t[ 2 ] = -0.0 / 0.0;
78  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
79 
80  // test what happens when there are equal time values
81  t[ 2 ] = t[ 1 ];
82  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
83 
84  // test what happens if the grids don't match
85  t[ 2 ] = 2.0;
86  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
87 
88  t.push_back( 4.0f );
89 
90  WMatrix< double > mat( 4, 4 );
91  std::shared_ptr< std::vector< double > > v( new std::vector< double >( 27, 4 ) );
92  mat.makeIdentity();
93  mat( 0, 0 ) = 1.0;
94  mat( 1, 1 ) = 0.5;
95  mat( 2, 2 ) = 2.0;
96 
97  WGridTransformOrtho transform( mat );
98  std::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
99 
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 ) ) );
102  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
103 
104  // test what happens if the valuesets data types don't match
105  d.resize( 3 );
106  t.resize( 3 );
107  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
108 
109  t.push_back( 4.0f );
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() ) ) );
113  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
114  }
115 
116  // test with 2 time slices
117  {
118  double data[] = { 1.0, 2.0 };
120  TimesVector t;
121 
122  // test what happens when the input is empty
123  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
124 
125  // test what happens when the vector sizes don't match
126  createData( data, 2, d, t );
127  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
128  t.push_back( 4.0f );
129  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
130 
131  // test what happens when there is an invalid time value
132  t.resize( 2 );
133  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
134  t[ 1 ] = 0.0f / 0.0f;
135  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
136 
137  // test what happens when there are equal time values
138  t[ 1 ] = t[ 0 ];
139  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
140 
141  // test what happens if the grids don't match
142  t[ 1 ] = 2.0;
143  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
144 
145  t.push_back( 4.0f );
146 
147  WMatrix< double > mat( 4, 4 );
148  std::shared_ptr< std::vector< double > > v( new std::vector< double >( 27, 4 ) );
149  mat.makeIdentity();
150  mat( 0, 0 ) = 1.0;
151  mat( 1, 1 ) = 0.5;
152  mat( 2, 2 ) = 2.0;
153 
154  WGridTransformOrtho transform( mat );
155  std::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
156 
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 ) ) );
159  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
160 
161  // test what happens if the valuesets data types don't match
162  d.resize( 2 );
163  t.resize( 2 );
164  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
165 
166  t.push_back( 4.0f );
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() ) ) );
170  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
171  }
172 
173  // test with 1 time slice
174  {
175  double data[] = { 1.0 };
177  TimesVector t;
178 
179  // test what happens when the input is empty
180  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
181 
182  // test what happens when the vector sizes don't match
183  createData( data, 1, d, t );
184  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
185  t.push_back( 4.0f );
186  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
187 
188  // test what happens when there is an invalid time value
189  t.resize( 1 );
190  TS_ASSERT_THROWS_NOTHING( WDataSetTimeSeries( d, t ) );
191  t[ 0 ] = -0.0f / 0.0f;
192  TS_ASSERT_THROWS( WDataSetTimeSeries( d, t ), const WException& );
193  }
194 
195  // datasets should be sorted by time
196  {
197  double data[] = { 1.0, 2.0, 3.0 };
199  TimesVector t;
200 
201  createData( data, 3, d, t );
202  std::swap( t[ 1 ], t[ 2 ] );
203  WDataSetTimeSeries ts( d, t );
204 
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 );
208  }
209  }
210 
211  /**
212  * The correct minimum and maximum times should be returned.
213  */
215  {
216  double data[] = { 1.0, 2.0, 3.0 };
218  TimesVector t;
219 
220  createData( data, 3, d, t );
221  {
222  WDataSetTimeSeries ts( d, t );
223 
224  TS_ASSERT_EQUALS( ts.getMinTime(), 0.0f );
225  TS_ASSERT_EQUALS( ts.getMaxTime(), 2.0f );
226  }
227 
228  createData( data, 3, d, t );
229  t[ 0 ] = 1.34f;
230  t[ 2 ] = 1.43f;
231  {
232  WDataSetTimeSeries ts( d, t );
233 
234  TS_ASSERT_EQUALS( ts.getMinTime(), 1.0f );
235  TS_ASSERT_EQUALS( ts.getMaxTime(), 1.43f );
236  }
237  }
238 
239  /**
240  * Times that were provided on construction should be found. Times outside of the
241  * interval [getMinTime(),getMaxTime()] should be rejected.
242  */
244  {
245  double data[] = { 1.0, 2.0, 3.0 };
247  TimesVector t;
248 
249  createData( data, 3, d, t );
250  {
251  WDataSetTimeSeries ts( d, t );
252  TS_ASSERT( ts.isTimeSlice( 0.0f ) );
253  TS_ASSERT( ts.isTimeSlice( 1.0f ) );
254  TS_ASSERT( ts.isTimeSlice( 2.0f ) );
255  TS_ASSERT( !ts.isTimeSlice( 5.0f ) );
256  TS_ASSERT( !ts.isTimeSlice( 0.0f / 0.0f ) );
257  TS_ASSERT( !ts.isTimeSlice( std::numeric_limits< float >::infinity() ) );
258  TS_ASSERT( !ts.isTimeSlice( 1.00001f ) );
259  TS_ASSERT( !ts.isTimeSlice( 2.345f ) );
260  TS_ASSERT( !ts.isTimeSlice( 0.5234f ) );
261  TS_ASSERT( !ts.isTimeSlice( -wlimits::FLT_EPS ) );
262  }
263 
264  createData( data, 3, d, t );
265  t[ 0 ] = 1.34f;
266  t[ 2 ] = 1.43f;
267  {
268  WDataSetTimeSeries ts( d, t );
269  TS_ASSERT( ts.isTimeSlice( 1.34f ) );
270  TS_ASSERT( ts.isTimeSlice( 1.43f ) );
271  TS_ASSERT( ts.isTimeSlice( 1.0f ) );
272  TS_ASSERT( !ts.isTimeSlice( 5.0f ) );
273  TS_ASSERT( !ts.isTimeSlice( 0.0f / 0.0f ) );
274  TS_ASSERT( !ts.isTimeSlice( std::numeric_limits< float >::infinity() ) );
275  TS_ASSERT( !ts.isTimeSlice( 1.00001f ) );
276  TS_ASSERT( !ts.isTimeSlice( 2.345f ) );
277  TS_ASSERT( !ts.isTimeSlice( 0.5234f ) );
278  TS_ASSERT( !ts.isTimeSlice( -wlimits::FLT_EPS ) );
279  }
280  }
281 
282  /**
283  * The nearest time slices should be calculated correctly. Boundary conditions must be
284  * handled correctly.
285  */
287  {
288  double data[] = { 1.0, 2.0, 3.0 };
290  TimesVector t;
291 
292  createData( data, 3, d, t );
293  WDataSetTimeSeries ts( d, t );
294 
295  float f = ts.findNearestTimeSlice( -std::numeric_limits< float >::infinity() );
296  TS_ASSERT_EQUALS( 0.0, f );
297  f = ts.findNearestTimeSlice( -3346.0 );
298  TS_ASSERT_EQUALS( 0.0, f );
299  f = ts.findNearestTimeSlice( -1.0 );
300  TS_ASSERT_EQUALS( 0.0, f );
301  f = ts.findNearestTimeSlice( -0.01 );
302  TS_ASSERT_EQUALS( 0.0, f );
304  TS_ASSERT_EQUALS( 0.0, f );
305  f = ts.findNearestTimeSlice( 0.0 );
306  TS_ASSERT_EQUALS( 0.0, f );
308  TS_ASSERT_EQUALS( 0.0, f );
309  f = ts.findNearestTimeSlice( 0.3 );
310  TS_ASSERT_EQUALS( 0.0, f );
311  f = ts.findNearestTimeSlice( 0.5 );
312  TS_ASSERT_EQUALS( 0.0, f );
313  f = ts.findNearestTimeSlice( 0.5 + wlimits::FLT_EPS );
314  TS_ASSERT_EQUALS( 1.0, f );
315  f = ts.findNearestTimeSlice( 1.0 - wlimits::FLT_EPS );
316  TS_ASSERT_EQUALS( 1.0, f );
317  f = ts.findNearestTimeSlice( 1.5 - wlimits::FLT_EPS );
318  TS_ASSERT_EQUALS( 1.0, f );
319  f = ts.findNearestTimeSlice( 1.5 );
320  TS_ASSERT_EQUALS( 1.0, f );
321  f = ts.findNearestTimeSlice( 2.0 - wlimits::FLT_EPS );
322  TS_ASSERT_EQUALS( 2.0f, f );
323  f = ts.findNearestTimeSlice( 2.0 );
324  TS_ASSERT_EQUALS( 2.0f, f );
325  f = ts.findNearestTimeSlice( std::numeric_limits< float >::infinity() );
326  TS_ASSERT_EQUALS( 2.0f, f );
327  TS_ASSERT_THROWS( ts.findNearestTimeSlice( 0.0 / 0.0 ), const WException& );
328  }
329 
330  /**
331  * Provided datasets should be returned for provided time slices.
332  */
334  {
335  double data[] = { 1.0, 2.0, 3.0 };
337  TimesVector t;
338 
339  createData( data, 3, d, t );
340  WDataSetTimeSeries ts( d, t );
341 
342  std::shared_ptr< WDataSetScalar const > null;
343 
344  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 0.0f / 0.0f ), null );
345  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( -std::numeric_limits< float >::infinity() ), null );
346  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 0.0f ), d[ 0 ] );
347  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( wlimits::FLT_EPS ), null );
348  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 0.999f ), null );
349  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 1.0f ), d[ 1 ] );
350  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 2.0f ), d[ 2 ] );
351  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( 344643.0f ), null );
352  TS_ASSERT_EQUALS( ts.getDataSetPtrAtTimeSlice( std::numeric_limits< float >::infinity() ), null );
353  }
354 
355  /**
356  * Interpolated datasets need to be correct.
357  */
359  {
360  double data[] = { 1.0, 2.0, 3.0 };
362  TimesVector t;
363 
364  createData( data, 3, d, t );
365  WDataSetTimeSeries ts( d, t );
366 
367  std::shared_ptr< WDataSetScalar const > null;
368  std::shared_ptr< WDataSetScalar const > ds;
369  std::string name( "a name" );
370 
371  ds = ts.calcDataSetAtTime( -std::numeric_limits< float >::infinity(), name );
372  TS_ASSERT_EQUALS( ds, null );
373 
374  ds = ts.calcDataSetAtTime( -wlimits::FLT_EPS, name );
375  TS_ASSERT_EQUALS( ds, null );
376 
377  ds = ts.calcDataSetAtTime( std::numeric_limits< float >::infinity(), name );
378  TS_ASSERT_EQUALS( ds, null );
379 
380  ds = ts.calcDataSetAtTime( 2.0f + 2.0f * wlimits::FLT_EPS, name );
381  TS_ASSERT_EQUALS( ds, null );
382 
383  ds = ts.calcDataSetAtTime( 0.0f, name );
384  TS_ASSERT_EQUALS( ds, d[ 0 ] );
385 
386  ds = ts.calcDataSetAtTime( 1.0f, name );
387  TS_ASSERT_EQUALS( ds, d[ 1 ] );
388 
389  ds = ts.calcDataSetAtTime( 2.0f, name );
390  TS_ASSERT_EQUALS( ds, d[ 2 ] );
391 
392  {
393  std::vector< double > v( 27, 1.35 );
394  ds = ts.calcDataSetAtTime( 0.35f, name );
395  TS_ASSERT( ds );
396  std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
397  TS_ASSERT( vs );
398  for( std::size_t k = 0; k < v.size(); ++k )
399  {
400  TS_ASSERT_DELTA( v[ k ], vs->rawData()[ k ], 1.0f * wlimits::FLT_EPS );
401  }
402  }
403  {
404  std::vector< double > v( 27, 1.99 );
405  ds = ts.calcDataSetAtTime( 0.99f, name );
406  TS_ASSERT( ds );
407  std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
408  TS_ASSERT( vs );
409  for( std::size_t k = 0; k < v.size(); ++k )
410  {
411  TS_ASSERT_DELTA( v[ k ], vs->rawData()[ k ], 1.0f * wlimits::FLT_EPS );
412  }
413  }
414  {
415  std::vector< double > v( 27, 2.598 );
416  ds = ts.calcDataSetAtTime( 1.598f, name );
417  TS_ASSERT( ds );
418  std::shared_ptr< WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( ds->getValueSet() );
419  TS_ASSERT( vs );
420  for( std::size_t k = 0; k < v.size(); ++k )
421  {
422  TS_ASSERT_DELTA( v[ k ], vs->rawData()[ k ], 1.0f * wlimits::FLT_EPS );
423  }
424  }
425  }
426 
427  /**
428  * Interpolation of values should be correct.
429  */
431  {
432  double data[] = { 1.0, 2.0, 3.0 };
434  TimesVector t;
435 
436  createData( data, 3, d, t );
437  WDataSetTimeSeries ts( d, t );
438 
439  float inf = std::numeric_limits< float >::infinity();
440  bool success;
441  double h;
442 
443  // test invalid times
444  WVector3d pos( 1.0, 0.5, 1.0 );
445 
446  TS_ASSERT_THROWS( h = ts.interpolate< double >( pos, -inf, &success ), const WException& );
447  TS_ASSERT( !success );
448  TS_ASSERT_THROWS( h = ts.interpolate< double >( pos, -3.0f, &success ), const WException& );
449  TS_ASSERT( !success );
450  TS_ASSERT_THROWS( h = ts.interpolate< double >( pos, -wlimits::FLT_EPS, &success ), const WException& );
451  TS_ASSERT( !success );
452  TS_ASSERT_THROWS( h = ts.interpolate< double >( pos, 2.0f + 2.0f * wlimits::FLT_EPS, &success ), const WException& );
453  TS_ASSERT( !success );
454  TS_ASSERT_THROWS( h = ts.interpolate< double >( pos, inf, &success ), const WException& );
455  TS_ASSERT( !success );
456 
457  // test invalid position
458  float time = 0.99f;
459  pos[ 0 ] = -wlimits::FLT_EPS;
460  h = ts.interpolate< double >( pos, time, &success );
461  TS_ASSERT( !success );
462 
463  // now test some valid cases
464  pos[ 0 ] = 1.0f;
465  h = ts.interpolate< double >( pos, time, &success );
466  TS_ASSERT( success );
467  TS_ASSERT_DELTA( h, 1.99, wlimits::FLT_EPS );
468  }
469 
470  /**
471  * Test the lower bound time helper routine.
472  * It should return the largest time slice that is smaller than or equal
473  * to the input time, or -inf if there is no such time slice.
474  */
475  void testLBTime()
476  {
477  double data[] = { 1.0, 2.0, 3.0 };
479  TimesVector t;
480 
481  createData( data, 3, d, t );
482  WDataSetTimeSeries ts( d, t );
483 
484  float neginf = -std::numeric_limits< float >::infinity();
485 
486  // not using TS_ASSERT_EQUALS here because of a bug
487  // passing inf as a parameter leads to an endless loop
488  TS_ASSERT( ts.getLBTimeSlice( neginf ) == neginf );
489  TS_ASSERT( ts.getLBTimeSlice( -0.01f ) == neginf );
490  TS_ASSERT( ts.getLBTimeSlice( 0.0f ) == 0.0f );
491  TS_ASSERT( ts.getLBTimeSlice( -wlimits::FLT_EPS ) == neginf );
492  TS_ASSERT( ts.getLBTimeSlice( wlimits::FLT_EPS ) == 0.0f );
493  TS_ASSERT( ts.getLBTimeSlice( 1.0f ) == 1.0f );
494  TS_ASSERT( ts.getLBTimeSlice( 1.2f ) == 1.0f );
495  TS_ASSERT( ts.getLBTimeSlice( 2.0f - wlimits::FLT_EPS ) == 1.0f );
496  TS_ASSERT( ts.getLBTimeSlice( 2.0f ) == 2.0f );
497  TS_ASSERT( ts.getLBTimeSlice( -neginf ) == 2.0f );
498 
499  // note that there is no test for nan, as these routines are private
500  // it is the callers responsibility to check for nan
501  }
502 
503  /**
504  * Test the upper bound time helper routine.
505  * It should return the smallest time slice that is larger than the input
506  * time, or inf if there is no such time slice.
507  */
508  void testUBTime()
509  {
510  double data[] = { 1.0, 2.0, 3.0 };
512  TimesVector t;
513 
514  createData( data, 3, d, t );
515  WDataSetTimeSeries ts( d, t );
516 
517  float inf = std::numeric_limits< float >::infinity();
518 
519  // not using TS_ASSERT_EQUALS here because of a bug
520  // passing inf as a parameter leads to an endless loop
521  TS_ASSERT( ts.getUBTimeSlice( -inf ) == 0.0f );
522  TS_ASSERT( ts.getUBTimeSlice( -0.01f ) == 0.0f );
523  TS_ASSERT( ts.getUBTimeSlice( 0.0f ) == 1.0f );
524  TS_ASSERT( ts.getUBTimeSlice( -wlimits::FLT_EPS ) == 0.0f );
525  TS_ASSERT( ts.getUBTimeSlice( wlimits::FLT_EPS ) == 1.0f );
526  TS_ASSERT( ts.getUBTimeSlice( 1.0f ) == 2.0f );
527  TS_ASSERT( ts.getUBTimeSlice( 1.2f ) == 2.0f );
528  TS_ASSERT( ts.getUBTimeSlice( 2.0f - wlimits::FLT_EPS ) == 2.0f );
529  TS_ASSERT( ts.getUBTimeSlice( 2.0f ) == inf );
530  TS_ASSERT( ts.getUBTimeSlice( inf ) == inf );
531 
532  // note that there is no test for nan, as these routines are private
533  // it is the callers responsibility to check for nan
534  }
535 
536 private:
537  /**
538  * A helper function that creates some input data.
539  *
540  * \param data An array of data values, one for each time slice.
541  * \param number The number of time slices.
542  * \param dsets The output datasets.
543  * \param times Some times for the output datasets.
544  */
545  void createData( double* data, int number, DataSetPtrVector& dsets, TimesVector& times ) // NOLINT
546  {
547  dsets.clear();
548  times.clear();
549 
550  WMatrix< double > mat( 4, 4 );
551  mat.makeIdentity();
552  mat( 0, 0 ) = 1.0;
553  mat( 1, 1 ) = 0.5;
554  mat( 2, 2 ) = 2.0;
555 
556  WGridTransformOrtho transform( mat );
557  std::shared_ptr< WGridRegular3D > g( new WGridRegular3D( 3, 3, 3, transform ) );
558 
559  for( int i = 0; i < number; ++i )
560  {
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 ) );
565  }
566  }
567 
568  /**
569  * Setup logger and other stuff for each test.
570  */
571  void setUp()
572  {
574  }
575 };
576 
577 #endif // WDATASETTIMESERIES_TEST_H
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 &times)
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...
Basic exception handler.
Definition: WException.h:39
A grid that has parallelepiped cells which all have the same proportion.
Implements an orthogonal grid transformation.
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.
Definition: WLogger.cpp:41
WMatrix & makeIdentity()
Makes the matrix contain the identity matrix, i.e.
Definition: WMatrix.h:352
Base Class for all value set types.
Definition: WValueSet.h:47
const float FLT_EPS
Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
Definition: WLimits.cpp:47