source: trunk/test/view_test.cc @ 1797

Last change on this file since 1797 was 1797, checked in by Peter, 12 years ago

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1// $Id: view_test.cc 1797 2009-02-12 18:07:10Z 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/VectorBase.h"
27#include "yat/utility/VectorMutable.h"
28#include "yat/utility/VectorView.h"
29#include "yat/utility/VectorConstView.h"
30
31#include <fstream>
32#include <iostream>
33#include <string>
34
35using namespace theplu::yat;
36void test_rvalue(test::Suite&);
37void test_rvalue_func(test::Suite& suite, const utility::VectorBase& vec);
38
39int main(int argc, char* argv[])
40{ 
41  using namespace theplu::yat::utility;
42  theplu::yat::test::Suite suite(argc, argv);
43  suite.err() << "testing vector" << std::endl;
44
45  Matrix data1;
46  data1.resize(3,1);
47  for(size_t i=0;i<3;i++) {
48    data1(i,0)=7+i;
49  }
50 
51
52  Matrix data2(3,1,1.0);
53
54  VectorConstView a=data1.column_const_view(0);
55  VectorView b=data2.column_view(0);
56  VectorView bajs(data2, 0, false);
57  if (a(0)!=data1(0,0)){
58    suite.err() << "Matrix::column_const_view failed\n";
59    suite.add(false);
60  }
61  if (b(0)!=data2(0,0)){
62    suite.err() << "Matrix::column_view failed\n";
63    suite.add(false);
64  }
65
66  data1.column_const_view(0);
67  if (b.size()!=3){
68    suite.add(false);
69    suite.err() << "ERROR: expected size to be 3 - found " << b.size() << std::endl;
70  }
71  if ( !(b(0)==1 && b(1)==(1) && b(2)==1) )
72    suite.add(false);
73
74  if (a.begin()!=data1.begin_column(0)){
75    suite.add(false);
76    suite.err() << "VectorConstView::begin should equal " 
77             << "Matrix::begin_column(size_t)\n";
78  }
79  if (a.end()!=data1.end_column(0)) {
80    suite.add(false);
81    suite.err() << "VectorConstView::end should equal " 
82             << "Matrix::end_column(size_t)\n";
83  }
84  if (b.begin()!=data2.begin_column(0)){
85    suite.add(false);
86    suite.err() << "VectorView::begin " 
87             << b.begin().base() << " should equal\n"
88             << "Matrix::begin_column(size_t) "
89             << data1.begin_column(0).base() << std::endl;
90  }
91  if (b.end()!=data2.end_column(0)){
92    suite.add(false);
93    suite.err() << "VectorView::end should equal " 
94             << "Matrix::end_column(size_t)\n";
95  }
96  VectorConstView c=data1.row_const_view(0);
97  VectorView d=data2.row_view(0);
98  if (c.begin()!=data1.begin_row(0)) {
99    suite.add(false);
100    suite.err() << "VectorConstView::begin should equal " 
101             << "Matrix::begin_row(size_t)\n";
102  }
103  if (c.end()!=data1.end_row(0)){
104    suite.add(false);
105    suite.err() << "VectorConstView::end should equal " 
106             << "Matrix::end_row(size_t)\n";
107  }
108  if (d.begin()!=data2.begin_row(0)){
109    suite.add(false);
110    suite.err() << "VectorView::begin should equal " 
111             << "Matrix::begin_row(size_t)\n";
112  }
113  if (d.end()!=data2.end_row(0)){
114    suite.add(false);
115    suite.err() << "VectorView::end should equal " 
116             << "Matrix::end_row(size_t)\n";
117  }
118
119
120  // test that VectorConstView created from VectorView is independent
121  // of VectorView
122  {
123    Vector vec(10,1.2);
124    VectorView* vv = new VectorView(vec);
125    VectorConstView vcv(*vv);
126    delete vv;
127    if (vcv.size()!=10)
128      suite.add(false);
129    if (vcv(0)!=1.2)
130      suite.add(false);
131  }
132 
133  test_rvalue(suite);
134
135  return suite.return_value();
136}
137
138void test_rvalue(test::Suite& suite)
139{
140  using namespace utility;
141  suite.err() << "test rvalue" << std::endl;
142  Matrix m(10,10);
143  VectorView vv(m.row_view(0));
144  // this block doesn't compile, se ticket:474
145  // vv = m.row_view(1);
146
147  //Vector vec(m.row_view(0));
148  //vec = m.row_view(1);
149
150  //VectorConstView vcv(m.row_view(0));
151  //test_rvalue_func(suite, m.row_view(0));
152
153  test_rvalue_func(suite, m.row_const_view(0));
154
155}
156
157void test_rvalue_func(test::Suite& suite, const utility::VectorBase& vec)
158{
159  suite.err() << "test_rvalue_func: size: " << vec.size() << std::endl;
160}
Note: See TracBrowser for help on using the repository browser.