Hopefully less bad version of Evoral::RangeList::subtract,

with more tests.


git-svn-id: svn://localhost/ardour2/branches/3.0@12514 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2012-05-31 20:23:31 +00:00
parent 19becdf7e0
commit a6786a6dd2
3 changed files with 120 additions and 17 deletions

View file

@ -1,5 +1,6 @@
#include "RangeTest.hpp"
#include "evoral/Range.hpp"
#include <stdlib.h>
CPPUNIT_TEST_SUITE_REGISTRATION (RangeTest);
@ -24,6 +25,7 @@ RangeTest::coalesceTest ()
CPPUNIT_ASSERT_EQUAL (8, i->to);
}
/* Basic subtraction of a few smaller ranges from a larger one */
void
RangeTest::subtractTest1 ()
{
@ -51,6 +53,7 @@ RangeTest::subtractTest1 ()
CPPUNIT_ASSERT_EQUAL (10, i->to);
}
/* Test subtraction of a range B from a range A, where A and B do not overlap */
void
RangeTest::subtractTest2 ()
{
@ -69,6 +72,7 @@ RangeTest::subtractTest2 ()
CPPUNIT_ASSERT_EQUAL (10, i->to);
}
/* Test subtraction of B from A, where B entirely overlaps A */
void
RangeTest::subtractTest3 ()
{
@ -82,3 +86,62 @@ RangeTest::subtractTest3 ()
RangeList<int>::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (0), s.size ());
}
/* A bit like subtractTest1, except some of the ranges
we are subtracting overlap.
*/
void
RangeTest::subtractTest4 ()
{
Range<int> fred (0, 10);
RangeList<int> jim;
jim.add (Range<int> (2, 4));
jim.add (Range<int> (7, 8));
jim.add (Range<int> (8, 9));
RangeList<int> sheila = subtract (fred, jim);
RangeList<int>::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (3), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (0, i->from);
CPPUNIT_ASSERT_EQUAL (1, i->to);
++i;
CPPUNIT_ASSERT_EQUAL (4, i->from);
CPPUNIT_ASSERT_EQUAL (6, i->to);
++i;
CPPUNIT_ASSERT_EQUAL (9, i->from);
CPPUNIT_ASSERT_EQUAL (10, i->to);
}
/* A bit like subtractTest1, except some of the ranges
we are subtracting overlap the start / end of the
initial range.
*/
void
RangeTest::subtractTest5 ()
{
Range<int> fred (1, 12);
RangeList<int> jim;
jim.add (Range<int> (0, 4));
jim.add (Range<int> (6, 7));
jim.add (Range<int> (9, 42));
RangeList<int> sheila = subtract (fred, jim);
RangeList<int>::List s = sheila.get ();
CPPUNIT_ASSERT_EQUAL (size_t (2), s.size ());
RangeList<int>::List::iterator i = s.begin ();
CPPUNIT_ASSERT_EQUAL (4, i->from);
CPPUNIT_ASSERT_EQUAL (5, i->to);
++i;
CPPUNIT_ASSERT_EQUAL (7, i->from);
CPPUNIT_ASSERT_EQUAL (8, i->to);
}