Tudat/InputOutput/UnitTests/unitTestMapTextFileReader.cpp
// Test if matrix text file reader is working correctly.
Test if matrix text file reader is working correctly.
Test if matrix text file reader is working correctly .
BOOST_AUTO_TEST_CASE( testMatrixTextFileReader )
{
    {
        std::map< int, std::vector< int > > expectedMap = {
            { 1, { 1, 2 } },
            { 2, { 1, 2, 4 } },
            { 3, { 1, 2, 4, 8 } },
            { 4, { 1, 2, 4, 8, 16 } }
        };
        auto inputFileMap = input_output::readStlVectorMapFromFile< int, int >(
                    input_output::getTudatRootPath( ) + "/InputOutput/UnitTests/testMap1.txt" );
        bool allEqual = true;
        try
        {
            for ( auto ent: inputFileMap )
            {
                auto key = ent.first;
                auto values = ent.second;
                for ( unsigned int i = 0; i < values.size(); i++ )
                {
                    if ( inputFileMap[ key ][ i ] != expectedMap[ key ][ i ] )
                    {
                        std::cout << "Element at " << i << " for key " << key << " ("
                                  << inputFileMap[ key ][ i ] << ") does not match expected value of "
                                  << "(" << expectedMap[ key ][ i ] << ")." << std::endl;
                        allEqual = false;
                        break;
                    }
                }
                if ( ! allEqual )
                {
                    break;
                }
            }
        }
        catch( std::runtime_error &inconsistentSizes )
        {
            std::cout << "Maps have different keys or inconsistent sizes." << std::endl;
            allEqual = false;
        }
        BOOST_CHECK( allEqual );
    }
    {
        std::map< double, std::vector< float > > expectedMap = {
            { 0.0, {  0.5, 0.8 } },
            { 0.1, { -0.5, 1.0 } },
            { 0.2, {  0.5 } },
            { 0.3, {  1e6, 1.0, 1.0 } }
        };
        auto inputFileMap = input_output::readStlVectorMapFromFile< double, float >(
                    input_output::getTudatRootPath( ) + "/InputOutput/UnitTests/testMap2.txt" );
        bool allEqual = true;
        try
        {
            for ( auto ent: inputFileMap )
            {
                auto key = ent.first;
                auto values = ent.second;
                for ( unsigned int i = 0; i < values.size(); i++ )
                {
                    if ( inputFileMap[ key ][ i ] != expectedMap[ key ][ i ] )
                    {
                        std::cout << "Element at " << i << " for key " << key << " ("
                                  << inputFileMap[ key ][ i ] << ") does not match expected value of "
                                  << "(" << expectedMap[ key ][ i ] << ")." << std::endl;
                        allEqual = false;
                        break;
                    }
                }
                if ( ! allEqual )
                {
                    break;
                }
            }
        }
        catch( std::runtime_error &inconsistentSizes )
        {
            std::cout << "Maps have different keys or inconsistent sizes." << std::endl;
            allEqual = false;
        }
        BOOST_CHECK( allEqual );
    }
    {
        std::map< std::string, std::vector< std::string > > expectedMap = {
            { "x", { "one", "two" } },
            { "y", { "three", "four", "five" } },
            { "z", { "six" } }
        };
        auto inputFileMap = input_output::readStlVectorMapFromFile< std::string, std::string >(
                    input_output::getTudatRootPath( ) + "/InputOutput/UnitTests/testMap3.txt" );
        bool allEqual = true;
        try
        {
            for ( auto ent: inputFileMap )
            {
                auto key = ent.first;
                auto values = ent.second;
                for ( unsigned int i = 0; i < values.size(); i++ )
                {
                    if ( inputFileMap[ key ][ i ] != expectedMap[ key ][ i ] )
                    {
                        std::cout << "Element at " << i << " for key " << key << " ("
                                  << inputFileMap[ key ][ i ] << ") does not match expected value of "
                                  << "(" << expectedMap[ key ][ i ] << ")." << std::endl;
                        allEqual = false;
                        break;
                    }
                }
                if ( ! allEqual )
                {
                    break;
                }
            }
        }
        catch( std::runtime_error &inconsistentSizes )
        {
            std::cout << "Maps have different keys or inconsistent sizes." << std::endl;
            allEqual = false;
        }
        BOOST_CHECK( allEqual );
    }
}
BOOST_AUTO_TEST_CASE ( testMatrixTextFileReader ) { { std :: map < int , std :: vector < int > > expectedMap = { { 1 , { 1 , 2 } } , { 2 , { 1 , 2 , 4 } } , { 3 , { 1 , 2 , 4 , 8 } } , { 4 , { 1 , 2 , 4 , 8 , 16 } } } ; auto inputFileMap = input_output :: readStlVectorMapFromFile < int , int > ( input_output :: getTudatRootPath ( ) + " " ) ; bool allEqual = true ; try { for ( auto ent : inputFileMap ) { auto key = ent . first ; auto values = ent . second ; for ( unsigned int i = 0 ; i < values . size ( ) ; i ++ ) { if ( inputFileMap [ key ] [ i ] != expectedMap [ key ] [ i ] ) { std :: cout << " " << i << " " << key << " " << inputFileMap [ key ] [ i ] << " " << " " << expectedMap [ key ] [ i ] << " " << std :: endl ; allEqual = false ; break ; } } if ( ! allEqual ) { break ; } } } catch ( std :: runtime_error & inconsistentSizes ) { std :: cout << " " << std :: endl ; allEqual = false ; } BOOST_CHECK ( allEqual ) ; } { std :: map < double , std :: vector < float > > expectedMap = { { 0.0 , { 0.5 , 0.8 } } , { 0.1 , { -0.5 , 1.0 } } , { 0.2 , { 0.5 } } , { 0.3 , { 1e6 , 1.0 , 1.0 } } } ; auto inputFileMap = input_output :: readStlVectorMapFromFile < double , float > ( input_output :: getTudatRootPath ( ) + " " ) ; bool allEqual = true ; try { for ( auto ent : inputFileMap ) { auto key = ent . first ; auto values = ent . second ; for ( unsigned int i = 0 ; i < values . size ( ) ; i ++ ) { if ( inputFileMap [ key ] [ i ] != expectedMap [ key ] [ i ] ) { std :: cout << " " << i << " " << key << " " << inputFileMap [ key ] [ i ] << " " << " " << expectedMap [ key ] [ i ] << " " << std :: endl ; allEqual = false ; break ; } } if ( ! allEqual ) { break ; } } } catch ( std :: runtime_error & inconsistentSizes ) { std :: cout << " " << std :: endl ; allEqual = false ; } BOOST_CHECK ( allEqual ) ; } { std :: map < std :: string , std :: vector < std :: string > > expectedMap = { { " " , { " " , " " } } , { " " , { " " , " " , " " } } , { " " , { " " } } } ; auto inputFileMap = input_output :: readStlVectorMapFromFile < std :: string , std :: string > ( input_output :: getTudatRootPath ( ) + " " ) ; bool allEqual = true ; try { for ( auto ent : inputFileMap ) { auto key = ent . first ; auto values = ent . second ; for ( unsigned int i = 0 ; i < values . size ( ) ; i ++ ) { if ( inputFileMap [ key ] [ i ] != expectedMap [ key ] [ i ] ) { std :: cout << " " << i << " " << key << " " << inputFileMap [ key ] [ i ] << " " << " " << expectedMap [ key ] [ i ] << " " << std :: endl ; allEqual = false ; break ; } } if ( ! allEqual ) { break ; } } } catch ( std :: runtime_error & inconsistentSizes ) { std :: cout << " " << std :: endl ; allEqual = false ; } BOOST_CHECK ( allEqual ) ; } }
Test if matrix text file reader is working correctly.
Test if matrix text file reader is working correctly .
// Test 1 // Set expected matrix. // Read input file and store data in matrix. // Check if data input file matrix matches expected matrix. // Test 2 // Set expected matrix. // Read input file and store data in matrix. // Check if data input file matrix matches expected matrix. // Test 1 // Set expected matrix. // Read input file and store data in matrix. // Check if data input file matrix matches expected matrix.