1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2015, Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
12 #ifndef BOOST_TEST_MODULE
13 #define BOOST_TEST_MODULE test_maximum_gap
16 #include <boost/test/included/unit_test.hpp>
24 #include <boost/geometry/algorithms/detail/max_interval_gap.hpp>
26 namespace bg
= boost::geometry
;
31 typedef unsigned value_type
;
32 typedef int difference_type
;
34 uint_interval(unsigned left
, unsigned right
)
39 template <std::size_t Index
>
40 value_type
get() const
42 return (Index
== 0) ? m_left
: m_right
;
45 difference_type
length() const
47 return static_cast<int>(m_right
) - static_cast<int>(m_left
);
51 unsigned m_left
, m_right
;
55 : public std::vector
<uint_interval
>
60 uint_intervals(unsigned left
, unsigned right
)
62 this->push_back(uint_interval(left
, right
));
65 uint_intervals
& operator()(unsigned left
, unsigned right
)
67 this->push_back(uint_interval(left
, right
));
72 std::ostream
& operator<<(std::ostream
& os
, uint_interval
const& interval
)
74 os
<< "[" << interval
.get
<0>() << ", " << interval
.get
<1>() << "]";
79 template <typename RangeOfIntervals
>
80 inline void test_one(std::string
const& case_id
,
81 RangeOfIntervals
const& intervals
,
82 typename
boost::range_value
85 >::type::difference_type expected_gap
)
87 typedef typename
boost::range_value
<RangeOfIntervals
>::type interval_type
;
88 typedef typename
interval_type::difference_type gap_type
;
90 gap_type gap
= bg::maximum_gap(intervals
);
92 std::ostringstream stream
;
93 for (typename
boost::range_const_iterator
<RangeOfIntervals
>::type
94 it
= boost::const_begin(intervals
);
95 it
!= boost::const_end(intervals
);
101 #ifdef BOOST_GEOMETRY_TEST_DEBUG
102 std::cout
<< "intervals:" << stream
.str() << std::endl
;
103 std::cout
<< "gap found? " << ((gap
> 0) ? "yes" : "no") << std::endl
;
104 std::cout
<< "max gap length: " << gap
<< std::endl
;
105 std::cout
<< std::endl
<< std::endl
;
108 BOOST_CHECK_MESSAGE(gap
== expected_gap
,
109 case_id
<< "; intervals: "
111 << "; expected: " << expected_gap
112 << ", detected: " << gap
);
115 BOOST_AUTO_TEST_CASE( test_maximum_gap
)
117 uint_intervals intervals
;
119 intervals
= uint_intervals(3,4)(1,10)(5,11)(20,35)(12,14)(36,40)(39,41)(35,36)(37,37)(50,50)(50,51);
120 test_one("case_01", intervals
, 9);
122 intervals
= uint_intervals(3,4)(1,10)(5,11)(20,35)(52,60)(12,14)(36,40)(39,41)(35,36)(37,37)(55,56);
123 test_one("case_02", intervals
, 11);
125 intervals
= uint_intervals(3,4);
126 test_one("case_03", intervals
, 0);
128 intervals
= uint_intervals(3,4)(15,15);
129 test_one("case_04", intervals
, 11);
131 intervals
= uint_intervals(3,14)(5,5)(5,6);
132 test_one("case_05", intervals
, 0);
134 intervals
= uint_intervals(3,10)(15,15)(15,18)(15,16);
135 test_one("case_06", intervals
, 5);
137 intervals
= uint_intervals(38,41)(3,10)(15,15)(15,18)(15,16)(20,30)(22,30)(23,30);
138 test_one("case_07", intervals
, 8);