Commit 2410c2cc authored by Daniel Bub's avatar Daniel Bub
Browse files

Merge branch 'top2021s6/#83_unittest_wcsvconverter' into 'sprint_6'

[MERGE #83] add unittests wcsvconverter

See merge request top/21s/sivert-vis/sivert-vis-project!101
parents 802a4bb1 ed480487
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <cmath>
#include <string>
#include <vector>
......@@ -409,7 +410,7 @@ bool WCsvConverter::checkIfOutputIsNull()
float WCsvConverter::getClusterSize( float edep )
{
return 7.6626 * pow( edep * 1000 / 25, 0.420307 );
return 7.6626f * powf( edep * 40.0f, 0.420307f );
}
float WCsvConverter::stringToDouble( std::string str )
......
......@@ -53,6 +53,10 @@
*/
class WCsvConverter
{
/**
* only test classes may be friend
*/
friend class WCsvConverterTest;
public:
/**
* Initializes the vectors, indices and transfer function color bar
......
......@@ -25,6 +25,8 @@
#ifndef WCSVCONVERTER_TEST_H
#define WCSVCONVERTER_TEST_H
#include <map>
#include <utility>
#include <vector>
#include <string>
#include <cxxtest/TestSuite.h>
......@@ -43,43 +45,136 @@ class WCsvConverterTest : public CxxTest::TestSuite
{
public:
/**
* Test the constructors of WCsvConverter, so no exception is thrown, when input parameters are correct
*
*/
WProtonData::SPtr m_protonData = nullptr;
/**
*
*/
boost::shared_ptr< WPropertyStatus > m_propertyStatus = nullptr;
/**
*
*/
static void testConstructorThrowNullptr()
boost::shared_ptr< WProperties > m_properties = nullptr;
/**
*
* @param setUp
* @return
*/
WModule::SPtr m_colorBar = nullptr;
/**
* Setup variables and data, needed for each test.
*/
void setUp()
{
WReaderCSV csvReader( W_FIXTURE_PATH + "../data/CSVs/valid.csv" );
boost::shared_ptr< WDataSetCSV > csvDataSet = csvReader.read();
m_protonData = WProtonData::SPtr( new WProtonData( csvDataSet->getHeader(), csvDataSet->getData() ) );
m_propertyStatus = boost::shared_ptr< WPropertyStatus >( new WPropertyStatus() );
WProtonData protonData( csvDataSet->getHeader(), csvDataSet->getData() );
m_propertyStatus->setColumnPropertyHandler( WColumnPropertyHandler::SPtr( new WColumnPropertyHandler( m_protonData, m_properties, NULL ) ) );
WModule::SPtr tmpColorBar( new WMTransferFunctionColorBar() );
m_propertyStatus->setFilterPropertyHandler( WFilterPropertyHandler::SPtr( new WFilterPropertyHandler( m_protonData, m_properties, NULL ) ) );
boost::shared_ptr< WPropertyStatus > tmpPropertyStatus( new WPropertyStatus() );
WColumnPropertyHandler tmpColumnPropertyHandler( NULL, NULL, NULL );
tmpPropertyStatus->setColumnPropertyHandler(
boost::make_shared< WColumnPropertyHandler>( tmpColumnPropertyHandler )
m_propertyStatus->setVisualizationPropertyHandler( WVisualizationPropertyHandler::SPtr(
new WVisualizationPropertyHandler( m_protonData, m_properties, NULL ) )
);
WEventIDLimitationPropertyHandler tmpEventIDLimitationPropertyHandler( NULL, NULL, NULL );
tmpPropertyStatus->setEventIDLimitationPropertyHandler(
boost::make_shared< WEventIDLimitationPropertyHandler>( tmpEventIDLimitationPropertyHandler )
m_propertyStatus->setEventIDLimitationPropertyHandler( WEventIDLimitationPropertyHandler::SPtr(
new WEventIDLimitationPropertyHandler( m_protonData, m_properties, NULL ) )
);
WFilterPropertyHandler tmpFilterPropertyHandler( NULL, NULL, NULL );
tmpPropertyStatus->setFilterPropertyHandler(
boost::make_shared< WFilterPropertyHandler>( tmpFilterPropertyHandler )
);
m_colorBar = WModule::SPtr( new WMTransferFunctionColorBar() );
//m_propertyStatus->getColumnPropertyHandler()->setSelectionEventMethod( nullptr );
}
WVisualizationPropertyHandler tmpVisualizationPropertyHandler( NULL, NULL, NULL );
tmpPropertyStatus->setVisualizationPropertyHandler(
boost::make_shared< WVisualizationPropertyHandler>( tmpVisualizationPropertyHandler )
);
/**
* Test the constructors of WCsvConverter, so no exception is thrown, when input parameters are correct
*/
void testConstructorThrowNothing()
{
TS_ASSERT_THROWS_NOTHING( WCsvConverter( m_protonData, m_propertyStatus, m_colorBar ) );
}
TS_ASSERT_THROWS_NOTHING( WCsvConverter( boost::make_shared< WProtonData >( protonData ),
tmpPropertyStatus,
tmpColorBar )
);
/**
* Tests the method getClusterSize()
*/
void testGetClusterSize()
{
WCsvConverter tmpCsvReader( m_protonData, m_propertyStatus, m_colorBar );
TS_ASSERT_EQUALS( tmpCsvReader.getClusterSize( 0.0f ), 0.0f );
TS_ASSERT_DELTA( tmpCsvReader.getClusterSize( 1.0f ), 36.11878927498844f, 1e-5 );
TS_ASSERT_DELTA( tmpCsvReader.getClusterSize( 1.0001f ), 36.1203073289856f, 1e-5 );
TS_ASSERT_IS_NAN( tmpCsvReader.getClusterSize( -0.0001f ) );
TS_ASSERT_IS_NAN( tmpCsvReader.getClusterSize( -1.0f ) );
}
/**
* Tests the method stringToDouble()
*/
void testStringToDouble()
{
std::map< std::string, double > testDoubleMap;
testDoubleMap.insert( std::pair< std::string, double >( "1000.1", 1000.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "1.", 1.0f ) );
testDoubleMap.insert( std::pair< std::string, double >( ".1", 0.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "2.1", 2.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "+1", 1.0f ) );
testDoubleMap.insert( std::pair< std::string, double >( "-1", -1.0f ) );
testDoubleMap.insert( std::pair< std::string, double >( "+.1", 0.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "-.1", -0.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "+1e-1", 0.1f ) );
testDoubleMap.insert( std::pair< std::string, double >( "0.001e-6", 0.000000001f ) );
testDoubleMap.insert( std::pair< std::string, double >( "0.111111111111111", 0.111111111111111f ) );
WCsvConverter tmpCsvReader( m_protonData, m_propertyStatus, m_colorBar );
for( std::pair< std::string, double > stringDoublePair : testDoubleMap )
{
TS_ASSERT_EQUALS( tmpCsvReader.stringToDouble( stringDoublePair.first ),
stringDoublePair.second );
}
TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "1.g" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "Test" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToDouble( "1.1.2" ), WException &e );
}
/**
* Tests the method stringToInt()
*/
void testStringToInt()
{
std::map< std::string, int > testIntMap;
testIntMap.insert( std::pair< std::string, int >( "1", 1 ) );
testIntMap.insert( std::pair< std::string, int >( "0", 0 ) );
testIntMap.insert( std::pair< std::string, int >( "10", 10 ) );
testIntMap.insert( std::pair< std::string, int >( "+1", 1 ) );
testIntMap.insert( std::pair< std::string, int >( "-1", -1 ) );
testIntMap.insert( std::pair< std::string, int >( "1e-1", 0 ) );
testIntMap.insert( std::pair< std::string, int >( "1e1", 10 ) );
testIntMap.insert( std::pair< std::string, int >( "+1e-1", 0 ) );
testIntMap.insert( std::pair< std::string, int >( "0.001e-6", 0 ) );
testIntMap.insert( std::pair< std::string, int >( "0.111111111111111", 0 ) );
WCsvConverter tmpCsvReader( m_protonData, m_propertyStatus, m_colorBar );
for( std::pair< std::string, int > stringIntPair : testIntMap )
{
TS_ASSERT_EQUALS( tmpCsvReader.stringToInt( stringIntPair.first ),
stringIntPair.second );
}
TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "1.g" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "Test" ), WException &e );
TS_ASSERT_THROWS( tmpCsvReader.stringToInt( "1.1.2" ), WException &e );
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment