source: trunk/test/view_test.cc @ 1720

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

adding some tests that refs #474. The commented code should compile before closing this ticket

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