| 1 | #pragma warning(push, 0)
|
|---|
| 2 | #include <boost/icl/split_interval_map.hpp>
|
|---|
| 3 | #include <boost/operators.hpp>
|
|---|
| 4 | #include <boost/test/unit_test.hpp>
|
|---|
| 5 | #pragma warning(pop)
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | namespace
|
|---|
| 9 | {
|
|---|
| 10 | struct SplitIntervalMapFixture
|
|---|
| 11 | {
|
|---|
| 12 | struct TestEntry
|
|---|
| 13 | : boost::equality_comparable<TestEntry>
|
|---|
| 14 | , boost::additive<TestEntry>
|
|---|
| 15 | {
|
|---|
| 16 | static size_t createCount;
|
|---|
| 17 | static size_t addCount;
|
|---|
| 18 | static size_t subCount;
|
|---|
| 19 |
|
|---|
| 20 | TestEntry() { ++createCount; }
|
|---|
| 21 |
|
|---|
| 22 | TestEntry& operator+=(TestEntry const& other) { ++addCount; return *this; }
|
|---|
| 23 | TestEntry& operator-=(TestEntry const& other) { ++subCount; return *this; }
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | typedef boost::icl::split_interval_map<int, TestEntry> TestContainer;
|
|---|
| 27 | typedef TestContainer::interval_type TestInterval;
|
|---|
| 28 |
|
|---|
| 29 | TestContainer container;
|
|---|
| 30 | TestEntry entry;
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | size_t SplitIntervalMapFixture::TestEntry::createCount;
|
|---|
| 34 | size_t SplitIntervalMapFixture::TestEntry::addCount;
|
|---|
| 35 | size_t SplitIntervalMapFixture::TestEntry::subCount;
|
|---|
| 36 |
|
|---|
| 37 | bool operator==(SplitIntervalMapFixture::TestEntry const& fst, SplitIntervalMapFixture::TestEntry const& snd)
|
|---|
| 38 | {
|
|---|
| 39 | return false;
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | BOOST_FIXTURE_TEST_SUITE(SplitIntervalMap_Tests, SplitIntervalMapFixture)
|
|---|
| 45 |
|
|---|
| 46 | BOOST_AUTO_TEST_CASE(add_noHint_Test)
|
|---|
| 47 | {
|
|---|
| 48 | TestEntry::createCount = 0;
|
|---|
| 49 | TestEntry::addCount = 0;
|
|---|
| 50 | TestEntry::subCount = 0;
|
|---|
| 51 |
|
|---|
| 52 | add(container, std::make_pair(TestInterval::right_open(10, 20), entry));
|
|---|
| 53 |
|
|---|
| 54 | BOOST_CHECK_EQUAL(TestEntry::createCount, 1); // for the absorption test
|
|---|
| 55 | BOOST_CHECK_EQUAL(TestEntry::addCount, 0);
|
|---|
| 56 | BOOST_CHECK_EQUAL(TestEntry::subCount, 0);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | BOOST_AUTO_TEST_CASE(add_hint_Test)
|
|---|
| 61 | {
|
|---|
| 62 | TestEntry::createCount = 0;
|
|---|
| 63 | TestEntry::addCount = 0;
|
|---|
| 64 | TestEntry::subCount = 0;
|
|---|
| 65 |
|
|---|
| 66 | container.add(container.begin(), std::make_pair(TestInterval::right_open(10, 20), entry));
|
|---|
| 67 |
|
|---|
| 68 | BOOST_CHECK_EQUAL(TestEntry::createCount, 1); // but is 5
|
|---|
| 69 | BOOST_CHECK_EQUAL(TestEntry::addCount, 0); // but is 1
|
|---|
| 70 | BOOST_CHECK_EQUAL(TestEntry::subCount, 0);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | BOOST_AUTO_TEST_SUITE_END()
|
|---|