1106 |
19 Feb 08 |
peter |
// $Id$ |
1106 |
19 Feb 08 |
peter |
2 |
|
1106 |
19 Feb 08 |
peter |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
1106 |
19 Feb 08 |
peter |
6 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1106 |
19 Feb 08 |
peter |
8 |
|
1106 |
19 Feb 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1106 |
19 Feb 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1106 |
19 Feb 08 |
peter |
License, or (at your option) any later version. |
1106 |
19 Feb 08 |
peter |
13 |
|
1106 |
19 Feb 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1106 |
19 Feb 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1106 |
19 Feb 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1106 |
19 Feb 08 |
peter |
General Public License for more details. |
1106 |
19 Feb 08 |
peter |
18 |
|
1106 |
19 Feb 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1106 |
19 Feb 08 |
peter |
21 |
*/ |
1106 |
19 Feb 08 |
peter |
22 |
|
2881 |
18 Nov 12 |
peter |
23 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
24 |
|
1237 |
15 Mar 08 |
peter |
25 |
#include "Suite.h" |
1237 |
15 Mar 08 |
peter |
26 |
|
1106 |
19 Feb 08 |
peter |
27 |
#include "yat/utility/Index.h" |
1106 |
19 Feb 08 |
peter |
28 |
#include "yat/utility/SmartPtr.h" |
1106 |
19 Feb 08 |
peter |
29 |
|
1106 |
19 Feb 08 |
peter |
30 |
#include <fstream> |
1106 |
19 Feb 08 |
peter |
31 |
#include <iostream> |
1106 |
19 Feb 08 |
peter |
32 |
#include <vector> |
1106 |
19 Feb 08 |
peter |
33 |
|
1237 |
15 Mar 08 |
peter |
34 |
int main(int argc, char* argv[]) |
4200 |
19 Aug 22 |
peter |
35 |
{ |
1106 |
19 Feb 08 |
peter |
36 |
using namespace theplu::yat; |
1106 |
19 Feb 08 |
peter |
37 |
using utility::Index; |
1106 |
19 Feb 08 |
peter |
38 |
|
1237 |
15 Mar 08 |
peter |
39 |
test::Suite suite(argc, argv); |
1237 |
15 Mar 08 |
peter |
40 |
suite.err() << "testing Index" << std::endl; |
1106 |
19 Feb 08 |
peter |
41 |
|
1106 |
19 Feb 08 |
peter |
42 |
Index index; |
1106 |
19 Feb 08 |
peter |
43 |
if (index.size()){ |
1237 |
15 Mar 08 |
peter |
44 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
45 |
suite.err() << "Default constructor failed\n"; |
1106 |
19 Feb 08 |
peter |
46 |
} |
1106 |
19 Feb 08 |
peter |
47 |
|
1106 |
19 Feb 08 |
peter |
48 |
Index index2(10); |
1106 |
19 Feb 08 |
peter |
49 |
if (index2.size()!=10){ |
1237 |
15 Mar 08 |
peter |
50 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
51 |
suite.err() << "Constructor Index(10) failed\n"; |
1106 |
19 Feb 08 |
peter |
52 |
} |
1106 |
19 Feb 08 |
peter |
53 |
for (size_t i=0; i<index2.size(); ++i) |
1106 |
19 Feb 08 |
peter |
54 |
if (index2[i]!=i){ |
1237 |
15 Mar 08 |
peter |
55 |
suite.add(false); |
4200 |
19 Aug 22 |
peter |
56 |
suite.err() << "index[" << i << "]=" << index2[i] << " expected " << i |
1106 |
19 Feb 08 |
peter |
57 |
<< "\n"; |
1106 |
19 Feb 08 |
peter |
58 |
} |
1106 |
19 Feb 08 |
peter |
59 |
|
1106 |
19 Feb 08 |
peter |
60 |
std::vector<size_t> vec; |
1106 |
19 Feb 08 |
peter |
61 |
vec.push_back(1); |
1106 |
19 Feb 08 |
peter |
62 |
vec.push_back(3); |
1106 |
19 Feb 08 |
peter |
63 |
vec.push_back(5); |
4200 |
19 Aug 22 |
peter |
64 |
utility::SmartPtr<const std::vector<size_t> > |
1106 |
19 Feb 08 |
peter |
65 |
sp(new const std::vector<size_t>(vec)); |
1106 |
19 Feb 08 |
peter |
66 |
Index index3(sp); |
1106 |
19 Feb 08 |
peter |
67 |
if (index3.size()!=vec.size()){ |
1237 |
15 Mar 08 |
peter |
68 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
69 |
suite.err() << "Constructor from SmartPtr failed\n"; |
1106 |
19 Feb 08 |
peter |
70 |
} |
1106 |
19 Feb 08 |
peter |
71 |
for (size_t i=0; i<index3.size(); ++i) |
1106 |
19 Feb 08 |
peter |
72 |
if (index3[i]!=vec[i]){ |
1237 |
15 Mar 08 |
peter |
73 |
suite.add(false); |
4200 |
19 Aug 22 |
peter |
74 |
suite.err() << "index[" << i << "]=" << index3[i] << " expected " << vec[i] |
1106 |
19 Feb 08 |
peter |
75 |
<< "\n"; |
1106 |
19 Feb 08 |
peter |
76 |
} |
1106 |
19 Feb 08 |
peter |
77 |
|
1237 |
15 Mar 08 |
peter |
78 |
suite.err() << " testing creation of sub index\n"; |
1106 |
19 Feb 08 |
peter |
79 |
Index index4(index2, index3); |
1106 |
19 Feb 08 |
peter |
80 |
if (index4.size()!=index3.size()){ |
1237 |
15 Mar 08 |
peter |
81 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
82 |
suite.err() << "failed\n"; |
1106 |
19 Feb 08 |
peter |
83 |
} |
1106 |
19 Feb 08 |
peter |
84 |
for (size_t i=0; i<index4.size(); ++i) |
1106 |
19 Feb 08 |
peter |
85 |
if (index4[i]!=index2[index3[i]]){ |
1237 |
15 Mar 08 |
peter |
86 |
suite.add(false); |
4200 |
19 Aug 22 |
peter |
87 |
suite.err() << "index[" << i << "]=" << index4[i] << " expected " |
1106 |
19 Feb 08 |
peter |
88 |
<< index2[index3[i]] << "\n"; |
1106 |
19 Feb 08 |
peter |
89 |
} |
1106 |
19 Feb 08 |
peter |
90 |
|
1106 |
19 Feb 08 |
peter |
91 |
Index index5(index4); |
1106 |
19 Feb 08 |
peter |
92 |
if (index5.size()!=index4.size()){ |
1237 |
15 Mar 08 |
peter |
93 |
suite.add(false); |
1237 |
15 Mar 08 |
peter |
94 |
suite.err() << "failed\n"; |
1106 |
19 Feb 08 |
peter |
95 |
} |
1106 |
19 Feb 08 |
peter |
96 |
for (size_t i=0; i<index5.size(); ++i) |
1106 |
19 Feb 08 |
peter |
97 |
if (index5[i]!=index4[i]){ |
1237 |
15 Mar 08 |
peter |
98 |
suite.add(false); |
4200 |
19 Aug 22 |
peter |
99 |
suite.err() << "index[" << i << "]=" << index5[i] << " expected " |
1106 |
19 Feb 08 |
peter |
100 |
<< index4[i] << "\n"; |
1106 |
19 Feb 08 |
peter |
101 |
} |
4200 |
19 Aug 22 |
peter |
102 |
|
1237 |
15 Mar 08 |
peter |
103 |
return suite.return_value(); |
1106 |
19 Feb 08 |
peter |
104 |
} |