source: trunk/test/iterator_test.cc @ 883

Last change on this file since 883 was 883, checked in by Peter, 16 years ago

fixing problems with iterator -> const_iterator conversion

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: iterator_test.cc 883 2007-09-22 22:05:41Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/trac/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/utility/Iterator.h"
27#include "yat/utility/vector.h"
28
29#include <algorithm>
30#include <fstream>
31
32using namespace theplu::yat;
33
34int main(const int argc,const char* argv[])
35{ 
36  std::ostream* message;
37  if (argc>1 && argv[1]==std::string("-v"))
38    message = &std::cerr;
39  else {
40    message = new std::ofstream("/dev/null");
41    if (argc>1)
42      std::cout << "iterator_test -v : for printing extra "  << "information\n";
43  }
44  *message << "testing iterator" << std::endl;
45  bool ok = true;
46
47  utility::vector vec(12);
48  classifier::DataLookup1D lookup(vec);
49  utility::vector::iterator begin=vec.begin();
50  // test iterator to const_iterator conversion
51  utility::vector::const_iterator ci = vec.begin();
52  ci = begin;
53  if (begin!=ci)
54    ok = false;
55 
56  utility::vector::iterator end=vec.end();
57  std::sort(begin, end);
58  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
59  classifier::DataLookup1D::const_iterator lend=lookup.end();
60 
61  std::copy(lbegin, lend, begin);
62  std::copy(begin, end, begin);
63  std::sort(begin, end);
64
65  if (!ok)
66    *message << "iterator test failed" << std::endl;
67 
68  return (ok ? 0 : -1);
69}
Note: See TracBrowser for help on using the repository browser.