source: trunk/test/iterator_test.cc @ 1027

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

going back to previous design in which view and const_view are in different classes. Having them in same didnt work as expected. There is a problem converting vector::iterator to vector::const_iterator. I'll open a separate ticket for this issue.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: iterator_test.cc 1027 2008-02-02 21:29:29Z 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  utility::vector vec(12);
52  classifier::DataLookup1D lookup(vec);
53  utility::vector::iterator begin=vec.begin();
54  // test iterator to const_iterator conversion
55  ///////////////////////////////////////////////////////
56  /* const conversion doesn't work for new vector structure
57  utility::vector::const_iterator ci = vec.begin();
58  ci = begin;
59  if (begin!=ci)
60    ok = false;
61  */ 
62  ///////////////////////////////////////////////////////
63  utility::vector::iterator end=vec.end();
64  std::sort(begin, end);
65  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
66  classifier::DataLookup1D::const_iterator lend=lookup.end();
67 
68  std::copy(lbegin, lend, begin);
69  std::copy(begin, end, begin);
70  std::sort(begin, end);
71
72  // test std algorithm on IteratorWeighted
73  utility::matrix m(1,3,1);
74  m(0,1)=2.0;
75  utility::matrix w(1,3,1);
76  classifier::MatrixLookupWeighted mw(m,w);
77  classifier::DataLookupWeighted1D aw(mw,0,true);
78  size_t nof1=std::count(aw.begin(),aw.end(),1.0);
79  if(nof1!=2) {
80    *message << "std algoritm with IteratorWeighted failed" << std::endl;
81    ok=false;
82  }
83
84  if (!ok)
85    *message << "iterator test failed" << std::endl;
86 
87  return (ok ? 0 : -1);
88}
Note: See TracBrowser for help on using the repository browser.