WVisiTrace_test.h 4.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2017 OpenWalnut Community and Hochschule Worms
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WVISITRACE_TEST_H
#define WVISITRACE_TEST_H

#include <utility>
#include <vector>

#include <cxxtest/TestSuite.h>

#include "../WVisiTrace.h"
34
#include "../../../core/common/math/test/WPositionTraits.h"
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

/**
 * Test for WMWriteMesh
 */
class WVisiTraceTest : public CxxTest::TestSuite
{
public:
    /**
     * Setup method called before every test case.
     */
    void setUp()
    {
    }

    /**
50
     * Ensure instantiation does not throw and does initialization right.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
     */
    void testInstatiation()
    {
        TS_ASSERT_THROWS_NOTHING( WVisiTrace() );
    }

    /**
     * Ensure that getline does not return anything until something is added.
     */
    void testGetLineOfInitial()
    {
        WVisiTrace myVisiTrace;
        std::vector< WPosition > line = myVisiTrace.getLine();
        TS_ASSERT_EQUALS( line.size(), 0 );
    }

    /**
     * Check correct order resulting from getLinearizedNodesRefs
     */
    void testLinearization()
    {
        WVisiTrace myVisiTrace;
        std::vector< std::vector< WPosition > > candidates;
74
        const std::vector< int > sizes = { 4, 2, 5, 8, 3, 6 };
75 76 77 78 79 80 81 82 83 84 85
        for( size_t id = 0; id < sizes.size(); ++id )
        {
            myVisiTrace.m_candidatePositions.push_back( std::vector< WPosition >( sizes[id] ) );
        }

        std::vector< std::pair< int, int > > order = myVisiTrace.getLinearizedNodesRefs();

        TS_ASSERT_EQUALS( order.size(), 28 );

        TS_ASSERT_EQUALS( order[0], std::make_pair( 0, 0 ) );
        TS_ASSERT_EQUALS( order[1], std::make_pair( 0, 1 ) );
86 87
        TS_ASSERT_EQUALS( order[2], std::make_pair( 0, 2 ) );
        TS_ASSERT_EQUALS( order[3], std::make_pair( 0, 3 ) );
88

89
         TS_ASSERT_EQUALS( order[5], std::make_pair( 1, 1 ) );
90 91 92 93 94 95 96 97 98 99 100 101
        TS_ASSERT_EQUALS( order[6], std::make_pair( 2, 0 ) );

        TS_ASSERT_EQUALS( order[27], std::make_pair( 5, 5 ) );
    }

    /**
     * Check getLinearizedNodesRefs
     */
    void testInverseLinearization()
    {
        WVisiTrace myVisiTrace;
        std::vector< std::vector< WPosition > > candidates;
102
        const std::vector< int > sizes = { 4, 2, 5, 8, 3, 6 };
103 104 105 106 107 108 109 110 111 112 113
        for( size_t id = 0; id < sizes.size(); ++id )
        {
            myVisiTrace.m_candidatePositions.push_back( std::vector< WPosition >( sizes[id] ) );
        }

        std::vector< std::vector< int > > inverseRefs = myVisiTrace.getInverseLinearizedNodesRefs();

        TS_ASSERT_EQUALS( inverseRefs.size(), 6 );

        TS_ASSERT_EQUALS( inverseRefs[0][0], 0 );
        TS_ASSERT_EQUALS( inverseRefs[0][1], 1 );
114 115
        TS_ASSERT_EQUALS( inverseRefs[0][2], 2 );
        TS_ASSERT_EQUALS( inverseRefs[0][3], 3 );
116

117 118
        TS_ASSERT_EQUALS( inverseRefs[1][0], 4 );
        TS_ASSERT_EQUALS( inverseRefs[1][1], 5 );
119 120 121 122 123

        TS_ASSERT_EQUALS( inverseRefs[2][0], 6 );

        TS_ASSERT_EQUALS( inverseRefs[5][5], 27 );
    }
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    /**
     * Check throwing of Dijkstra
     */
    void testPerformDijkstraException()
    {
        WVisiTrace myVisiTrace;

        myVisiTrace.m_candidatePositions.push_back(
            {
                WPosition( 1, 0, 0 ),
                WPosition( 1, 0, 1 ),
                WPosition( 1, 0, 2 ),
                WPosition( 1, 0, 3 )
            }
            );
        myVisiTrace.m_candidatePositions.push_back(
            {
                WPosition( 1, 1, -3.5 ),
                WPosition( 1, 1, -2.5 )
            } );
        myVisiTrace.m_candidatePositions.push_back(
            {
                WPosition( 1, 1.2, 0 ),
                WPosition( 1, 1.2, 1 ),
                WPosition( 1, 1.2, 2 ),
                WPosition( 1, 1.2, 3 )
            }
            );

        TS_ASSERT_THROWS_NOTHING( myVisiTrace.performDijkstra() );
        TS_ASSERT_EQUALS( myVisiTrace.m_curve3D[0], WPosition( 1, 0, 0 ) );
156 157
        TS_ASSERT_EQUALS( myVisiTrace.m_curve3D[1], WPosition( 1, 1, -2.5 ) );
        TS_ASSERT_EQUALS( myVisiTrace.m_curve3D[2], WPosition( 1, 1.2, 0 ) );
158
    }
159 160 161
};

#endif  // WVISITRACE_TEST_H