source: trunk/test/view_test.cc @ 1119

Last change on this file since 1119 was 1119, checked in by Peter, 15 years ago

add view_test into TESTS

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: view_test.cc 1119 2008-02-21 22:27:48Z 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
68  if (ok)
69    *message << "test is ok" << std::endl;
70  else
71    *message << "view test failed" << std::endl;
72
73  if (message!=&std::cerr)
74    delete message;
75
76  return (ok ? 0 : -1);
77}
78
79
Note: See TracBrowser for help on using the repository browser.