source: trunk/test/matrix_weighted_test.cc @ 2119

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

converted files to utf-8. fixes #577

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: matrix_weighted_test.cc 2119 2009-12-12 23:11:43Z 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_swap(test::Suite& suite);
36
37int main(int argc, char* argv[])
38{
39  test::Suite suite(argc, argv);
40
41  test_constructor_void(suite);
42  test_constructor_const(suite);
43  test_constructor_matrix(suite);
44  test_swap(suite);
45
46  suite.return_value();
47}
48
49
50void test_constructor_const(test::Suite& suite)
51{
52  suite.err() << "testing MatrixWeighted(size_t, size_t , double, double)" 
53              << std::endl;
54  MatrixWeighted x(10, 20, 1.0, 0.92);
55  suite.add(x.columns()==20);
56  suite.add(x.rows()==10);
57  for (size_t i=0; i<x.rows(); ++i)
58    for (size_t j=0; j<x.columns(); ++j) {
59      suite.add(suite.equal(x(i,j).data(),1.0));
60      suite.add(suite.equal(x(i,j).weight(),0.92));
61    }
62}
63
64
65void test_constructor_matrix(test::Suite& suite)
66{
67  suite.err() << "testing MatrixWeighted(const Matrix&)" << std::endl;
68  utility::Matrix x(2,3,1.12);
69  x(0,0)=0.93;
70  utility::MatrixWeighted xw(x);
71  if (x.columns()==xw.columns() && x.rows()==xw.rows()) {
72    for (size_t i=0; i<xw.rows(); ++i)
73      for (size_t j=0; j<xw.columns(); ++j) {
74        suite.add(suite.equal(xw(i,j).data(), x(i,j)));
75        suite.add(suite.equal(xw(i,j).weight(), 1.0));
76      }
77  }
78  else {
79    suite.add(false);
80    suite.err() << "ERROR: sizes mismatch" << std::endl;
81    suite.err() << "  MatrixWeighted is " << xw.rows() << " x " << xw.columns()
82                << std::endl;
83    suite.err() << "  expected " << x.rows() << " x " << x.columns()
84                << std::endl;
85  }
86 
87}
88
89
90void test_constructor_void(test::Suite& suite)
91{
92  MatrixWeighted x;
93  suite.add(x.columns()==0);
94  suite.add(x.rows()==0);
95}
96
97void test_swap(test::Suite& suite)
98{
99  MatrixWeighted x(3,10);
100  MatrixWeighted y(0,0);
101  x.swap(y);
102  suite.add(x.columns()==0);
103  suite.add(x.rows()==0);
104  suite.add(y.columns()==10);
105  suite.add(y.rows()==3);
106}
107
108
Note: See TracBrowser for help on using the repository browser.