source: trunk/test/view_test.cc @ 1658

Last change on this file since 1658 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: 3.5 KB
Line 
1// $Id: view_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/VectorBase.h"
26#include "yat/utility/VectorMutable.h"
27#include "yat/utility/VectorView.h"
28#include "yat/utility/VectorConstView.h"
29
30#include <fstream>
31#include <iostream>
32#include <string>
33
34int main(int argc, char* argv[])
35{ 
36  using namespace theplu::yat::utility;
37  theplu::yat::test::Suite suite(argc, argv);
38  suite.err() << "testing vector" << std::endl;
39
40  Matrix data1;
41  data1.resize(3,1);
42  for(size_t i=0;i<3;i++) {
43    data1(i,0)=7+i;
44  }
45 
46
47  Matrix data2(3,1,1.0);
48
49  VectorConstView a=data1.column_const_view(0);
50  VectorView b=data2.column_view(0);
51  VectorView bajs(data2, 0, false);
52  if (a(0)!=data1(0,0)){
53    suite.err() << "Matrix::column_const_view failed\n";
54    suite.add(false);
55  }
56  if (b(0)!=data2(0,0)){
57    suite.err() << "Matrix::column_view failed\n";
58    suite.add(false);
59  }
60
61  data1.column_const_view(0);
62  if (b.size()!=3){
63    suite.add(false);
64    suite.err() << "ERROR: expected size to be 3 - found " << b.size() << std::endl;
65  }
66  if ( !(b(0)==1 && b(1)==(1) && b(2)==1) )
67    suite.add(false);
68
69  if (a.begin()!=data1.begin_column(0)){
70    suite.add(false);
71    suite.err() << "VectorConstView::begin should equal " 
72             << "Matrix::begin_column(size_t)\n";
73  }
74  if (a.end()!=data1.end_column(0)) {
75    suite.add(false);
76    suite.err() << "VectorConstView::end should equal " 
77             << "Matrix::end_column(size_t)\n";
78  }
79  if (b.begin()!=data2.begin_column(0)){
80    suite.add(false);
81    suite.err() << "VectorView::begin " 
82             << b.begin().base() << " should equal\n"
83             << "Matrix::begin_column(size_t) "
84             << data1.begin_column(0).base() << std::endl;
85  }
86  if (b.end()!=data2.end_column(0)){
87    suite.add(false);
88    suite.err() << "VectorView::end should equal " 
89             << "Matrix::end_column(size_t)\n";
90  }
91  VectorConstView c=data1.row_const_view(0);
92  VectorView d=data2.row_view(0);
93  if (c.begin()!=data1.begin_row(0)) {
94    suite.add(false);
95    suite.err() << "VectorConstView::begin should equal " 
96             << "Matrix::begin_row(size_t)\n";
97  }
98  if (c.end()!=data1.end_row(0)){
99    suite.add(false);
100    suite.err() << "VectorConstView::end should equal " 
101             << "Matrix::end_row(size_t)\n";
102  }
103  if (d.begin()!=data2.begin_row(0)){
104    suite.add(false);
105    suite.err() << "VectorView::begin should equal " 
106             << "Matrix::begin_row(size_t)\n";
107  }
108  if (d.end()!=data2.end_row(0)){
109    suite.add(false);
110    suite.err() << "VectorView::end should equal " 
111             << "Matrix::end_row(size_t)\n";
112  }
113
114
115  // test that VectorConstView created from VectorView is independent
116  // of VectorView
117  {
118    Vector vec(10,1.2);
119    VectorView* vv = new VectorView(vec);
120    VectorConstView vcv(*vv);
121    delete vv;
122    if (vcv.size()!=10)
123      suite.add(false);
124    if (vcv(0)!=1.2)
125      suite.add(false);
126  }
127 
128
129  return suite.return_value();
130}
131
132
Note: See TracBrowser for help on using the repository browser.