1 | // $Id: iterator_test.cc 1743 2009-01-23 14:20:30Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
5 | Copyright (C) 2008 Peter Johansson, Markus Ringnér |
---|
6 | |
---|
7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
8 | |
---|
9 | The yat library is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License as |
---|
11 | published by the Free Software Foundation; either version 2 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | The yat library is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with this program; if not, write to the Free Software |
---|
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
22 | 02111-1307, USA. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "Suite.h" |
---|
26 | |
---|
27 | #include "yat/classifier/DataLookup1D.h" |
---|
28 | |
---|
29 | #include "yat/classifier/DataLookupWeighted1D.h" |
---|
30 | #include "yat/classifier/MatrixLookupWeighted.h" |
---|
31 | #include "yat/utility/Container2DIterator.h" |
---|
32 | #include "yat/utility/Matrix.h" |
---|
33 | #include "yat/utility/Vector.h" |
---|
34 | |
---|
35 | #include <algorithm> |
---|
36 | #include <fstream> |
---|
37 | |
---|
38 | using namespace theplu::yat; |
---|
39 | |
---|
40 | int 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 | classifier::MatrixLookup ml(m); |
---|
92 | classifier::DataLookup1D dl1(ml,0,true); |
---|
93 | if (dl1.begin()!=ml.begin_row(0)) |
---|
94 | suite.add(false); |
---|
95 | if (dl1.end()!=ml.end_row(0)) |
---|
96 | suite.add(false); |
---|
97 | classifier::DataLookup1D dl2(ml,0,false); |
---|
98 | if (dl2.begin()!=ml.begin_column(0)) |
---|
99 | suite.add(false); |
---|
100 | if (dl2.end()!=ml.end_column(0)) |
---|
101 | suite.add(false); |
---|
102 | |
---|
103 | return suite.return_value(); |
---|
104 | } |
---|