2291 |
07 Jul 10 |
peter |
// $Id$ |
2291 |
07 Jul 10 |
peter |
2 |
|
2291 |
07 Jul 10 |
peter |
3 |
/* |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2010, 2011, 2012, 2014, 2015, 2016, 2017, 2021, 2022 Peter Johansson |
2291 |
07 Jul 10 |
peter |
5 |
|
2291 |
07 Jul 10 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2291 |
07 Jul 10 |
peter |
7 |
|
2291 |
07 Jul 10 |
peter |
The yat library is free software; you can redistribute it and/or |
2291 |
07 Jul 10 |
peter |
modify it under the terms of the GNU General Public License as |
2291 |
07 Jul 10 |
peter |
published by the Free Software Foundation; either version 3 of the |
2291 |
07 Jul 10 |
peter |
License, or (at your option) any later version. |
2291 |
07 Jul 10 |
peter |
12 |
|
2291 |
07 Jul 10 |
peter |
The yat library is distributed in the hope that it will be useful, |
2291 |
07 Jul 10 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2291 |
07 Jul 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2291 |
07 Jul 10 |
peter |
General Public License for more details. |
2291 |
07 Jul 10 |
peter |
17 |
|
2291 |
07 Jul 10 |
peter |
You should have received a copy of the GNU General Public License |
2291 |
07 Jul 10 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2291 |
07 Jul 10 |
peter |
20 |
*/ |
2291 |
07 Jul 10 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2291 |
07 Jul 10 |
peter |
24 |
#include "Suite.h" |
2291 |
07 Jul 10 |
peter |
25 |
|
2291 |
07 Jul 10 |
peter |
26 |
#include "yat/utility/Segment.h" |
2358 |
02 Dec 10 |
peter |
27 |
#include "yat/utility/SegmentMap.h" |
2291 |
07 Jul 10 |
peter |
28 |
#include "yat/utility/SegmentSet.h" |
2291 |
07 Jul 10 |
peter |
29 |
|
2296 |
08 Jul 10 |
peter |
30 |
using namespace theplu::yat; |
2296 |
08 Jul 10 |
peter |
31 |
using namespace utility; |
4032 |
21 Jan 21 |
peter |
32 |
void test_comp(test::Suite& suite); |
2357 |
01 Dec 10 |
peter |
33 |
void test_compare(test::Suite& suite); |
2296 |
08 Jul 10 |
peter |
34 |
void test_count(test::Suite&); |
2611 |
04 Nov 11 |
peter |
35 |
void test_erase(test::Suite&); |
3649 |
15 Jun 17 |
peter |
36 |
void test_includes(test::Suite&); |
2296 |
08 Jul 10 |
peter |
37 |
void test_insert(test::Suite&); |
2296 |
08 Jul 10 |
peter |
38 |
void test_insert_merge(test::Suite&); |
3598 |
22 Jan 17 |
peter |
39 |
void test_make_segment(test::Suite&); |
3649 |
15 Jun 17 |
peter |
40 |
void test_overlap(test::Suite&); |
2296 |
08 Jul 10 |
peter |
41 |
void test_segment(test::Suite& suite); |
3449 |
07 Dec 15 |
peter |
42 |
void test_operator(test::Suite& suite); |
2358 |
02 Dec 10 |
peter |
43 |
void test_segment_map(test::Suite& suite); |
4027 |
17 Jan 21 |
peter |
44 |
void test_segment_set(test::Suite& suite); |
2296 |
08 Jul 10 |
peter |
45 |
void test_set_bound(test::Suite&); |
3650 |
18 Jun 17 |
peter |
46 |
void test_union(test::Suite&); |
2296 |
08 Jul 10 |
peter |
47 |
|
2358 |
02 Dec 10 |
peter |
48 |
template<typename T> |
2358 |
02 Dec 10 |
peter |
49 |
void avoid_pedantic_warning(T) {} |
2358 |
02 Dec 10 |
peter |
50 |
|
2291 |
07 Jul 10 |
peter |
51 |
int main(int argc, char* argv[]) |
3650 |
18 Jun 17 |
peter |
52 |
{ |
2296 |
08 Jul 10 |
peter |
53 |
test::Suite suite(argc, argv); |
2291 |
07 Jul 10 |
peter |
54 |
|
4032 |
21 Jan 21 |
peter |
55 |
test_comp(suite); |
2357 |
01 Dec 10 |
peter |
56 |
test_compare(suite); |
2296 |
08 Jul 10 |
peter |
57 |
test_count(suite); |
2611 |
04 Nov 11 |
peter |
58 |
test_erase(suite); |
3649 |
15 Jun 17 |
peter |
59 |
test_includes(suite); |
2296 |
08 Jul 10 |
peter |
60 |
test_insert(suite); |
2296 |
08 Jul 10 |
peter |
61 |
test_insert_merge(suite); |
3598 |
22 Jan 17 |
peter |
62 |
test_make_segment(suite); |
3649 |
15 Jun 17 |
peter |
63 |
test_overlap(suite); |
2296 |
08 Jul 10 |
peter |
64 |
test_segment(suite); |
2296 |
08 Jul 10 |
peter |
65 |
test_set_bound(suite); |
3650 |
18 Jun 17 |
peter |
66 |
test_union(suite); |
2296 |
08 Jul 10 |
peter |
67 |
|
2358 |
02 Dec 10 |
peter |
68 |
test_segment_map(suite); |
4027 |
17 Jan 21 |
peter |
69 |
test_segment_set(suite); |
2358 |
02 Dec 10 |
peter |
70 |
|
2296 |
08 Jul 10 |
peter |
71 |
return suite.return_value(); |
2296 |
08 Jul 10 |
peter |
72 |
} |
2296 |
08 Jul 10 |
peter |
73 |
|
2357 |
01 Dec 10 |
peter |
74 |
|
4032 |
21 Jan 21 |
peter |
75 |
void test_comp(test::Suite& suite) |
4032 |
21 Jan 21 |
peter |
76 |
{ |
4252 |
18 Nov 22 |
peter |
77 |
Segment<double> key(0,1); |
4032 |
21 Jan 21 |
peter |
78 |
{ |
4032 |
21 Jan 21 |
peter |
79 |
SegmentSet<double> set; |
4032 |
21 Jan 21 |
peter |
80 |
SegmentSet<double>::key_compare kcompare = set.key_comp(); |
4032 |
21 Jan 21 |
peter |
81 |
if (kcompare(key, key)) |
4032 |
21 Jan 21 |
peter |
82 |
suite.add(false); |
4032 |
21 Jan 21 |
peter |
83 |
test::avoid_compiler_warning(kcompare); |
4032 |
21 Jan 21 |
peter |
84 |
SegmentSet<double>::value_compare vcompare = set.value_comp(); |
4032 |
21 Jan 21 |
peter |
85 |
if (vcompare(key, key)) |
4032 |
21 Jan 21 |
peter |
86 |
suite.add(false); |
4032 |
21 Jan 21 |
peter |
87 |
test::avoid_compiler_warning(vcompare); |
4032 |
21 Jan 21 |
peter |
88 |
} |
4032 |
21 Jan 21 |
peter |
89 |
|
4032 |
21 Jan 21 |
peter |
90 |
{ |
4032 |
21 Jan 21 |
peter |
91 |
SegmentMap<double, std::string> map; |
4032 |
21 Jan 21 |
peter |
92 |
std::pair<const Segment<double>, std::string> value(key, "hello"); |
4032 |
21 Jan 21 |
peter |
93 |
SegmentMap<double, std::string>::key_compare kcompare = map.key_comp(); |
4032 |
21 Jan 21 |
peter |
94 |
if (kcompare(key, key)) |
4032 |
21 Jan 21 |
peter |
95 |
suite.add(false); |
4032 |
21 Jan 21 |
peter |
96 |
test::avoid_compiler_warning(kcompare); |
4032 |
21 Jan 21 |
peter |
97 |
SegmentMap<double, std::string>::value_compare vcompare = map.value_comp(); |
4032 |
21 Jan 21 |
peter |
98 |
if (vcompare(value, value)) |
4032 |
21 Jan 21 |
peter |
99 |
suite.add(false); |
4032 |
21 Jan 21 |
peter |
100 |
test::avoid_compiler_warning(vcompare); |
4032 |
21 Jan 21 |
peter |
101 |
} |
4032 |
21 Jan 21 |
peter |
102 |
} |
4032 |
21 Jan 21 |
peter |
103 |
|
4032 |
21 Jan 21 |
peter |
104 |
|
4200 |
19 Aug 22 |
peter |
105 |
void test_compare_(test::Suite& suite, double lhs_begin, double lhs_end, |
2357 |
01 Dec 10 |
peter |
106 |
double rhs_begin, double rhs_end, int expected) |
2357 |
01 Dec 10 |
peter |
107 |
{ |
4200 |
19 Aug 22 |
peter |
108 |
int result = compare_3way(Segment<double>(lhs_begin,lhs_end), |
2357 |
01 Dec 10 |
peter |
109 |
Segment<double>(rhs_begin,rhs_end)); |
2357 |
01 Dec 10 |
peter |
110 |
if (result!=expected) { |
2357 |
01 Dec 10 |
peter |
111 |
suite.add(false); |
2357 |
01 Dec 10 |
peter |
112 |
suite.err() << "error:" |
2357 |
01 Dec 10 |
peter |
113 |
<< "[" << lhs_begin << ", " << lhs_end << ") vs " |
2357 |
01 Dec 10 |
peter |
114 |
<< "[" << rhs_begin << ", " << rhs_end << ")\n" |
2357 |
01 Dec 10 |
peter |
115 |
<< "result: " << result << "\n" |
2357 |
01 Dec 10 |
peter |
116 |
<< "expected: " << expected << "\n" |
2357 |
01 Dec 10 |
peter |
117 |
<< "\n"; |
2357 |
01 Dec 10 |
peter |
118 |
} |
3488 |
01 Apr 16 |
peter |
119 |
|
3488 |
01 Apr 16 |
peter |
120 |
compare_3way(lhs_begin, Segment<double>(rhs_begin,rhs_end)); |
3488 |
01 Apr 16 |
peter |
121 |
compare_3way(Segment<double>(rhs_begin,rhs_end), lhs_begin); |
2357 |
01 Dec 10 |
peter |
122 |
} |
2357 |
01 Dec 10 |
peter |
123 |
|
4200 |
19 Aug 22 |
peter |
124 |
void test_compare(test::Suite& suite, double lhs_begin, double lhs_end, |
2357 |
01 Dec 10 |
peter |
125 |
double rhs_begin, double rhs_end, int expected) |
2357 |
01 Dec 10 |
peter |
126 |
{ |
2357 |
01 Dec 10 |
peter |
127 |
test_compare_(suite, lhs_begin, lhs_end, rhs_begin, rhs_end, expected); |
2357 |
01 Dec 10 |
peter |
// test symmetry |
2357 |
01 Dec 10 |
peter |
129 |
test_compare_(suite, rhs_begin, rhs_end, lhs_begin, lhs_end, -expected); |
2357 |
01 Dec 10 |
peter |
130 |
} |
2357 |
01 Dec 10 |
peter |
131 |
|
2357 |
01 Dec 10 |
peter |
132 |
void test_compare(test::Suite& suite) |
2357 |
01 Dec 10 |
peter |
133 |
{ |
2357 |
01 Dec 10 |
peter |
134 |
test_compare(suite, 0, 10, 20, 30, -1); |
2357 |
01 Dec 10 |
peter |
135 |
test_compare(suite, 0, 10, 10, 30, -1); |
2357 |
01 Dec 10 |
peter |
136 |
test_compare(suite, 0, 10, 5, 30, 0); |
2357 |
01 Dec 10 |
peter |
137 |
test_compare(suite, 0, 10, -5, 5, 0); |
2357 |
01 Dec 10 |
peter |
138 |
test_compare(suite, 0, 10, -5, 0, 1); |
2357 |
01 Dec 10 |
peter |
139 |
test_compare(suite, 0, 10, -5, -1, 1); |
4200 |
19 Aug 22 |
peter |
// zero sized |
2357 |
01 Dec 10 |
peter |
141 |
test_compare(suite, 0, 0, 20, 30, -1); |
2357 |
01 Dec 10 |
peter |
142 |
test_compare(suite, 0, 0, 0, 1, -1); |
2357 |
01 Dec 10 |
peter |
143 |
test_compare(suite, 0, 0, -5, 5, 0); |
2357 |
01 Dec 10 |
peter |
144 |
test_compare(suite, 0, 0, -5, 0, 1); |
2357 |
01 Dec 10 |
peter |
145 |
test_compare(suite, 0, 0, -5, -1, 1); |
2357 |
01 Dec 10 |
peter |
146 |
|
2357 |
01 Dec 10 |
peter |
// zero sized on both sides |
2357 |
01 Dec 10 |
peter |
148 |
test_compare(suite, 0, 0, 1, 1, -1); |
2357 |
01 Dec 10 |
peter |
149 |
test_compare(suite, 0, 0, 0, 0, 0); |
2357 |
01 Dec 10 |
peter |
150 |
test_compare(suite, 0, 0, -1, -1, 1); |
2357 |
01 Dec 10 |
peter |
151 |
} |
2357 |
01 Dec 10 |
peter |
152 |
|
2357 |
01 Dec 10 |
peter |
153 |
|
2611 |
04 Nov 11 |
peter |
154 |
void test_erase(test::Suite& suite) |
2611 |
04 Nov 11 |
peter |
155 |
{ |
2611 |
04 Nov 11 |
peter |
156 |
suite.out() << "test_erase\n"; |
2611 |
04 Nov 11 |
peter |
157 |
suite.out() << " SegmentSet\n"; |
2611 |
04 Nov 11 |
peter |
158 |
SegmentSet<double> set; |
2611 |
04 Nov 11 |
peter |
159 |
set.insert(Segment<double>(0,2)); |
2611 |
04 Nov 11 |
peter |
160 |
set.insert(Segment<double>(10,20)); |
2611 |
04 Nov 11 |
peter |
161 |
set.insert(Segment<double>(30,50)); |
2611 |
04 Nov 11 |
peter |
162 |
SegmentSet<double>::iterator iter = set.find(15); |
2611 |
04 Nov 11 |
peter |
163 |
set.erase(iter); |
2611 |
04 Nov 11 |
peter |
164 |
if (!suite.add(set.size()==2)) |
2611 |
04 Nov 11 |
peter |
165 |
suite.err() << "size: " << set.size() << " expected 2\n"; |
2611 |
04 Nov 11 |
peter |
166 |
set.erase(set.begin(), set.end()); |
2611 |
04 Nov 11 |
peter |
167 |
if (!suite.add(set.size()==0)) |
2611 |
04 Nov 11 |
peter |
168 |
suite.err() << "size: " << set.size() << " expected 0\n"; |
2611 |
04 Nov 11 |
peter |
169 |
suite.out() << " SegmentMap\n"; |
2611 |
04 Nov 11 |
peter |
170 |
typedef SegmentMap<double, std::string> Map; |
2611 |
04 Nov 11 |
peter |
171 |
Map map; |
2611 |
04 Nov 11 |
peter |
172 |
Map::key_type s(0,2); |
2611 |
04 Nov 11 |
peter |
173 |
map.insert(Map::value_type(s, "aha")); |
2611 |
04 Nov 11 |
peter |
174 |
map.erase(map.begin()); |
2611 |
04 Nov 11 |
peter |
175 |
map.erase(map.begin(), map.end()); |
2611 |
04 Nov 11 |
peter |
176 |
} |
2611 |
04 Nov 11 |
peter |
177 |
|
2611 |
04 Nov 11 |
peter |
178 |
|
2296 |
08 Jul 10 |
peter |
179 |
void test_insert(test::Suite& suite) |
2296 |
08 Jul 10 |
peter |
180 |
{ |
2291 |
07 Jul 10 |
peter |
181 |
Segment<double> segment; |
2291 |
07 Jul 10 |
peter |
182 |
Segment<double> segment2(0,2); |
2291 |
07 Jul 10 |
peter |
183 |
|
2291 |
07 Jul 10 |
peter |
184 |
SegmentSet<double> set; |
2291 |
07 Jul 10 |
peter |
185 |
if (set.size()!=0) { |
2291 |
07 Jul 10 |
peter |
186 |
suite.add(false); |
2291 |
07 Jul 10 |
peter |
187 |
suite.err() << "expected size 0\n"; |
2291 |
07 Jul 10 |
peter |
188 |
} |
2291 |
07 Jul 10 |
peter |
189 |
set.insert(segment2); |
2291 |
07 Jul 10 |
peter |
190 |
if (set.size()!=1) { |
2291 |
07 Jul 10 |
peter |
191 |
suite.add(false); |
2291 |
07 Jul 10 |
peter |
192 |
suite.err() << "expected size 1\n"; |
2291 |
07 Jul 10 |
peter |
193 |
} |
2291 |
07 Jul 10 |
peter |
194 |
set.insert(segment2); |
2291 |
07 Jul 10 |
peter |
195 |
if (set.size()!=1) { |
2291 |
07 Jul 10 |
peter |
196 |
suite.add(false); |
2291 |
07 Jul 10 |
peter |
197 |
suite.err() << "expected size 1\n"; |
2291 |
07 Jul 10 |
peter |
198 |
} |
2296 |
08 Jul 10 |
peter |
199 |
set.insert(Segment<double>(1,3)); |
2296 |
08 Jul 10 |
peter |
200 |
if (set.size()!=1) { |
2296 |
08 Jul 10 |
peter |
201 |
suite.add(false); |
2296 |
08 Jul 10 |
peter |
202 |
suite.err() << "expected size 1\n"; |
2296 |
08 Jul 10 |
peter |
203 |
} |
2357 |
01 Dec 10 |
peter |
204 |
else if (set.begin()->begin()!=0.0 || set.begin()->end()!=2.0) { |
2357 |
01 Dec 10 |
peter |
205 |
suite.add(false); |
2357 |
01 Dec 10 |
peter |
206 |
suite.err() << "error: expected segment to be [0, 2)\n" |
4200 |
19 Aug 22 |
peter |
207 |
<< "found: [" << set.begin()->begin() |
2357 |
01 Dec 10 |
peter |
208 |
<< ", " << set.begin()->end() << ")\n"; |
2357 |
01 Dec 10 |
peter |
209 |
} |
2291 |
07 Jul 10 |
peter |
210 |
if (!suite.add(set.find(0)!=set.end())) |
2291 |
07 Jul 10 |
peter |
211 |
suite.err() << "error: set.find(0): expected not end()\n"; |
3344 |
06 Nov 14 |
peter |
212 |
} |
2296 |
08 Jul 10 |
peter |
213 |
|
2296 |
08 Jul 10 |
peter |
214 |
void test_count(test::Suite& suite) |
2296 |
08 Jul 10 |
peter |
215 |
{ |
2296 |
08 Jul 10 |
peter |
216 |
SegmentSet<double> set; |
2296 |
08 Jul 10 |
peter |
217 |
set.insert(Segment<double>(0,2)); |
2291 |
07 Jul 10 |
peter |
// test count |
2291 |
07 Jul 10 |
peter |
219 |
if (!suite.add(set.count(0)==1)) |
2291 |
07 Jul 10 |
peter |
220 |
suite.err() << "error: set.count(0): expected 1\n"; |
2291 |
07 Jul 10 |
peter |
221 |
if (!suite.add(set.count(1)==1)) |
2291 |
07 Jul 10 |
peter |
222 |
suite.err() << "error: set.count(1): expected 1\n"; |
2291 |
07 Jul 10 |
peter |
223 |
if (!suite.add(set.count(2)==0)) |
2291 |
07 Jul 10 |
peter |
224 |
suite.err() << "error: set.count(2): expected 0\n"; |
2296 |
08 Jul 10 |
peter |
225 |
} |
2291 |
07 Jul 10 |
peter |
226 |
|
2296 |
08 Jul 10 |
peter |
227 |
void test_insert_merge(test::Suite& suite) |
2296 |
08 Jul 10 |
peter |
228 |
{ |
2296 |
08 Jul 10 |
peter |
229 |
SegmentSet<double> set; |
2296 |
08 Jul 10 |
peter |
230 |
set.insert(Segment<double>(0,2)); |
2291 |
07 Jul 10 |
peter |
231 |
set.insert_merge(Segment<double>(3,5)); |
2291 |
07 Jul 10 |
peter |
232 |
if (!suite.add(set.size()==2)) |
2291 |
07 Jul 10 |
peter |
233 |
suite.err() << "error: set.size(): expected 2\n"; |
2291 |
07 Jul 10 |
peter |
234 |
|
2291 |
07 Jul 10 |
peter |
235 |
set.insert_merge(Segment<double>(12,13)); |
2291 |
07 Jul 10 |
peter |
236 |
if (!suite.add(set.size()==3)) |
2291 |
07 Jul 10 |
peter |
237 |
suite.err() << "error: set.size(): expected 3\n"; |
2291 |
07 Jul 10 |
peter |
238 |
|
2291 |
07 Jul 10 |
peter |
239 |
set.insert_merge(Segment<double>(1,4)); |
2291 |
07 Jul 10 |
peter |
240 |
if (!suite.add(set.size()==2)) |
2291 |
07 Jul 10 |
peter |
241 |
suite.err() << "error: set.size(): " << set.size() << " expected 2\n"; |
2291 |
07 Jul 10 |
peter |
242 |
|
2291 |
07 Jul 10 |
peter |
243 |
set.insert_merge(Segment<double>(0,100)); |
2291 |
07 Jul 10 |
peter |
244 |
if (!suite.add(set.size()==1)) |
2291 |
07 Jul 10 |
peter |
245 |
suite.err() << "error: set.size(): " << set.size() << " expected 1\n"; |
3344 |
06 Nov 14 |
peter |
246 |
set.insert_merge(set.end(), Segment<double>(200, 1000)); |
3345 |
06 Nov 14 |
peter |
247 |
|
3345 |
06 Nov 14 |
peter |
248 |
SegmentSet<double> set2; |
3345 |
06 Nov 14 |
peter |
249 |
set2.insert_merge(set.begin(), set.end()); |
3345 |
06 Nov 14 |
peter |
250 |
std::vector<Segment<double> > vec(set.size()); |
3345 |
06 Nov 14 |
peter |
251 |
std::copy(set.begin(), set.end(), vec.begin()); |
3345 |
06 Nov 14 |
peter |
252 |
set2.insert_merge(vec.begin(), vec.end()); |
2296 |
08 Jul 10 |
peter |
253 |
} |
2291 |
07 Jul 10 |
peter |
254 |
|
3598 |
22 Jan 17 |
peter |
255 |
|
3598 |
22 Jan 17 |
peter |
256 |
void make_segment_foo(Segment<int> seg) |
3598 |
22 Jan 17 |
peter |
257 |
{ |
3598 |
22 Jan 17 |
peter |
258 |
} |
3598 |
22 Jan 17 |
peter |
259 |
|
3598 |
22 Jan 17 |
peter |
260 |
|
3598 |
22 Jan 17 |
peter |
261 |
void test_make_segment(test::Suite& suite) |
3598 |
22 Jan 17 |
peter |
262 |
{ |
3598 |
22 Jan 17 |
peter |
263 |
make_segment_foo(make_segment(12, 18)); |
3598 |
22 Jan 17 |
peter |
264 |
} |
3598 |
22 Jan 17 |
peter |
265 |
|
3598 |
22 Jan 17 |
peter |
266 |
|
2296 |
08 Jul 10 |
peter |
267 |
void test_set_bound(test::Suite& suite) |
2296 |
08 Jul 10 |
peter |
268 |
{ |
2296 |
08 Jul 10 |
peter |
269 |
SegmentSet<double> set; |
2296 |
08 Jul 10 |
peter |
270 |
set.insert(Segment<double>(0,2)); |
2291 |
07 Jul 10 |
peter |
271 |
set.begin(); |
2291 |
07 Jul 10 |
peter |
272 |
set.end(); |
2358 |
02 Dec 10 |
peter |
273 |
if (!suite.add(set.lower_bound(-1)==set.begin())) |
2291 |
07 Jul 10 |
peter |
274 |
suite.err() << "error: expected set.lower_bound to return begin()\n"; |
2358 |
02 Dec 10 |
peter |
275 |
if (!suite.add(set.lower_bound(1)==set.begin())) |
2349 |
17 Nov 10 |
peter |
276 |
suite.err() << "error: expected set.lower_bound to return begin()\n"; |
2358 |
02 Dec 10 |
peter |
277 |
if (!suite.add(set.lower_bound(2)==set.end())) |
2349 |
17 Nov 10 |
peter |
278 |
suite.err() << "error: expected set.lower_bound to return end()\n"; |
2349 |
17 Nov 10 |
peter |
279 |
|
2358 |
02 Dec 10 |
peter |
280 |
if (!suite.add(set.upper_bound(0)==set.end())) |
2291 |
07 Jul 10 |
peter |
281 |
suite.err() << "error: expected set.upper_bound to return end()\n"; |
2358 |
02 Dec 10 |
peter |
282 |
if (!suite.add(set.upper_bound(2)==set.end())) |
2358 |
02 Dec 10 |
peter |
283 |
suite.err() << "error: expected set.upper_bound to return end()\n"; |
2349 |
17 Nov 10 |
peter |
284 |
|
2349 |
17 Nov 10 |
peter |
285 |
set.insert_merge(Segment<double>(3,4)); |
2358 |
02 Dec 10 |
peter |
286 |
SegmentSet<double>::const_iterator i=set.lower_bound(3.5); |
2349 |
17 Nov 10 |
peter |
287 |
if (i->begin() != 3 || i->end() != 4) { |
2349 |
17 Nov 10 |
peter |
288 |
suite.add(false); |
2349 |
17 Nov 10 |
peter |
289 |
suite.out() << "found: " << i->begin() << " " << i->end() << "\n"; |
2349 |
17 Nov 10 |
peter |
290 |
suite.out() << "expected: 3 4\n"; |
2349 |
17 Nov 10 |
peter |
291 |
} |
2349 |
17 Nov 10 |
peter |
292 |
|
2358 |
02 Dec 10 |
peter |
293 |
i=set.lower_bound(1); |
2349 |
17 Nov 10 |
peter |
294 |
if (i->begin() != 0 || i->end() != 2) { |
2349 |
17 Nov 10 |
peter |
295 |
suite.add(false); |
2349 |
17 Nov 10 |
peter |
296 |
suite.out() << "found: " << i->begin() << " " << i->end() << "\n"; |
2349 |
17 Nov 10 |
peter |
297 |
suite.out() << "expected: 0 2\n"; |
2349 |
17 Nov 10 |
peter |
298 |
} |
2349 |
17 Nov 10 |
peter |
299 |
|
2296 |
08 Jul 10 |
peter |
300 |
set.clear(); |
2296 |
08 Jul 10 |
peter |
301 |
} |
2291 |
07 Jul 10 |
peter |
302 |
|
4027 |
17 Jan 21 |
peter |
303 |
|
2358 |
02 Dec 10 |
peter |
304 |
void test_segment_map(test::Suite& suite) |
2358 |
02 Dec 10 |
peter |
305 |
{ |
2358 |
02 Dec 10 |
peter |
306 |
typedef SegmentMap<double, std::string> Map; |
2358 |
02 Dec 10 |
peter |
307 |
Map map; |
2358 |
02 Dec 10 |
peter |
308 |
Map::element_type x = 0.0; |
2358 |
02 Dec 10 |
peter |
309 |
avoid_pedantic_warning(x); |
2358 |
02 Dec 10 |
peter |
310 |
Map::key_type key = Segment<double>(1.0,2.0); |
2358 |
02 Dec 10 |
peter |
311 |
Map::mapped_type mapped = "foofana"; |
2360 |
04 Dec 10 |
peter |
312 |
|
2360 |
04 Dec 10 |
peter |
313 |
map.insert(Map::value_type(key, mapped)); |
2360 |
04 Dec 10 |
peter |
314 |
suite.add(map.find(1.5) != map.end()); |
2360 |
04 Dec 10 |
peter |
315 |
suite.add(map.find(1.5)->second == "foofana"); |
2362 |
05 Dec 10 |
peter |
316 |
|
2362 |
05 Dec 10 |
peter |
317 |
Map::iterator i = map.begin(); |
2362 |
05 Dec 10 |
peter |
318 |
i = map.end(); |
2362 |
05 Dec 10 |
peter |
319 |
const Map const_map(map); |
2362 |
05 Dec 10 |
peter |
320 |
Map::const_iterator ci = const_map.begin(); |
2362 |
05 Dec 10 |
peter |
321 |
ci = const_map.end(); |
2362 |
05 Dec 10 |
peter |
322 |
|
2362 |
05 Dec 10 |
peter |
323 |
suite.add(map.size()==1); |
2362 |
05 Dec 10 |
peter |
324 |
map.clear(); |
2362 |
05 Dec 10 |
peter |
325 |
suite.add(map.empty()==true); |
2362 |
05 Dec 10 |
peter |
326 |
suite.add(map.size()==0); |
2362 |
05 Dec 10 |
peter |
327 |
map = const_map; |
2362 |
05 Dec 10 |
peter |
328 |
suite.add(map.size()==1); |
2362 |
05 Dec 10 |
peter |
329 |
suite.add(const_map.count(1.0)==1); |
2362 |
05 Dec 10 |
peter |
330 |
suite.add(const_map.count(0.0)==0); |
2362 |
05 Dec 10 |
peter |
331 |
suite.add(const_map.empty()==false); |
2362 |
05 Dec 10 |
peter |
332 |
suite.add(const_map.find(1.0)==const_map.begin()); |
2362 |
05 Dec 10 |
peter |
333 |
suite.add(const_map.find(30.0)==const_map.end()); |
2362 |
05 Dec 10 |
peter |
334 |
ci = const_map.lower_bound(0.0); |
2362 |
05 Dec 10 |
peter |
335 |
ci = const_map.upper_bound(0.0); |
2362 |
05 Dec 10 |
peter |
336 |
i = map.lower_bound(0.0); |
2362 |
05 Dec 10 |
peter |
337 |
i = map.upper_bound(0.0); |
2358 |
02 Dec 10 |
peter |
338 |
} |
2358 |
02 Dec 10 |
peter |
339 |
|
4027 |
17 Jan 21 |
peter |
340 |
|
4027 |
17 Jan 21 |
peter |
341 |
void test_segment_set(test::Suite& suite) |
4027 |
17 Jan 21 |
peter |
342 |
{ |
4027 |
17 Jan 21 |
peter |
343 |
SegmentSet<double> set; |
4027 |
17 Jan 21 |
peter |
344 |
Segment<double> segment(0.12,23.2); |
4027 |
17 Jan 21 |
peter |
345 |
set.insert_merge(segment); |
4027 |
17 Jan 21 |
peter |
346 |
set.insert_merge(Segment<double>(0.12,23.2)); |
4027 |
17 Jan 21 |
peter |
347 |
SegmentSet<double>::iterator hint = set.begin(); |
4027 |
17 Jan 21 |
peter |
348 |
set.insert_merge(hint, segment); |
4027 |
17 Jan 21 |
peter |
349 |
set.insert_merge(hint, Segment<double>(0.12,23.2)); |
4027 |
17 Jan 21 |
peter |
350 |
SegmentSet<double>::const_iterator chint = set.begin(); |
4027 |
17 Jan 21 |
peter |
351 |
set.insert_merge(chint, segment); |
4027 |
17 Jan 21 |
peter |
352 |
set.insert_merge(chint, Segment<double>(0.12,23.2)); |
4027 |
17 Jan 21 |
peter |
353 |
std::vector<Segment<double>> vec(set.begin(), set.end()); |
4027 |
17 Jan 21 |
peter |
354 |
set.insert_merge(vec.begin(), vec.end()); |
4027 |
17 Jan 21 |
peter |
355 |
|
4027 |
17 Jan 21 |
peter |
// test functions inherited from SegmentTree |
4027 |
17 Jan 21 |
peter |
357 |
SegmentSet<double>::const_iterator citer = set.begin(); |
4027 |
17 Jan 21 |
peter |
358 |
SegmentSet<double>::const_iterator iter = set.begin(); |
4027 |
17 Jan 21 |
peter |
359 |
|
4027 |
17 Jan 21 |
peter |
360 |
citer = set.end(); |
4027 |
17 Jan 21 |
peter |
361 |
iter = set.end(); |
4027 |
17 Jan 21 |
peter |
362 |
|
4027 |
17 Jan 21 |
peter |
363 |
if (set.count(0.13)!=1) { |
4027 |
17 Jan 21 |
peter |
364 |
suite.add(false); |
4027 |
17 Jan 21 |
peter |
365 |
suite.err() << "error: expected count = 1\n"; |
4027 |
17 Jan 21 |
peter |
366 |
} |
4027 |
17 Jan 21 |
peter |
367 |
if (set.count(0.02)!=0) { |
4027 |
17 Jan 21 |
peter |
368 |
suite.add(false); |
4027 |
17 Jan 21 |
peter |
369 |
suite.err() << "error: expected count = 0\n"; |
4027 |
17 Jan 21 |
peter |
370 |
} |
4027 |
17 Jan 21 |
peter |
371 |
if (set.empty()) { |
4027 |
17 Jan 21 |
peter |
372 |
suite.add(false); |
4027 |
17 Jan 21 |
peter |
373 |
suite.err() << "error: expected empty() return false"; |
4027 |
17 Jan 21 |
peter |
374 |
} |
4027 |
17 Jan 21 |
peter |
375 |
if (set.find(0.15) == set.end()) { |
4027 |
17 Jan 21 |
peter |
376 |
suite.add(false); |
4027 |
17 Jan 21 |
peter |
377 |
suite.err() << "error: find returned end()"; |
4027 |
17 Jan 21 |
peter |
378 |
} |
4027 |
17 Jan 21 |
peter |
379 |
set.erase(set.begin()); |
4027 |
17 Jan 21 |
peter |
380 |
set.clear(); |
4027 |
17 Jan 21 |
peter |
381 |
set.erase(set.begin(), set.end()); |
4027 |
17 Jan 21 |
peter |
382 |
|
4027 |
17 Jan 21 |
peter |
383 |
set.insert(segment); |
4027 |
17 Jan 21 |
peter |
384 |
set.insert(Segment<double>(102, 200)); |
4027 |
17 Jan 21 |
peter |
385 |
|
4027 |
17 Jan 21 |
peter |
386 |
iter = set.lower_bound(1.0); |
4027 |
17 Jan 21 |
peter |
387 |
citer = set.lower_bound(1.0); |
4027 |
17 Jan 21 |
peter |
388 |
iter = set.upper_bound(1.0); |
4027 |
17 Jan 21 |
peter |
389 |
citer = set.upper_bound(1.0); |
4027 |
17 Jan 21 |
peter |
390 |
SegmentSet<double>::size_type s = set.size(); |
4027 |
17 Jan 21 |
peter |
391 |
test::avoid_compiler_warning(s); |
4027 |
17 Jan 21 |
peter |
392 |
} |
4027 |
17 Jan 21 |
peter |
393 |
|
4027 |
17 Jan 21 |
peter |
394 |
|
2296 |
08 Jul 10 |
peter |
395 |
void test_segment(test::Suite& suite) |
2296 |
08 Jul 10 |
peter |
396 |
{ |
2293 |
07 Jul 10 |
peter |
397 |
Segment<double> segment12(0,2); |
2293 |
07 Jul 10 |
peter |
398 |
Segment<double> segment13(1,3); |
3449 |
07 Dec 15 |
peter |
399 |
if (segment12==segment13) { |
3449 |
07 Dec 15 |
peter |
400 |
suite.add(false); |
3449 |
07 Dec 15 |
peter |
401 |
suite.err() << "segment12==segment13 : expected false\n"; |
3449 |
07 Dec 15 |
peter |
402 |
} |
3449 |
07 Dec 15 |
peter |
403 |
if (!(segment12!=segment13)) { |
3449 |
07 Dec 15 |
peter |
404 |
suite.add(false); |
3449 |
07 Dec 15 |
peter |
405 |
suite.err() << "segment12!=segment13 : expected true\n"; |
3449 |
07 Dec 15 |
peter |
406 |
} |
2293 |
07 Jul 10 |
peter |
407 |
Segment<double> segment14 = intersection(segment12, segment13); |
2293 |
07 Jul 10 |
peter |
408 |
suite.add(segment14.begin()==1); |
2293 |
07 Jul 10 |
peter |
409 |
suite.add(segment14.end()==2); |
2293 |
07 Jul 10 |
peter |
410 |
|
2294 |
07 Jul 10 |
peter |
411 |
if (!suite.add(compare(Segment<double>(0,2), Segment<double>(3,4)))) |
2294 |
07 Jul 10 |
peter |
412 |
suite.err() << "error: compare: expected 1\n"; |
2294 |
07 Jul 10 |
peter |
413 |
if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(3,4))==-1)) |
2294 |
07 Jul 10 |
peter |
414 |
suite.err() << "error: compare_3way: expected -1\n"; |
2294 |
07 Jul 10 |
peter |
415 |
|
2294 |
07 Jul 10 |
peter |
416 |
if (!suite.add(compare(Segment<double>(0,2), Segment<double>(1,2))==false)) |
2294 |
07 Jul 10 |
peter |
417 |
suite.err() << "error: compare: expected 0\n"; |
2294 |
07 Jul 10 |
peter |
418 |
if (!suite.add(compare_3way(Segment<double>(0,2), Segment<double>(1,2))==0)) |
2294 |
07 Jul 10 |
peter |
419 |
suite.err() << "error: compare_3way: expected 0\n"; |
2294 |
07 Jul 10 |
peter |
420 |
|
2294 |
07 Jul 10 |
peter |
421 |
if (!suite.add(compare(Segment<double>(3,4), Segment<double>(0,2))==false)) |
2294 |
07 Jul 10 |
peter |
422 |
suite.err() << "error: compare: expected 0\n"; |
2294 |
07 Jul 10 |
peter |
423 |
if (!suite.add(compare_3way(Segment<double>(3,4), Segment<double>(0,2))==1)) |
2294 |
07 Jul 10 |
peter |
424 |
suite.err() << "error: compare_3way: expected 1\n"; |
2294 |
07 Jul 10 |
peter |
425 |
|
2291 |
07 Jul 10 |
peter |
426 |
} |
3649 |
15 Jun 17 |
peter |
427 |
|
3649 |
15 Jun 17 |
peter |
428 |
|
3649 |
15 Jun 17 |
peter |
429 |
void test_includes(test::Suite& suite, const Segment<int>& a, |
3649 |
15 Jun 17 |
peter |
430 |
const Segment<int>& b, bool answer) |
3649 |
15 Jun 17 |
peter |
431 |
{ |
3649 |
15 Jun 17 |
peter |
432 |
if (includes(a, b) != answer) { |
3649 |
15 Jun 17 |
peter |
433 |
suite.add(false); |
3649 |
15 Jun 17 |
peter |
434 |
suite.err() << "error: includes: " |
3649 |
15 Jun 17 |
peter |
435 |
<< "[" << a.begin() << ", " |
3649 |
15 Jun 17 |
peter |
436 |
<< a.end() << ") " |
3649 |
15 Jun 17 |
peter |
437 |
<< "[" << b.begin() << ", " |
3649 |
15 Jun 17 |
peter |
438 |
<< b.end() << ") " |
3649 |
15 Jun 17 |
peter |
439 |
<< "expected: " << answer << "\n"; |
3649 |
15 Jun 17 |
peter |
440 |
} |
3649 |
15 Jun 17 |
peter |
441 |
} |
3649 |
15 Jun 17 |
peter |
442 |
|
3649 |
15 Jun 17 |
peter |
443 |
|
3649 |
15 Jun 17 |
peter |
444 |
void test_includes(test::Suite& suite) |
3649 |
15 Jun 17 |
peter |
445 |
{ |
3649 |
15 Jun 17 |
peter |
446 |
Segment<int> a(0, 10); |
3649 |
15 Jun 17 |
peter |
447 |
Segment<int> b(0, 5); |
3649 |
15 Jun 17 |
peter |
448 |
Segment<int> c(5, 10); |
3649 |
15 Jun 17 |
peter |
449 |
|
3649 |
15 Jun 17 |
peter |
450 |
test_includes(suite, a, a, true); |
3649 |
15 Jun 17 |
peter |
451 |
test_includes(suite, a, b, false); |
3649 |
15 Jun 17 |
peter |
452 |
test_includes(suite, a, c, false); |
3649 |
15 Jun 17 |
peter |
453 |
|
3649 |
15 Jun 17 |
peter |
454 |
test_includes(suite, b, a, true); |
3649 |
15 Jun 17 |
peter |
455 |
test_includes(suite, b, b, true); |
3649 |
15 Jun 17 |
peter |
456 |
test_includes(suite, b, c, false); |
3649 |
15 Jun 17 |
peter |
457 |
|
3649 |
15 Jun 17 |
peter |
458 |
test_includes(suite, c, a, true); |
3649 |
15 Jun 17 |
peter |
459 |
test_includes(suite, c, b, false); |
3649 |
15 Jun 17 |
peter |
460 |
test_includes(suite, c, c, true); |
3649 |
15 Jun 17 |
peter |
461 |
} |
3649 |
15 Jun 17 |
peter |
462 |
|
3649 |
15 Jun 17 |
peter |
463 |
|
3649 |
15 Jun 17 |
peter |
464 |
void test_overlap(test::Suite& suite, const Segment<int>& a, |
3649 |
15 Jun 17 |
peter |
465 |
const Segment<int>& b, bool answer) |
3649 |
15 Jun 17 |
peter |
466 |
{ |
3649 |
15 Jun 17 |
peter |
467 |
if (overlap(a, b) != answer) { |
3649 |
15 Jun 17 |
peter |
468 |
suite.add(false); |
3649 |
15 Jun 17 |
peter |
469 |
suite.err() << "error: overlap: " |
3649 |
15 Jun 17 |
peter |
470 |
<< "[" << a.begin() << ", " |
3649 |
15 Jun 17 |
peter |
471 |
<< a.end() << ") " |
3649 |
15 Jun 17 |
peter |
472 |
<< "[" << b.begin() << ", " |
3649 |
15 Jun 17 |
peter |
473 |
<< b.end() << ") " |
3649 |
15 Jun 17 |
peter |
474 |
<< "expected: " << answer << "\n"; |
3649 |
15 Jun 17 |
peter |
475 |
} |
3649 |
15 Jun 17 |
peter |
476 |
} |
3649 |
15 Jun 17 |
peter |
477 |
|
3649 |
15 Jun 17 |
peter |
478 |
|
3649 |
15 Jun 17 |
peter |
479 |
void test_overlap(test::Suite& suite) |
3649 |
15 Jun 17 |
peter |
480 |
{ |
3649 |
15 Jun 17 |
peter |
481 |
Segment<int> a(0, 10); |
3649 |
15 Jun 17 |
peter |
482 |
Segment<int> b(0, 5); |
3649 |
15 Jun 17 |
peter |
483 |
Segment<int> c(5, 10); |
3649 |
15 Jun 17 |
peter |
484 |
|
3649 |
15 Jun 17 |
peter |
485 |
test_overlap(suite, a, a, true); |
3649 |
15 Jun 17 |
peter |
486 |
test_overlap(suite, a, b, true); |
3649 |
15 Jun 17 |
peter |
487 |
test_overlap(suite, a, c, true); |
3649 |
15 Jun 17 |
peter |
488 |
|
3649 |
15 Jun 17 |
peter |
489 |
test_overlap(suite, b, a, true); |
3649 |
15 Jun 17 |
peter |
490 |
test_overlap(suite, b, b, true); |
3649 |
15 Jun 17 |
peter |
491 |
test_overlap(suite, b, c, false); |
3649 |
15 Jun 17 |
peter |
492 |
|
3649 |
15 Jun 17 |
peter |
493 |
test_overlap(suite, c, a, true); |
3649 |
15 Jun 17 |
peter |
494 |
test_overlap(suite, c, b, false); |
3649 |
15 Jun 17 |
peter |
495 |
test_overlap(suite, c, c, true); |
3649 |
15 Jun 17 |
peter |
496 |
} |
3650 |
18 Jun 17 |
peter |
497 |
|
3650 |
18 Jun 17 |
peter |
498 |
|
3650 |
18 Jun 17 |
peter |
499 |
void test_union(test::Suite& suite, const Segment<int>& a, |
3650 |
18 Jun 17 |
peter |
500 |
const Segment<int>& b, const Segment<int>& answer) |
3650 |
18 Jun 17 |
peter |
501 |
{ |
3650 |
18 Jun 17 |
peter |
502 |
if (set_union(a, b) != answer) { |
3650 |
18 Jun 17 |
peter |
503 |
suite.add(false); |
3650 |
18 Jun 17 |
peter |
504 |
suite.err() << "error: union: " |
3650 |
18 Jun 17 |
peter |
505 |
<< "[" << a.begin() << ", " |
3650 |
18 Jun 17 |
peter |
506 |
<< a.end() << ") " |
3650 |
18 Jun 17 |
peter |
507 |
<< "[" << b.begin() << ", " |
3650 |
18 Jun 17 |
peter |
508 |
<< b.end() << ") " |
3650 |
18 Jun 17 |
peter |
509 |
<< "expected: [" << answer.begin() << "," << answer.end() |
3650 |
18 Jun 17 |
peter |
510 |
<< " )\n"; |
3650 |
18 Jun 17 |
peter |
511 |
} |
3650 |
18 Jun 17 |
peter |
512 |
} |
3650 |
18 Jun 17 |
peter |
513 |
|
3650 |
18 Jun 17 |
peter |
514 |
|
3650 |
18 Jun 17 |
peter |
515 |
void test_union(test::Suite& suite) |
3650 |
18 Jun 17 |
peter |
516 |
{ |
3650 |
18 Jun 17 |
peter |
517 |
Segment<int> a(0, 10); |
3650 |
18 Jun 17 |
peter |
518 |
Segment<int> b(0, 5); |
3650 |
18 Jun 17 |
peter |
519 |
Segment<int> c(5, 12); |
3650 |
18 Jun 17 |
peter |
520 |
|
3650 |
18 Jun 17 |
peter |
521 |
test_union(suite, a, a, a); |
3650 |
18 Jun 17 |
peter |
522 |
test_union(suite, a, b, a); |
3650 |
18 Jun 17 |
peter |
523 |
test_union(suite, a, c, Segment<int>(0,12)); |
3650 |
18 Jun 17 |
peter |
524 |
|
3650 |
18 Jun 17 |
peter |
525 |
test_union(suite, b, a, a); |
3650 |
18 Jun 17 |
peter |
526 |
test_union(suite, b, b, b); |
3650 |
18 Jun 17 |
peter |
527 |
test_union(suite, b, c, Segment<int>(0,12)); |
3650 |
18 Jun 17 |
peter |
528 |
|
3650 |
18 Jun 17 |
peter |
529 |
test_union(suite, c, a, Segment<int>(0,12)); |
3650 |
18 Jun 17 |
peter |
530 |
test_union(suite, c, b, Segment<int>(0,12)); |
3650 |
18 Jun 17 |
peter |
531 |
test_union(suite, c, c, c); |
3650 |
18 Jun 17 |
peter |
532 |
} |