1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2011-2011: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #define BOOST_TEST_MODULE icl::fix_icl_after_thread unit test
9 #include <libs/icl/test/disable_test_warnings.hpp>
10 #include "../unit_test_unwarned.hpp"
11
12 //#define BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
13 #include <boost/icl/interval_map.hpp>
14 #include <boost/icl/split_interval_map.hpp>
15 #include <boost/icl/separate_interval_set.hpp>
16 #include <boost/icl/split_interval_set.hpp>
17
18 #include <iostream>
19
20 using namespace std;
21 using namespace boost;
22 using namespace unit_test;
23 using namespace boost::icl;
24
25
BOOST_AUTO_TEST_CASE(ticket_5482)26 BOOST_AUTO_TEST_CASE(ticket_5482)
27 {
28 typedef interval_map<int,int,partial_absorber,std::less> m1_t;
29 typedef interval_map<int,int,partial_absorber,std::greater> m2_t;
30 m1_t m1;
31 m2_t m2;
32 m1.insert(make_pair(m1_t::interval_type(1), 20));
33 m1.insert(make_pair(m1_t::interval_type(2), 20));
34 m1.insert(make_pair(m1_t::interval_type(3), 20));
35
36 m2.insert(make_pair(m2_t::interval_type(1), 20));
37 m2.insert(make_pair(m2_t::interval_type(2), 20));
38 m2.insert(make_pair(m2_t::interval_type(3), 20));
39
40 BOOST_CHECK_EQUAL(m1.iterative_size(), m2.iterative_size());
41 BOOST_CHECK_EQUAL(m1.iterative_size(), 1);
42 BOOST_CHECK_EQUAL(m2.iterative_size(), 1);
43 }
44
45
46 #include <boost/cstdint.hpp>
BOOST_AUTO_TEST_CASE(ticket_5559_Denis)47 BOOST_AUTO_TEST_CASE(ticket_5559_Denis)
48 {
49 //Submitted by Denis
50 typedef boost::icl::interval_set<boost::uint32_t, std::greater> Set;
51 const uint32_t ui32_max = (std::numeric_limits<uint32_t>::max)();
52
53 Set q1( Set::interval_type::closed(ui32_max, 0) );
54 Set q5( Set::interval_type::closed(0, 0) );
55
56 BOOST_CHECK_EQUAL(q1, q1+q5);
57 }
58
59 //------------------------------------------------------------------------------
60 // Ticket #6095 Marvin Sielenkemper
61 //------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(ticket_6095_Marvin_Sielenkemper_isEmptyTest)62 BOOST_AUTO_TEST_CASE(ticket_6095_Marvin_Sielenkemper_isEmptyTest)
63 {
64 typedef int Value;
65 typedef boost::icl::interval<Value> Interval;
66 typedef std::numeric_limits<Value> Limits;
67
68 Value const max((Limits::max)());
69
70 //Interval::interval_type piff = Interval::open(max, max);
71
72 BOOST_CHECK(!icl::is_empty(Interval::open(max - 2, max)));
73 BOOST_CHECK( icl::is_empty(Interval::open(max - 1, max)));
74 BOOST_CHECK( icl::is_empty(Interval::open(max, max)));
75 }
76
BOOST_AUTO_TEST_CASE(ticket_6095_Marvin_Sielenkemper_totalRangeTest)77 BOOST_AUTO_TEST_CASE(ticket_6095_Marvin_Sielenkemper_totalRangeTest)
78 {
79 typedef int Value;
80 typedef boost::icl::interval<Value> Interval;
81 typedef std::numeric_limits<Value> Limits;
82
83 Value const min((Limits::min)());
84 Value const max((Limits::max)());
85
86 boost::icl::interval_map<Value, int, boost::icl::total_enricher> intervals;
87
88 intervals += std::make_pair(Interval::closed(min, max), 0);
89 intervals += std::make_pair(Interval::right_open(0, 10), 3);
90
91 BOOST_CHECK_EQUAL(intervals.iterative_size(), 3);
92 }
93
BOOST_AUTO_TEST_CASE(test_ticket_7871)94 BOOST_AUTO_TEST_CASE(test_ticket_7871)
95 {
96 boost::icl::split_interval_map <int, int> a, b;
97 a = b;
98 BOOST_CHECK_EQUAL(a, b);
99 }
100
101 //------------------------------------------------------------------------------
102 // Ticket #11308 Stephen Hewitt
103 //------------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(ticket_11308_Stephen_Hewitt_extreme_valued_closed_intervals)104 BOOST_AUTO_TEST_CASE(ticket_11308_Stephen_Hewitt_extreme_valued_closed_intervals)
105 {
106 typedef boost::icl::closed_interval<boost::uint16_t, std::less> interval_t;
107 typedef boost::icl::split_interval_set<boost::uint16_t, std::less, interval_t> set_t;
108
109 set_t s1, s2;
110
111 s1 += interval_t(0x0000, 0x9fff);
112 s1 += interval_t(0xa000, 0xbfff);
113 s1 += interval_t(0xc000, 0xffff);
114
115 s2 += interval_t(0x0000, 0xffff);
116 s2 += interval_t(0xa000, 0xbfff);
117
118 BOOST_CHECK_EQUAL(s1, s2);
119 }
120
BOOST_AUTO_TEST_CASE(extreme_valued_right_open_intervals)121 BOOST_AUTO_TEST_CASE(extreme_valued_right_open_intervals)
122 {
123 typedef boost::icl::right_open_interval<boost::uint16_t, std::less> interval_t;
124 typedef boost::icl::split_interval_set<boost::uint16_t, std::less, interval_t> set_t;
125
126 set_t s1, s2;
127
128 s1 += interval_t(0x0000, 0xa000);
129 s1 += interval_t(0xa000, 0xc000);
130 s1 += interval_t(0xc000, 0xffff); //Contains 0xfffe as largest element
131
132 s2 += interval_t(0x0000, 0xffff);
133 s2 += interval_t(0xa000, 0xc000);
134
135 BOOST_CHECK_EQUAL(s1, s2);
136 }
137
BOOST_AUTO_TEST_CASE(extreme_valued_left_open_intervals)138 BOOST_AUTO_TEST_CASE(extreme_valued_left_open_intervals)
139 {
140 typedef boost::icl::left_open_interval<boost::uint16_t, std::less> interval_t;
141 typedef boost::icl::split_interval_set<boost::uint16_t, std::less, interval_t> set_t;
142
143 set_t s1, s2;
144
145 s1 += interval_t(0x0000, 0x9fff); //Contains 1 as smallest element
146 s1 += interval_t(0x9fff, 0xbfff);
147 s1 += interval_t(0xbfff, 0xffff);
148
149 s2 += interval_t(0x0000, 0xffff);
150 s2 += interval_t(0x9fff, 0xbfff);
151
152 BOOST_CHECK_EQUAL(s1, s2);
153 }
154
BOOST_AUTO_TEST_CASE(extreme_valued_open_intervals)155 BOOST_AUTO_TEST_CASE(extreme_valued_open_intervals)
156 {
157 typedef boost::icl::open_interval<boost::uint16_t, std::less> interval_t;
158 typedef boost::icl::split_interval_set<boost::uint16_t, std::less, interval_t> set_t;
159
160 set_t s1, s2;
161
162 s1 += interval_t(0x0000, 0xa000); //Contains 1 as smallest element
163 s1 += interval_t(0x9fff, 0xc000);
164 s1 += interval_t(0xbfff, 0xffff); //Contains 0xfffe as largest element
165
166 s2 += interval_t(0x0000, 0xffff);
167 s2 += interval_t(0x9fff, 0xc000);
168
169 BOOST_CHECK_EQUAL(s1, s2);
170 }
171
BOOST_AUTO_TEST_CASE(test_span_and_hull)172 BOOST_AUTO_TEST_CASE(test_span_and_hull)
173 {
174 typedef closed_interval<int> cl_I_int;
175 cl_I_int span_1_2 = span< cl_I_int >(1,2);
176 cl_I_int span_2_1 = span< cl_I_int >(2,1);
177 BOOST_CHECK_EQUAL(span_1_2, span_2_1);
178 BOOST_CHECK_EQUAL(hull< cl_I_int >(1,2), hull< cl_I_int >(2,1));
179
180 BOOST_CHECK_EQUAL( span< right_open_interval<int> >(2,1)
181 , construct< right_open_interval<int> >(1,2) );
182
183 BOOST_CHECK_EQUAL( hull< right_open_interval<int> >(2,1)
184 , construct< right_open_interval<int> >(1,3) );
185 }
186
BOOST_AUTO_TEST_CASE(test_ticket_11942)187 BOOST_AUTO_TEST_CASE(test_ticket_11942)
188 {
189 boost::icl::split_interval_set<int> intervals;
190 intervals.insert(boost::icl::discrete_interval<int>(1, 2));
191 intervals.insert(boost::icl::discrete_interval<int>(2, 3));
192 intervals.insert(boost::icl::discrete_interval<int>(0, 3));
193
194 BOOST_CHECK_EQUAL(intervals.size(), 3);
195 }
196
BOOST_AUTO_TEST_CASE(test_ticket_12872)197 BOOST_AUTO_TEST_CASE(test_ticket_12872)
198 {
199 boost::icl::split_interval_set<unsigned> ss
200 = boost::icl::split_interval_set<unsigned>();
201 std::vector<std::pair<unsigned, unsigned> > rs;
202 rs.push_back(make_pair(88, 96));
203 rs.push_back(make_pair(72, 96));
204 rs.push_back(make_pair(80, 96));
205 rs.push_back(make_pair(24, 64));
206 rs.push_back(make_pair(80, 96));
207 rs.push_back(make_pair(32, 72));
208 rs.push_back(make_pair(88, 96));
209 rs.push_back(make_pair(16, 56));
210 // {{88, 96}, {72, 96}, {80, 96}, {24, 64}, {80, 96}, {32, 72},
211 // {88, 96}, {16, 56}};
212
213 for(int i=0; i < rs.size(); i++) {
214 ss.add( boost::icl::interval<unsigned>::right_open(rs[i].first, rs[i].second) );
215 }
216
217 boost::icl::split_interval_map<unsigned, unsigned> im
218 = boost::icl::split_interval_map<unsigned, unsigned>();
219 for(int i=0; i < rs.size(); i++) {
220 im.add( make_pair( boost::icl::interval<unsigned>::right_open(rs[i].first, rs[i].second), 1 ) );
221 }
222
223 BOOST_CHECK_EQUAL(interval_count(ss), interval_count(im));
224 BOOST_CHECK_EQUAL(icl::size(ss), icl::size(im));
225 BOOST_CHECK_EQUAL(hull(ss), hull(im));
226 }
227
BOOST_AUTO_TEST_CASE(test_ticket_12926)228 BOOST_AUTO_TEST_CASE(test_ticket_12926)
229 {
230 boost::icl::interval_set<int> a;
231 a.insert(boost::icl::interval<int>::right_open(-100, 100));
232 a.insert(-50);
233
234 BOOST_CHECK_EQUAL(a.size(), 200);
235 }
236
237