1483 |
09 Sep 08 |
peter |
// $Id$ |
1483 |
09 Sep 08 |
peter |
2 |
|
1483 |
09 Sep 08 |
peter |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2012 Peter Johansson |
1483 |
09 Sep 08 |
peter |
6 |
|
1483 |
09 Sep 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1483 |
09 Sep 08 |
peter |
8 |
|
1483 |
09 Sep 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1483 |
09 Sep 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1483 |
09 Sep 08 |
peter |
License, or (at your option) any later version. |
1483 |
09 Sep 08 |
peter |
13 |
|
1483 |
09 Sep 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1483 |
09 Sep 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1483 |
09 Sep 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1483 |
09 Sep 08 |
peter |
General Public License for more details. |
1483 |
09 Sep 08 |
peter |
18 |
|
1483 |
09 Sep 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1483 |
09 Sep 08 |
peter |
21 |
*/ |
1483 |
09 Sep 08 |
peter |
22 |
|
2881 |
18 Nov 12 |
peter |
23 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
24 |
|
1483 |
09 Sep 08 |
peter |
25 |
#include "Suite.h" |
1483 |
09 Sep 08 |
peter |
26 |
|
1483 |
09 Sep 08 |
peter |
27 |
#include "yat/utility/Matrix.h" |
1483 |
09 Sep 08 |
peter |
28 |
#include "yat/utility/MatrixWeighted.h" |
1483 |
09 Sep 08 |
peter |
29 |
|
1483 |
09 Sep 08 |
peter |
30 |
#include <string> |
1483 |
09 Sep 08 |
peter |
31 |
|
1483 |
09 Sep 08 |
peter |
32 |
using namespace theplu::yat; |
1483 |
09 Sep 08 |
peter |
33 |
using utility::MatrixWeighted; |
1483 |
09 Sep 08 |
peter |
34 |
void test_constructor_void(test::Suite& suite); |
1483 |
09 Sep 08 |
peter |
35 |
void test_constructor_const(test::Suite& suite); |
1483 |
09 Sep 08 |
peter |
36 |
void test_constructor_matrix(test::Suite& suite); |
2143 |
15 Jan 10 |
peter |
37 |
void test_concepts(test::Suite& suite); |
1706 |
08 Jan 09 |
peter |
38 |
void test_swap(test::Suite& suite); |
1483 |
09 Sep 08 |
peter |
39 |
|
1483 |
09 Sep 08 |
peter |
40 |
int main(int argc, char* argv[]) |
1483 |
09 Sep 08 |
peter |
41 |
{ |
1483 |
09 Sep 08 |
peter |
42 |
test::Suite suite(argc, argv); |
1483 |
09 Sep 08 |
peter |
43 |
|
1483 |
09 Sep 08 |
peter |
44 |
test_constructor_void(suite); |
1483 |
09 Sep 08 |
peter |
45 |
test_constructor_const(suite); |
1483 |
09 Sep 08 |
peter |
46 |
test_constructor_matrix(suite); |
1706 |
08 Jan 09 |
peter |
47 |
test_swap(suite); |
2143 |
15 Jan 10 |
peter |
48 |
test_concepts(suite); |
1483 |
09 Sep 08 |
peter |
49 |
|
1483 |
09 Sep 08 |
peter |
50 |
suite.return_value(); |
1483 |
09 Sep 08 |
peter |
51 |
} |
1483 |
09 Sep 08 |
peter |
52 |
|
1483 |
09 Sep 08 |
peter |
53 |
|
2143 |
15 Jan 10 |
peter |
54 |
void test_concepts(test::Suite& suite) |
2143 |
15 Jan 10 |
peter |
55 |
{ |
2143 |
15 Jan 10 |
peter |
56 |
const MatrixWeighted const_m(2,2,0); |
2143 |
15 Jan 10 |
peter |
57 |
MatrixWeighted mutable_m(2,2,0); |
2143 |
15 Jan 10 |
peter |
// concept compiler tests |
2143 |
15 Jan 10 |
peter |
59 |
suite.test_concept_container2d(const_m); |
2143 |
15 Jan 10 |
peter |
60 |
suite.test_concept_mutable_container2d(mutable_m); |
2143 |
15 Jan 10 |
peter |
61 |
} |
2143 |
15 Jan 10 |
peter |
62 |
|
2143 |
15 Jan 10 |
peter |
63 |
|
1483 |
09 Sep 08 |
peter |
64 |
void test_constructor_const(test::Suite& suite) |
1483 |
09 Sep 08 |
peter |
65 |
{ |
4200 |
19 Aug 22 |
peter |
66 |
suite.err() << "testing MatrixWeighted(size_t, size_t , double, double)" |
1483 |
09 Sep 08 |
peter |
67 |
<< std::endl; |
1483 |
09 Sep 08 |
peter |
68 |
MatrixWeighted x(10, 20, 1.0, 0.92); |
1483 |
09 Sep 08 |
peter |
69 |
suite.add(x.columns()==20); |
1483 |
09 Sep 08 |
peter |
70 |
suite.add(x.rows()==10); |
1483 |
09 Sep 08 |
peter |
71 |
for (size_t i=0; i<x.rows(); ++i) |
1483 |
09 Sep 08 |
peter |
72 |
for (size_t j=0; j<x.columns(); ++j) { |
1483 |
09 Sep 08 |
peter |
73 |
suite.add(suite.equal(x(i,j).data(),1.0)); |
1483 |
09 Sep 08 |
peter |
74 |
suite.add(suite.equal(x(i,j).weight(),0.92)); |
1483 |
09 Sep 08 |
peter |
75 |
} |
1483 |
09 Sep 08 |
peter |
76 |
} |
1483 |
09 Sep 08 |
peter |
77 |
|
1483 |
09 Sep 08 |
peter |
78 |
|
1483 |
09 Sep 08 |
peter |
79 |
void test_constructor_matrix(test::Suite& suite) |
1483 |
09 Sep 08 |
peter |
80 |
{ |
1483 |
09 Sep 08 |
peter |
81 |
suite.err() << "testing MatrixWeighted(const Matrix&)" << std::endl; |
1483 |
09 Sep 08 |
peter |
82 |
utility::Matrix x(2,3,1.12); |
1483 |
09 Sep 08 |
peter |
83 |
x(0,0)=0.93; |
1483 |
09 Sep 08 |
peter |
84 |
utility::MatrixWeighted xw(x); |
1483 |
09 Sep 08 |
peter |
85 |
if (x.columns()==xw.columns() && x.rows()==xw.rows()) { |
1483 |
09 Sep 08 |
peter |
86 |
for (size_t i=0; i<xw.rows(); ++i) |
1483 |
09 Sep 08 |
peter |
87 |
for (size_t j=0; j<xw.columns(); ++j) { |
1483 |
09 Sep 08 |
peter |
88 |
suite.add(suite.equal(xw(i,j).data(), x(i,j))); |
1483 |
09 Sep 08 |
peter |
89 |
suite.add(suite.equal(xw(i,j).weight(), 1.0)); |
1483 |
09 Sep 08 |
peter |
90 |
} |
1483 |
09 Sep 08 |
peter |
91 |
} |
1483 |
09 Sep 08 |
peter |
92 |
else { |
1483 |
09 Sep 08 |
peter |
93 |
suite.add(false); |
1483 |
09 Sep 08 |
peter |
94 |
suite.err() << "ERROR: sizes mismatch" << std::endl; |
1483 |
09 Sep 08 |
peter |
95 |
suite.err() << " MatrixWeighted is " << xw.rows() << " x " << xw.columns() |
1483 |
09 Sep 08 |
peter |
96 |
<< std::endl; |
1483 |
09 Sep 08 |
peter |
97 |
suite.err() << " expected " << x.rows() << " x " << x.columns() |
1483 |
09 Sep 08 |
peter |
98 |
<< std::endl; |
1483 |
09 Sep 08 |
peter |
99 |
} |
4200 |
19 Aug 22 |
peter |
100 |
|
1483 |
09 Sep 08 |
peter |
101 |
} |
1483 |
09 Sep 08 |
peter |
102 |
|
1483 |
09 Sep 08 |
peter |
103 |
|
1483 |
09 Sep 08 |
peter |
104 |
void test_constructor_void(test::Suite& suite) |
1483 |
09 Sep 08 |
peter |
105 |
{ |
1483 |
09 Sep 08 |
peter |
106 |
MatrixWeighted x; |
1483 |
09 Sep 08 |
peter |
107 |
suite.add(x.columns()==0); |
1483 |
09 Sep 08 |
peter |
108 |
suite.add(x.rows()==0); |
1483 |
09 Sep 08 |
peter |
109 |
} |
1483 |
09 Sep 08 |
peter |
110 |
|
1706 |
08 Jan 09 |
peter |
111 |
void test_swap(test::Suite& suite) |
1706 |
08 Jan 09 |
peter |
112 |
{ |
1706 |
08 Jan 09 |
peter |
113 |
MatrixWeighted x(3,10); |
1706 |
08 Jan 09 |
peter |
114 |
MatrixWeighted y(0,0); |
1706 |
08 Jan 09 |
peter |
115 |
x.swap(y); |
1706 |
08 Jan 09 |
peter |
116 |
suite.add(x.columns()==0); |
1706 |
08 Jan 09 |
peter |
117 |
suite.add(x.rows()==0); |
1706 |
08 Jan 09 |
peter |
118 |
suite.add(y.columns()==10); |
1706 |
08 Jan 09 |
peter |
119 |
suite.add(y.rows()==3); |
1706 |
08 Jan 09 |
peter |
120 |
} |