summaryrefslogtreecommitdiff
path: root/o3tl/qa
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-07-13 13:55:15 +0200
committerMichael Stahl <mstahl@redhat.com>2012-07-17 15:28:09 +0200
commit0f57086b221eb1e7d3d9d7cdb6f3cdcb50f1edda (patch)
tree7f0561cf75ee89cd390cc7ffe074e0ea25d14af8 /o3tl/qa
parent1d6830ec60f726b0e6ecd1d0d0062825c1edbb2a (diff)
Improvements to sorted_vector
Implement suggestionss from David Tardon, mostly around prohibiting access that could result in the vector becoming unsorted. Add front() and back() accessors. Add lower_bound() method. Add optimised insert() method. Change-Id: Icbb3597277f3e5963573b57d4f6d3cb740e896e6
Diffstat (limited to 'o3tl/qa')
-rw-r--r--o3tl/qa/test-sorted_vector.cxx40
1 files changed, 40 insertions, 0 deletions
diff --git a/o3tl/qa/test-sorted_vector.cxx b/o3tl/qa/test-sorted_vector.cxx
index 11732bd5f875..16dc1dd36173 100644
--- a/o3tl/qa/test-sorted_vector.cxx
+++ b/o3tl/qa/test-sorted_vector.cxx
@@ -50,6 +50,12 @@ public:
CPPUNIT_ASSERT( aVec[0] == p1 );
CPPUNIT_ASSERT( aVec[1] == p3 );
+ CPPUNIT_ASSERT( *aVec.begin() == p1 );
+ CPPUNIT_ASSERT( *(aVec.end()-1) == p3 );
+
+ CPPUNIT_ASSERT( aVec.front() == p1 );
+ CPPUNIT_ASSERT( aVec.back() == p3 );
+
CPPUNIT_ASSERT( aVec.find(p1) != aVec.end() );
CPPUNIT_ASSERT( aVec.find(p1) - aVec.begin() == 0 );
CPPUNIT_ASSERT( aVec.find(p3) != aVec.end() );
@@ -64,6 +70,38 @@ public:
aVec.DeleteAndDestroyAll();
}
+ void testInsertRange()
+ {
+ o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec1;
+ SwContent *p1 = new SwContent(1);
+ SwContent *p2 = new SwContent(2);
+ SwContent *p3 = new SwContent(3);
+
+ aVec1.insert(p1);
+ aVec1.insert(p2);
+ aVec1.insert(p3);
+
+ o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec2;
+ aVec2.insert( aVec1 );
+
+ CPPUNIT_ASSERT( aVec2.size() == 3 );
+ }
+
+ void testLowerBound()
+ {
+ o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent> > aVec;
+ SwContent *p1 = new SwContent(1);
+ SwContent *p2 = new SwContent(2);
+ SwContent *p3 = new SwContent(3);
+ SwContent *p4 = new SwContent(4);
+
+ aVec.insert(p1);
+ aVec.insert(p2);
+ aVec.insert(p3);
+
+ CPPUNIT_ASSERT( aVec.lower_bound(p1) == aVec.begin() );
+ CPPUNIT_ASSERT( aVec.lower_bound(p4) == aVec.end() );
+ }
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
@@ -71,6 +109,8 @@ public:
CPPUNIT_TEST_SUITE(sorted_vector_test);
CPPUNIT_TEST(testBasics);
+ CPPUNIT_TEST(testInsertRange);
+ CPPUNIT_TEST(testLowerBound);
CPPUNIT_TEST_SUITE_END();
};