source: trunk/test/matrix_weighted_test.cc @ 2143

Last change on this file since 2143 was 2143, checked in by Peter, 13 years ago

fixes #449

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