source: trunk/test/matrix_weighted_test.cc @ 1483

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

refs #396 - removing a constructor in MatrixLookupWeighted? - needed to re-organize tests in ncc_test to track down an error

  • 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 1483 2008-09-09 16:03:15Z peter $
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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Suite.h"
25
26#include "yat/utility/Matrix.h"
27#include "yat/utility/MatrixWeighted.h"
28
29#include <string>
30
31using namespace theplu::yat;
32using utility::MatrixWeighted;
33void test_constructor_void(test::Suite& suite);
34void test_constructor_const(test::Suite& suite);
35void test_constructor_matrix(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
45  suite.return_value();
46}
47
48
49void test_constructor_const(test::Suite& suite)
50{
51  suite.err() << "testing MatrixWeighted(size_t, size_t , double, double)" 
52              << std::endl;
53  MatrixWeighted x(10, 20, 1.0, 0.92);
54  suite.add(x.columns()==20);
55  suite.add(x.rows()==10);
56  for (size_t i=0; i<x.rows(); ++i)
57    for (size_t j=0; j<x.columns(); ++j) {
58      suite.add(suite.equal(x(i,j).data(),1.0));
59      suite.add(suite.equal(x(i,j).weight(),0.92));
60    }
61}
62
63
64void test_constructor_matrix(test::Suite& suite)
65{
66  suite.err() << "testing MatrixWeighted(const Matrix&)" << std::endl;
67  utility::Matrix x(2,3,1.12);
68  x(0,0)=0.93;
69  utility::MatrixWeighted xw(x);
70  if (x.columns()==xw.columns() && x.rows()==xw.rows()) {
71    for (size_t i=0; i<xw.rows(); ++i)
72      for (size_t j=0; j<xw.columns(); ++j) {
73        suite.add(suite.equal(xw(i,j).data(), x(i,j)));
74        suite.add(suite.equal(xw(i,j).weight(), 1.0));
75      }
76  }
77  else {
78    suite.add(false);
79    suite.err() << "ERROR: sizes mismatch" << std::endl;
80    suite.err() << "  MatrixWeighted is " << xw.rows() << " x " << xw.columns()
81                << std::endl;
82    suite.err() << "  expected " << x.rows() << " x " << x.columns()
83                << std::endl;
84  }
85 
86}
87
88
89void test_constructor_void(test::Suite& suite)
90{
91  MatrixWeighted x;
92  suite.add(x.columns()==0);
93  suite.add(x.rows()==0);
94}
95
96
Note: See TracBrowser for help on using the repository browser.