OpenWalnut  1.5.0dev
WCsvConverter_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 WCSVCONVERTER_TEST_H
26 #define WCSVCONVERTER_TEST_H
27 
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 #include <cxxtest/TestSuite.h>
35 
36 #include "../../data/io/WReaderCSV.h"
37 #include "../../transferFunctionColorBar/WMTransferFunctionColorBar.h"
38 #include "../WCsvConverter.h"
39 #include "../WMFilterProtonData.h"
40 #include "core/kernel/WModuleFactory.h"
41 
42 /**
43  * Test class of WCsvConverter class
44  */
45 class WCsvConverterTest : public CxxTest::TestSuite
46 {
47 public:
48  /**
49  * The protondata
50  */
52 
53  /**
54  * The property status
55  */
56  std::shared_ptr< WPropertyStatus > m_propertyStatus = nullptr;
57 
58  /**
59  * the property group
60  */
61  std::shared_ptr< WProperties > m_properties = nullptr;
62 
63  /**
64  * The color bar
65  */
67 
68  /**
69  * Setup variables and data, needed for each test.
70  */
71  void setUp()
72  {
73  WReaderCSV csvReader( W_FIXTURE_PATH + "../data/CSVs/valid.csv" );
74  std::shared_ptr< WDataSetCSV > csvDataSet = csvReader.read();
75  m_protonData = WProtonData::SPtr( new WProtonData( csvDataSet->getHeader(), csvDataSet->getData() ) );
76  m_propertyStatus = std::shared_ptr< WPropertyStatus >( new WPropertyStatus() );
77 
79 
81 
82  m_propertyStatus->setVisualizationPropertyHandler( WVisualizationPropertyHandler::SPtr(
84  );
85 
86  m_propertyStatus->setEventIDLimitationPropertyHandler( WEventIDLimitationPropertyHandler::SPtr(
88  );
89 
91  //m_propertyStatus->getColumnPropertyHandler()->setSelectionEventMethod( nullptr );
92  }
93 
94  /**
95  * Test the constructors of WCsvConverter, so no exception is thrown, when input parameters are correct
96  */
98  {
99  TS_ASSERT_THROWS_NOTHING( WCsvConverter( m_protonData, m_propertyStatus, m_colorBar ) );
100  }
101 
102  /**
103  * Tests the method getClusterSize()
104  */
106  {
108  TS_ASSERT_EQUALS( tmpCsvReader.getClusterSize( 0.0f ), 0.0f );
109  TS_ASSERT_DELTA( tmpCsvReader.getClusterSize( 1.0f ), 36.11878927498844f, 1e-5 );
110  TS_ASSERT_DELTA( tmpCsvReader.getClusterSize( 1.0001f ), 36.1203073289856f, 1e-5 );
111 
112  // uses std::isnan instead of TS_ASSERT_IS_NAN as it is not present in the cxxtest version on the build server
113  TS_ASSERT( std::isnan( tmpCsvReader.getClusterSize( -0.0001f ) ) );
114  TS_ASSERT( std::isnan( tmpCsvReader.getClusterSize( -1.0f ) ) );
115  }
116 
117  /**
118  * Tests the method stringToDouble()
119  */
121  {
122  std::map< std::string, double > testDoubleMap;
123  testDoubleMap.insert( std::pair< std::string, double >( "1000.1", 1000.1f ) );
124  testDoubleMap.insert( std::pair< std::string, double >( "1.", 1.0f ) );
125  testDoubleMap.insert( std::pair< std::string, double >( ".1", 0.1f ) );
126  testDoubleMap.insert( std::pair< std::string, double >( "2.1", 2.1f ) );
127  testDoubleMap.insert( std::pair< std::string, double >( "+1", 1.0f ) );
128  testDoubleMap.insert( std::pair< std::string, double >( "-1", -1.0f ) );
129  testDoubleMap.insert( std::pair< std::string, double >( "+.1", 0.1f ) );
130  testDoubleMap.insert( std::pair< std::string, double >( "-.1", -0.1f ) );
131  testDoubleMap.insert( std::pair< std::string, double >( "+1e-1", 0.1f ) );
132  testDoubleMap.insert( std::pair< std::string, double >( "0.001e-6", 0.000000001f ) );
133  testDoubleMap.insert( std::pair< std::string, double >( "0.111111111111111", 0.111111111111111f ) );
134 
136 
137  for( std::pair< std::string, double > stringDoublePair : testDoubleMap )
138  {
139  TS_ASSERT_EQUALS( tmpCsvReader.stringToDouble( stringDoublePair.first ),
140  stringDoublePair.second );
141  }
142 
143  TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "1.g" ), WException &e );
144  TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "" ), WException &e );
145  TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "Test" ), WException &e );
146  TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "1.1.2" ), WException &e );
147  }
148 
149  /**
150  * Tests the method stringToInt()
151  */
153  {
154  std::map< std::string, int > testIntMap;
155  testIntMap.insert( std::pair< std::string, int >( "1", 1 ) );
156  testIntMap.insert( std::pair< std::string, int >( "0", 0 ) );
157  testIntMap.insert( std::pair< std::string, int >( "10", 10 ) );
158  testIntMap.insert( std::pair< std::string, int >( "+1", 1 ) );
159  testIntMap.insert( std::pair< std::string, int >( "-1", -1 ) );
160  testIntMap.insert( std::pair< std::string, int >( "1e-1", 0 ) );
161  testIntMap.insert( std::pair< std::string, int >( "1e1", 10 ) );
162  testIntMap.insert( std::pair< std::string, int >( "+1e-1", 0 ) );
163  testIntMap.insert( std::pair< std::string, int >( "0.001e-6", 0 ) );
164  testIntMap.insert( std::pair< std::string, int >( "0.111111111111111", 0 ) );
165 
167 
168  for( std::pair< std::string, int > stringIntPair : testIntMap )
169  {
170  TS_ASSERT_EQUALS( tmpCsvReader.stringToInt( stringIntPair.first ),
171  stringIntPair.second );
172  }
173 
174  TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "1.g" ), WException &e );
175  TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "" ), WException &e );
176  TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "Test" ), WException &e );
177  TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "1.1.2" ), WException &e );
178  }
179 };
180 
181 #endif // WCSVCONVERTER_TEST_H
Creates, updates and handles the column properties.
std::shared_ptr< WColumnPropertyHandler > SPtr
shared_ptr that points to itself
Test class of WCsvConverter class.
std::shared_ptr< WPropertyStatus > m_propertyStatus
The property status.
void testStringToDouble()
Tests the method stringToDouble()
void testConstructorThrowNothing()
Test the constructors of WCsvConverter, so no exception is thrown, when input parameters are correct.
void testGetClusterSize()
Tests the method getClusterSize()
std::shared_ptr< WProperties > m_properties
the property group
void testStringToInt()
Tests the method stringToInt()
WProtonData::SPtr m_protonData
The protondata.
WModule::SPtr m_colorBar
The color bar.
void setUp()
Setup variables and data, needed for each test.
Converts the csv data to points and fibers.
Definition: WCsvConverter.h:54
float stringToDouble(std::string str)
checks whether the string is a number (double)
int stringToInt(std::string str)
checks whether the string is a number (int)
float getClusterSize(float edep)
Computes the cluster size.
Creates, updates and handles the EventID properties.
std::shared_ptr< WEventIDLimitationPropertyHandler > SPtr
shared_ptr that points to itself
Basic exception handler.
Definition: WException.h:39
Creates, updates and handles the filter properties.
std::shared_ptr< WFilterPropertyHandler > SPtr
Function variables for updating the data.
This module simply registers the given dataset to the texture handling mechanism.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
Definition: WModule.h:106
Holds references to all the property handlers.
Holds the csv data.
Definition: WProtonData.h:43
std::shared_ptr< WProtonData > SPtr
shared_ptr that points to itself
Definition: WProtonData.h:52
Read content from a CSV file.
Definition: WReaderCSV.h:43
virtual std::shared_ptr< WDataSetCSV > read()
Read the file and create a dataset as a vector.
Definition: WReaderCSV.cpp:74
Creates, updates and handles the visualization properties.
std::shared_ptr< WVisualizationPropertyHandler > SPtr
shared_ptr that points to itself