OpenWalnut
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
core
common
datastructures
test
WDendrogram_test.h
1
//---------------------------------------------------------------------------
2
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
4
//
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
7
//
8
// This file is part of OpenWalnut.
9
//
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22
//
23
//---------------------------------------------------------------------------
24
25
#ifndef WDENDROGRAM_TEST_H
26
#define WDENDROGRAM_TEST_H
27
28
#include <cxxtest/TestSuite.h>
29
30
#include "../../WLogger.h"
31
#include "../WDendrogram.h"
32
33
/**
34
* TestSuite for the WDendrogram class
35
*/
36
class
WDendrogramTest
:
public
CxxTest::TestSuite
37
{
38
public
:
39
/**
40
* Check if the dendrogram correctly constructs the txt string. <dfn>($level, ($childs,...),
41
* ($left, $right), $similarity)\n</dfn> But for the leaves we have <dfn>(0,
42
* ($tractNum,))\n</dfn>.
43
\verbatim
44
.----'----. 0.32
45
| 8 |
46
0.4 .---'---. |
47
| 6 | .--'--. 0.6
48
0.8 .--'--. | | 7 |
49
| 5 | | | |
50
| | | | |
51
0 1 2 3 4
52
\endverbatim
53
*/
54
void
testStringCreation
(
void
)
55
{
56
WDendrogram
d( 5 );
57
d.
merge
( 0, 1, 0.8 );
// 5
58
d.
merge
( 5, 2, 0.4 );
// 6
59
d.
merge
( 3, 4, 0.60 );
// 7
60
d.
merge
( 6, 7, 0.32 );
// 8
61
std::stringstream ss;
62
ss <<
"(0, (0,))"
<< std::endl;
63
ss <<
"(0, (1,))"
<< std::endl;
64
ss <<
"(0, (2,))"
<< std::endl;
65
ss <<
"(0, (3,))"
<< std::endl;
66
ss <<
"(0, (4,))"
<< std::endl;
67
ss <<
"(1, (0, 1), (0, 1), 0.8)"
<< std::endl;
68
ss <<
"(2, (2, 0, 1), (2, 5), 0.4)"
<< std::endl;
69
ss <<
"(1, (3, 4), (3, 4), 0.6)"
<< std::endl;
70
ss <<
"(3, (2, 0, 1, 3, 4), (6, 7), 0.32)"
<< std::endl;
71
if
( ss.str() != d.
toString
() )
72
{
73
std::cout <<
"Expected:"
<< std::endl << ss.str();
74
std::cout <<
"But got:"
<< std::endl << d.
toString
();
75
TS_FAIL(
"Invalid dendrogram to string generation"
);
76
}
77
}
78
79
/**
80
* Sets up the WLogger to properly log some thing...
81
*/
82
void
setUp
(
void
)
83
{
84
WLogger::startup
();
85
}
86
};
87
88
#endif // WDENDROGRAM_TEST_H
Generated by
1.8.3.1