source: trunk/test/iterator_test.cc @ 1062

Last change on this file since 1062 was 1062, checked in by Peter, 13 years ago

redesigning Iterator class to hold a 2D container rather than 1D as before. refs #267

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: iterator_test.cc 1062 2008-02-10 18:41:06Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
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/classifier/DataLookup1D.h"
25
26#include "yat/classifier/DataLookupWeighted1D.h"
27#include "yat/classifier/MatrixLookupWeighted.h"
28#include "yat/utility/Iterator.h"
29#include "yat/utility/IteratorWeighted.h"
30#include "yat/utility/matrix.h"
31#include "yat/utility/vector.h"
32
33#include <algorithm>
34#include <fstream>
35
36using namespace theplu::yat;
37
38int main(const int argc,const char* argv[])
39{ 
40  std::ostream* message;
41  if (argc>1 && argv[1]==std::string("-v"))
42    message = &std::cerr;
43  else {
44    message = new std::ofstream("/dev/null");
45    if (argc>1)
46      std::cout << "iterator_test -v : for printing extra "  << "information\n";
47  }
48  *message << "testing iterator" << std::endl;
49  bool ok = true;
50
51  *message << "testing utility::vector::iterator" << std::endl;
52  utility::vector vec(12);
53  classifier::DataLookup1D lookup(vec);
54  utility::vector::iterator begin=vec.begin();
55  // test iterator to const_iterator conversion
56  utility::vector::const_iterator ci = vec.begin();
57  ci = begin;
58  if (begin!=ci)
59    ok = false;
60
61  utility::vector::iterator end=vec.end();
62  std::sort(begin, end);
63
64  *message << "testing classifier::DataLookup1D::const_iterator" << std::endl;
65  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
66  classifier::DataLookup1D::const_iterator lend=lookup.end();
67 
68  *message << "copy from DataLookup1D to Vector" << std::endl;
69  std::copy(lbegin, lend, begin);
70  *message << "copy from Vector to Vector" << std::endl;
71  std::copy(begin, end, begin);
72  *message << "sort Vector" << std::endl;
73  std::sort(begin, end);
74
75  // test std algorithm on IteratorWeighted
76  utility::matrix m(1,3,1);
77  m(0,1)=2.0;
78  utility::matrix w(1,3,1);
79  classifier::MatrixLookupWeighted mw(m,w);
80  classifier::DataLookupWeighted1D aw(mw,0,true);
81  size_t nof1=std::count(aw.begin(),aw.end(),1.0);
82  if(nof1!=2) {
83    *message << "std algoritm with IteratorWeighted failed" << std::endl;
84    ok=false;
85  }
86
87  if (!ok)
88    *message << "iterator test failed" << std::endl;
89 
90  return (ok ? 0 : -1);
91}
Note: See TracBrowser for help on using the repository browser.