OpenWalnut
1.4.0
|
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 WDENDROGRAM_TEST_H 00026 #define WDENDROGRAM_TEST_H 00027 00028 #include <cxxtest/TestSuite.h> 00029 00030 #include "../../WLogger.h" 00031 #include "../WDendrogram.h" 00032 00033 /** 00034 * TestSuite for the WDendrogram class 00035 */ 00036 class WDendrogramTest : public CxxTest::TestSuite 00037 { 00038 public: 00039 /** 00040 * Check if the dendrogram correctly constructs the txt string. <dfn>($level, ($childs,...), 00041 * ($left, $right), $similarity)\n</dfn> But for the leaves we have <dfn>(0, 00042 * ($tractNum,))\n</dfn>. 00043 \verbatim 00044 .----'----. 0.32 00045 | 8 | 00046 0.4 .---'---. | 00047 | 6 | .--'--. 0.6 00048 0.8 .--'--. | | 7 | 00049 | 5 | | | | 00050 | | | | | 00051 0 1 2 3 4 00052 \endverbatim 00053 */ 00054 void testStringCreation( void ) 00055 { 00056 WDendrogram d( 5 ); 00057 d.merge( 0, 1, 0.8 ); // 5 00058 d.merge( 5, 2, 0.4 ); // 6 00059 d.merge( 3, 4, 0.60 ); // 7 00060 d.merge( 6, 7, 0.32 ); // 8 00061 std::stringstream ss; 00062 ss << "(0, (0,))" << std::endl; 00063 ss << "(0, (1,))" << std::endl; 00064 ss << "(0, (2,))" << std::endl; 00065 ss << "(0, (3,))" << std::endl; 00066 ss << "(0, (4,))" << std::endl; 00067 ss << "(1, (0, 1), (0, 1), 0.8)" << std::endl; 00068 ss << "(2, (2, 0, 1), (2, 5), 0.4)" << std::endl; 00069 ss << "(1, (3, 4), (3, 4), 0.6)" << std::endl; 00070 ss << "(3, (2, 0, 1, 3, 4), (6, 7), 0.32)" << std::endl; 00071 if( ss.str() != d.toString() ) 00072 { 00073 std::cout << "Expected:" << std::endl << ss.str(); 00074 std::cout << "But got:" << std::endl << d.toString(); 00075 TS_FAIL( "Invalid dendrogram to string generation" ); 00076 } 00077 } 00078 00079 /** 00080 * Sets up the WLogger to properly log some thing... 00081 */ 00082 void setUp( void ) 00083 { 00084 WLogger::startup(); 00085 } 00086 }; 00087 00088 #endif // WDENDROGRAM_TEST_H