source: branches/0.4-stable/test/iterator_test.cc @ 1392

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

trac has moved

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1// $Id: iterator_test.cc 1392 2008-07-28 19:35:30Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
5
6  This file is part of the yat library, http://dev.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 "Suite.h"
25
26#include "yat/classifier/DataLookup1D.h"
27
28#include "yat/classifier/DataLookupWeighted1D.h"
29#include "yat/classifier/MatrixLookupWeighted.h"
30#include "yat/utility/Container2DIterator.h"
31#include "yat/utility/Matrix.h"
32#include "yat/utility/Vector.h"
33
34#include <algorithm>
35#include <fstream>
36
37using namespace theplu::yat;
38
39int main(int argc, char* argv[])
40{ 
41  test::Suite suite(argc, argv);
42  suite.err() << "testing iterator" << std::endl;
43
44  suite.err() << "testing utility::vector::iterator" << std::endl;
45  utility::Vector vec(12);
46  classifier::DataLookup1D lookup(vec);
47  utility::Vector::iterator begin=vec.begin();
48  // test iterator to const_iterator conversion
49  utility::Vector::const_iterator ci = vec.begin();
50  ci = begin;
51  if (begin!=ci)
52    suite.add(false);
53
54  utility::Vector::iterator end=vec.end();
55  std::sort(begin, end);
56
57  suite.err() << "testing classifier::DataLookup1D::const_iterator" << std::endl;
58  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
59  classifier::DataLookup1D::const_iterator lend=lookup.end();
60 
61  suite.err() << "copy from DataLookup1D to Vector" << std::endl;
62  std::copy(lbegin, lend, begin);
63  suite.err() << "copy from Vector to Vector" << std::endl;
64  std::copy(begin, end, begin);
65  suite.err() << "sort Vector" << std::endl;
66  std::sort(begin, end);
67
68  // test std algorithm on IteratorWeighted
69  utility::Matrix m(1,3,1);
70  m(0,1)=2.0;
71  utility::Matrix w(1,3,1);
72  classifier::MatrixLookupWeighted mw(m,w);
73  classifier::DataLookupWeighted1D aw(mw,0,true);
74  size_t nof1=std::count(aw.begin(),aw.end(),
75                         std::pair<double, double>(1.0, 1.0));
76  if(nof1!=2) {
77    suite.err() << "std algoritm with IteratorWeighted failed" << std::endl;
78    suite.add(false);
79  }
80  if (aw.begin()!=mw.begin_row(0))
81    suite.add(false);
82  if (aw.end()!=mw.end_row(0))
83    suite.add(false);
84  classifier::DataLookupWeighted1D aw2(mw,0,false);
85  if (aw2.begin()!=mw.begin_column(0))
86    suite.add(false);
87  if (aw2.end()!=mw.end_column(0))
88    suite.add(false);
89
90  classifier::MatrixLookup ml(m);
91  classifier::DataLookup1D dl1(ml,0,true);
92  if (dl1.begin()!=ml.begin_row(0))
93    suite.add(false);
94  if (dl1.end()!=ml.end_row(0))
95    suite.add(false);
96  classifier::DataLookup1D dl2(ml,0,false);
97  if (dl2.begin()!=ml.begin_column(0))
98    suite.add(false);
99  if (dl2.end()!=ml.end_column(0))
100    suite.add(false);
101
102  return suite.return_value();
103}
Note: See TracBrowser for help on using the repository browser.