source: trunk/test/iterator_test.cc @ 1363

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

working on #369

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