interval contains
This commit is contained in:
parent
4258caf522
commit
2eda92fe7a
@ -15,6 +15,10 @@ bool Interval::intersects(Interval & interval) {
|
||||
interval.getEnd() - 1 < _start);
|
||||
}
|
||||
|
||||
bool Interval::contains(Interval & interval) {
|
||||
return (_start <= interval.getStart() && _end >= interval.getEnd());
|
||||
}
|
||||
|
||||
SUFFIX_MARKER_TYPE Interval::getLength() {
|
||||
return _end - _start;
|
||||
}
|
||||
|
@ -32,6 +32,12 @@ public:
|
||||
*/
|
||||
bool intersects(Interval & interval);
|
||||
|
||||
/*! Checks if this interval contains another.
|
||||
\param interval another interval
|
||||
\returns true if this interval contains the other
|
||||
*/
|
||||
bool contains(Interval & interval);
|
||||
|
||||
/*! Getter for interval length.
|
||||
\returns end - start
|
||||
*/
|
||||
|
@ -68,4 +68,37 @@ BOOST_AUTO_TEST_CASE( IntervalIntersects8 )
|
||||
BOOST_CHECK(!interval2.intersects(interval1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( IntervalContains1 )
|
||||
{
|
||||
Interval interval1(2,9);
|
||||
Interval interval2(3,7);
|
||||
BOOST_CHECK(interval1.contains(interval2));
|
||||
BOOST_CHECK(!interval2.contains(interval1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( IntervalContains2 )
|
||||
{
|
||||
Interval interval1(3,9);
|
||||
Interval interval2(3,7);
|
||||
BOOST_CHECK(interval1.contains(interval2));
|
||||
BOOST_CHECK(!interval2.contains(interval1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( IntervalContains3 )
|
||||
{
|
||||
Interval interval1(4,9);
|
||||
Interval interval2(3,7);
|
||||
BOOST_CHECK(!interval1.contains(interval2));
|
||||
BOOST_CHECK(!interval2.contains(interval1));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( IntervalContains4 )
|
||||
{
|
||||
Interval interval1(2,9);
|
||||
Interval interval2(3,17);
|
||||
BOOST_CHECK(!interval1.contains(interval2));
|
||||
BOOST_CHECK(!interval2.contains(interval1));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user