source: trunk/test/matrix_weighted_test.cc @ 1607

Last change on this file since 1607 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

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