From 1e3f1471776152f6e2f9baee5da26b123c0b88ef Mon Sep 17 00:00:00 2001 From: Jan Gaspar Date: Thu, 22 Dec 2005 23:16:58 +0000 Subject: [PATCH] iterator validity insert test [SVN r2788] --- include/boost/circular_buffer/base.hpp | 3 + test/Jamfile | 2 +- test/base_test.cpp | 2 +- ...ison.cpp => bounded_buffer_comparison.cpp} | 0 test/{common.inl => common.ipp} | 0 test/iterator_test.cpp | 62 ++++++++++++------- test/space_optimized_test.cpp | 2 +- 7 files changed, 46 insertions(+), 25 deletions(-) rename test/{cb_comparison.cpp => bounded_buffer_comparison.cpp} (100%) rename test/{common.inl => common.ipp} (100%) diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index a3348cd..74a412b 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -102,6 +102,9 @@ public: //! A range of a const array. TODO - better doc typedef std::pair const_array_range; + + //! Capacity type (defined just for consistency with circular_buffer_space_optimized). + typedef size_type capacity_control; // Helper types diff --git a/test/Jamfile b/test/Jamfile index c3d7670..e8f0ae1 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -14,6 +14,6 @@ DEPENDS all : circular_buffer ; : [ run base_test.cpp ] [ run space_optimized_test.cpp ] [ run iterator_test.cpp ] - [ compile bounded_buffer.cpp ] + [ compile bounded_buffer_comparison.cpp ] ; } diff --git a/test/base_test.cpp b/test/base_test.cpp index 07ca531..3a79546 100644 --- a/test/base_test.cpp +++ b/test/base_test.cpp @@ -10,7 +10,7 @@ #define CB_CONTAINER circular_buffer -#include "common.inl" +#include "common.ipp" void iterator_constructor_and_assign_test() { diff --git a/test/cb_comparison.cpp b/test/bounded_buffer_comparison.cpp similarity index 100% rename from test/cb_comparison.cpp rename to test/bounded_buffer_comparison.cpp diff --git a/test/common.inl b/test/common.ipp similarity index 100% rename from test/common.inl rename to test/common.ipp diff --git a/test/iterator_test.cpp b/test/iterator_test.cpp index 13b4ab2..43aaf85 100644 --- a/test/iterator_test.cpp +++ b/test/iterator_test.cpp @@ -12,6 +12,8 @@ #include "test.hpp" +int array[] = { 1, 2, 3, 4, 5 }; + // test of the example (introduced in the documentation) void validity_example_test() { @@ -32,15 +34,32 @@ void validity_example_test() { void validity_insert_test() { - circular_buffer cb1(4); - cb1.push_back(1); - cb1.push_back(2); - cb1.push_back(3); - cb1.push_back(4); - circular_buffer::iterator it1 = cb1.begin(); + circular_buffer cb(4, array, array + 3); + circular_buffer::iterator it1 = cb.begin(); + circular_buffer::iterator it2 = cb.begin() + 1; + circular_buffer::iterator it3 = cb.begin() + 2; + + // cb = {1, 2, 3} BOOST_CHECK(*it1 == 1); - cb1.insert(cb1.begin() + 1, 5); - BOOST_CHECK(*it1 == 4); + BOOST_CHECK(*it2 == 2); + BOOST_CHECK(*it3 == 3); + + cb.insert(cb.begin() + 1, 4); + + // cb = {1, 4, 2, 3} + BOOST_CHECK(*it1 == 1); + BOOST_CHECK(*it2 == 4); + BOOST_CHECK(*it3 == 2); + + cb.insert(cb.begin() + 1, 5); + + // cb = {3, 5, 4, 2} + BOOST_CHECK(*it1 == 3); + BOOST_CHECK(*it2 == 5); + BOOST_CHECK(*it3 == 4); +} + +void validity_insert_n_test() { circular_buffer cb2(4); cb2.push_back(1); @@ -53,20 +72,18 @@ void validity_insert_test() { BOOST_CHECK(*it2 == 4); } -void validity_test() { - // erase - // rerase - // insert - // rinsert - // push_back - // push_front - // linearize - // swap - // set_capacity - // rset_capacity - // resize - // rresize -} +// erase +// rerase +// insert +// rinsert +// push_back +// push_front +// linearize +// swap +// set_capacity +// rset_capacity +// resize +// rresize // test main test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { @@ -75,6 +92,7 @@ test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { tests->add(BOOST_TEST_CASE(&validity_example_test)); tests->add(BOOST_TEST_CASE(&validity_insert_test)); + tests->add(BOOST_TEST_CASE(&validity_insert_n_test)); return tests; } diff --git a/test/space_optimized_test.cpp b/test/space_optimized_test.cpp index 080ab12..d7a2335 100644 --- a/test/space_optimized_test.cpp +++ b/test/space_optimized_test.cpp @@ -12,7 +12,7 @@ #define CB_CONTAINER circular_buffer_space_optimized -#include "common.inl" +#include "common.ipp" typedef circular_buffer_space_optimized cb_space_optimized; typedef cb_space_optimized::capacity_control capacity_ctrl;