1989 |
12 Jun 09 |
peter |
// $Id$ |
1989 |
12 Jun 09 |
peter |
2 |
|
1989 |
12 Jun 09 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2012 Peter Johansson |
1989 |
12 Jun 09 |
peter |
5 |
|
1989 |
12 Jun 09 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1989 |
12 Jun 09 |
peter |
7 |
|
1989 |
12 Jun 09 |
peter |
The yat library is free software; you can redistribute it and/or |
1989 |
12 Jun 09 |
peter |
modify it under the terms of the GNU General Public License as |
1989 |
12 Jun 09 |
peter |
published by the Free Software Foundation; either version 3 of the |
1989 |
12 Jun 09 |
peter |
License, or (at your option) any later version. |
1989 |
12 Jun 09 |
peter |
12 |
|
1989 |
12 Jun 09 |
peter |
The yat library is distributed in the hope that it will be useful, |
1989 |
12 Jun 09 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1989 |
12 Jun 09 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1989 |
12 Jun 09 |
peter |
General Public License for more details. |
1989 |
12 Jun 09 |
peter |
17 |
|
1989 |
12 Jun 09 |
peter |
You should have received a copy of the GNU General Public License |
1989 |
12 Jun 09 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1989 |
12 Jun 09 |
peter |
20 |
*/ |
1989 |
12 Jun 09 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
1989 |
12 Jun 09 |
peter |
24 |
#include "Suite.h" |
1989 |
12 Jun 09 |
peter |
25 |
|
1989 |
12 Jun 09 |
peter |
26 |
#include "yat/utility/Matrix.h" |
1989 |
12 Jun 09 |
peter |
27 |
#include "yat/utility/MatrixWeighted.h" |
1989 |
12 Jun 09 |
peter |
28 |
#include "yat/utility/merge.h" |
1989 |
12 Jun 09 |
peter |
29 |
|
1989 |
12 Jun 09 |
peter |
30 |
#include <string> |
1989 |
12 Jun 09 |
peter |
31 |
#include <vector> |
1989 |
12 Jun 09 |
peter |
32 |
|
1989 |
12 Jun 09 |
peter |
33 |
using namespace theplu::yat; |
1989 |
12 Jun 09 |
peter |
34 |
template<class Container> |
1989 |
12 Jun 09 |
peter |
35 |
void test1(test::Suite&, const Container&, const std::vector<std::string>&, |
1989 |
12 Jun 09 |
peter |
36 |
const utility::Matrix&, const std::vector<std::string>&); |
1989 |
12 Jun 09 |
peter |
37 |
|
2000 |
13 Jun 09 |
peter |
38 |
template<class Container> |
2000 |
13 Jun 09 |
peter |
39 |
void test2(test::Suite&, const Container&, const std::vector<std::string>&); |
2000 |
13 Jun 09 |
peter |
40 |
|
2252 |
16 May 10 |
peter |
41 |
void compiler_tests(void); |
2252 |
16 May 10 |
peter |
42 |
|
1989 |
12 Jun 09 |
peter |
43 |
int main(int argc, char* argv[]) |
4200 |
19 Aug 22 |
peter |
44 |
{ |
1989 |
12 Jun 09 |
peter |
45 |
test::Suite suite(argc, argv); |
1989 |
12 Jun 09 |
peter |
46 |
suite.err() << "testing merge ... " << std::endl; |
1989 |
12 Jun 09 |
peter |
47 |
|
1989 |
12 Jun 09 |
peter |
48 |
utility::Matrix x(4,1,4); |
1989 |
12 Jun 09 |
peter |
49 |
x(1,0)=1; |
1989 |
12 Jun 09 |
peter |
50 |
std::vector<std::string> in(4, "monkey"); |
1989 |
12 Jun 09 |
peter |
51 |
in[2] = "banana"; |
1989 |
12 Jun 09 |
peter |
52 |
utility::Matrix y(2,1); |
1989 |
12 Jun 09 |
peter |
53 |
y(0,0)=4; |
1989 |
12 Jun 09 |
peter |
54 |
y(1,0)=3; |
1989 |
12 Jun 09 |
peter |
55 |
std::vector<std::string> out; |
1989 |
12 Jun 09 |
peter |
56 |
out.push_back("banana"); |
1989 |
12 Jun 09 |
peter |
57 |
out.push_back("monkey"); |
1989 |
12 Jun 09 |
peter |
58 |
test1(suite, x, in, y, out); |
1989 |
12 Jun 09 |
peter |
59 |
|
2000 |
13 Jun 09 |
peter |
60 |
utility::MatrixWeighted xw(x); |
2000 |
13 Jun 09 |
peter |
61 |
test1(suite, xw, in, y, out); |
2000 |
13 Jun 09 |
peter |
62 |
|
2252 |
16 May 10 |
peter |
63 |
if (false) // do nut run compiler tests |
2252 |
16 May 10 |
peter |
64 |
compiler_tests(); |
2252 |
16 May 10 |
peter |
65 |
|
1989 |
12 Jun 09 |
peter |
66 |
return suite.return_value(); |
1989 |
12 Jun 09 |
peter |
67 |
} |
1989 |
12 Jun 09 |
peter |
68 |
|
2252 |
16 May 10 |
peter |
69 |
|
2252 |
16 May 10 |
peter |
70 |
void compiler_tests(void) |
2252 |
16 May 10 |
peter |
71 |
{ |
2252 |
16 May 10 |
peter |
72 |
test::container2d_archetype<double> in; |
2252 |
16 May 10 |
peter |
73 |
test::container2d_archetype<utility::DataWeight> win; |
2252 |
16 May 10 |
peter |
74 |
std::vector<std::string> labels; |
2252 |
16 May 10 |
peter |
75 |
utility::Matrix out; |
2252 |
16 May 10 |
peter |
76 |
utility::MatrixWeighted wout; |
2252 |
16 May 10 |
peter |
77 |
statistics::Average averager; |
2252 |
16 May 10 |
peter |
78 |
merge(in, labels, out); |
2252 |
16 May 10 |
peter |
79 |
merge(win, labels, out); |
2252 |
16 May 10 |
peter |
80 |
merge(in, labels, wout, averager, averager); |
2252 |
16 May 10 |
peter |
81 |
merge(win, labels, wout, averager, averager); |
2252 |
16 May 10 |
peter |
82 |
|
2252 |
16 May 10 |
peter |
83 |
} |
2252 |
16 May 10 |
peter |
84 |
|
1989 |
12 Jun 09 |
peter |
85 |
template<class Container> |
4200 |
19 Aug 22 |
peter |
86 |
void test1(test::Suite& suite, const Container& x, |
1989 |
12 Jun 09 |
peter |
87 |
const std::vector<std::string>& in, |
4200 |
19 Aug 22 |
peter |
88 |
const utility::Matrix& correct_y, |
1989 |
12 Jun 09 |
peter |
89 |
const std::vector<std::string>& correct_out) |
1989 |
12 Jun 09 |
peter |
90 |
{ |
1989 |
12 Jun 09 |
peter |
91 |
std::vector<std::string> labels(in); |
1989 |
12 Jun 09 |
peter |
92 |
utility::Matrix result; |
1989 |
12 Jun 09 |
peter |
93 |
merge(x, labels, result); |
1989 |
12 Jun 09 |
peter |
94 |
|
1989 |
12 Jun 09 |
peter |
95 |
if (!suite.add(result.columns()==correct_y.columns())) |
1989 |
12 Jun 09 |
peter |
96 |
suite.err() << "number of columns is incorrect\n" |
1989 |
12 Jun 09 |
peter |
97 |
<< "expected " << correct_y.columns() << " " |
1989 |
12 Jun 09 |
peter |
98 |
<< "found " << result.columns() << "\n"; |
1989 |
12 Jun 09 |
peter |
99 |
else if (!suite.add(result.rows()==correct_y.rows())) |
1989 |
12 Jun 09 |
peter |
100 |
suite.err() << "number of rows is incorrect\n" |
1989 |
12 Jun 09 |
peter |
101 |
<< "expected " << correct_y.rows() << " " |
1989 |
12 Jun 09 |
peter |
102 |
<< "found " << result.rows() << "\n"; |
1989 |
12 Jun 09 |
peter |
103 |
else { |
4200 |
19 Aug 22 |
peter |
104 |
suite.add(suite.equal_range(result.begin(), result.end(), |
1989 |
12 Jun 09 |
peter |
105 |
correct_y.begin())); |
1989 |
12 Jun 09 |
peter |
106 |
} |
1990 |
12 Jun 09 |
peter |
107 |
if (!suite.add(labels==correct_out)) |
1990 |
12 Jun 09 |
peter |
108 |
suite.err() << "labels are incorrect\n"; |
1989 |
12 Jun 09 |
peter |
109 |
} |
1989 |
12 Jun 09 |
peter |
110 |
|
1989 |
12 Jun 09 |
peter |
111 |
|
2000 |
13 Jun 09 |
peter |
112 |
template<class Container> |
4200 |
19 Aug 22 |
peter |
113 |
void test2(test::Suite& suite, const Container& x, |
2000 |
13 Jun 09 |
peter |
114 |
const std::vector<std::string>& in) |
2000 |
13 Jun 09 |
peter |
115 |
{ |
2000 |
13 Jun 09 |
peter |
116 |
std::vector<std::string> labels(in); |
2000 |
13 Jun 09 |
peter |
117 |
utility::MatrixWeighted result; |
2000 |
13 Jun 09 |
peter |
// just a compilation test |
2000 |
13 Jun 09 |
peter |
119 |
merge(x, labels, result, statistics::Average(), statistics::Average()); |
2000 |
13 Jun 09 |
peter |
120 |
} |