OpenWalnut  1.4.0
WFiber_test.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WFIBER_TEST_H
00026 #define WFIBER_TEST_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <cxxtest/TestSuite.h>
00032 
00033 #include "../../math/linearAlgebra/WPosition.h"
00034 #include "../WFiber.h"
00035 #include "WFiberTraits.h"
00036 
00037 /**
00038  * Unit tests our WFiber class
00039  */
00040 class WFiberTest : public CxxTest::TestSuite
00041 {
00042 public:
00043     /**
00044      * Two fibers are equal if they have equal WPositions in same order
00045      */
00046     void testEqualityOperator( void )
00047     {
00048         WFiber fib1;
00049         WFiber fib2;
00050         fib1.push_back( WPosition( 1.2, 3.4, 5.6 ) );
00051         fib1.push_back( WPosition( 7.8, 9.0, -1.2 ) );
00052         fib2.push_back( WPosition( 1.2, 3.4, 5.6 ) );
00053         fib2.push_back( WPosition( 7.8, 9.0, -1.2 ) );
00054         TS_ASSERT_EQUALS( fib1, fib2 );
00055     }
00056 
00057     /**
00058      * dLt(Q,R) chooses just the maximum out come of either dt(Q,r) or dt(R,Q)
00059      * and hence it is a symmetric metric.
00060      */
00061     void testDLTisSymmetric( void )
00062     {
00063         WFiber q;
00064         q.push_back( WPosition( 0, 1, 0 ) );
00065         q.push_back( WPosition( 0, 0, 0 ) );
00066         WFiber r;
00067         r.push_back( WPosition( 1, 1, 0 ) );
00068         r.push_back( WPosition( 2, 2, 0 ) );
00069 
00070         TS_ASSERT_EQUALS( WFiber::distDLT( 1.0, q, r ), std::sqrt( 5.0 ) / 2.0 );
00071         TS_ASSERT_EQUALS( WFiber::distDLT( 1.0, r, q ), std::sqrt( 5.0 ) / 2.0 );
00072     }
00073 
00074     /**
00075      * dSt(Q,R) chooses just the minimum outcome of either dt(Q,r) or dt(R,Q)
00076      * and hence it is a symmetric metric.
00077      */
00078     void testDSTisSymmetric( void )
00079     {
00080         WFiber q;
00081         q.push_back( WPosition( 0, 1, 0 ) );
00082         q.push_back( WPosition( 0, 0, 0 ) );
00083         WFiber r;
00084         r.push_back( WPosition( 1, 1, 0 ) );
00085         r.push_back( WPosition( 2, 2, 0 ) );
00086 
00087         TS_ASSERT_EQUALS( WFiber::distDST( 1.0, q, r ), std::sqrt( 2.0 ) / 2.0 );
00088         TS_ASSERT_EQUALS( WFiber::distDST( 1.0, r, q ), std::sqrt( 2.0 ) / 2.0 );
00089     }
00090 
00091     /**
00092      * The dt(Q,R) measure (mean closest point distance) is not symmetric.
00093      * distances below a certain threshold will be omitted.
00094      */
00095     void testDTMeasure( void )
00096     {
00097         WFiber q;
00098         q.push_back( WPosition( 0, 1, 0 ) );
00099         q.push_back( WPosition( 0, 0, 0 ) );
00100         WFiber r;
00101         r.push_back( WPosition( 1, 1, 0 ) );
00102         r.push_back( WPosition( 2, 2, 0 ) );
00103 
00104         TS_ASSERT_EQUALS( WFiber::distDST( 1.0, q, r ), std::sqrt( 2.0 ) / 2.0 );
00105         TS_ASSERT_EQUALS( WFiber::distDLT( 1.0, q, r ), std::sqrt( 5.0 ) / 2.0 );
00106     }
00107 };
00108 
00109 #endif  // WFIBER_TEST_H