source: trunk/test/view_test.cc @ 1131

Last change on this file since 1131 was 1131, checked in by Peter, 14 years ago

adding test for VectorConstView? independance

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1// $Id: view_test.cc 1131 2008-02-23 18:50:11Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson, Markus Ringnér
5
6  This file is part of the yat library, http://trac.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 "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(const int argc,const char* argv[])
35{ 
36  using namespace theplu::yat::utility;
37  std::ostream* message;
38  if (argc>1 && argv[1]==std::string("-v"))
39    message = &std::cerr;
40  else {
41    message = new std::ofstream("/dev/null");
42    if (argc>1)
43      std::cout << "vector_test -v : for printing extra "  << "information\n";
44  }
45  *message << "testing vector" << std::endl;
46  bool ok = true;
47
48  Matrix data1;
49  data1.resize(3,1);
50  for(size_t i=0;i<3;i++) {
51    data1(i,0)=7+i;
52  }
53
54  Matrix data2(3,1,1.0);
55
56  VectorConstView a=data1.column_const_view(0);
57  VectorView b=data2.column_view(0);
58
59  data1.column_const_view(0);
60  if (b.size()!=3){
61    ok =false;
62    *message << "ERROR: expected size to be 3 - found " << b.size() << std::endl;
63  }
64  if ( !(b(0)==1 && b(1)==(1) && b(2)==1) )
65    ok = false;
66
67  // test that VectorConstView created from VectorView is independent
68  // of VectorView
69  {
70    Vector vec(10,1.2);
71    VectorView* vv = new VectorView(vec);
72    VectorConstView vcv(*vv);
73    delete vv;
74    if (vcv.size()!=10)
75      ok = false;
76    if (vcv(0)!=1.2)
77      ok = false;
78  }
79 
80
81  if (ok)
82    *message << "test is ok" << std::endl;
83  else
84    *message << "view test failed" << std::endl;
85
86  if (message!=&std::cerr)
87    delete message;
88
89  return (ok ? 0 : -1);
90}
91
92
Note: See TracBrowser for help on using the repository browser.