|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56983 - sandbox/SOC/2006/tree/trunk/libs/tree/test
From: ockham_at_[hidden]
Date: 2009-10-18 13:56:38
Author: bernhard.reiter
Date: 2009-10-18 13:56:37 EDT (Sun, 18 Oct 2009)
New Revision: 56983
URL: http://svn.boost.org/trac/boost/changeset/56983
Log:
Parametrize lower_bound and upper_bound tests
Text files modified:
sandbox/SOC/2006/tree/trunk/libs/tree/test/lower_bound_test.cpp | 95 +++++++++++++++++++++++----------------
sandbox/SOC/2006/tree/trunk/libs/tree/test/upper_bound_test.cpp | 86 +++++++++++++++++++++++-------------
2 files changed, 110 insertions(+), 71 deletions(-)
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/lower_bound_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/lower_bound_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/lower_bound_test.cpp 2009-10-18 13:56:37 EDT (Sun, 18 Oct 2009)
@@ -6,57 +6,72 @@
#include <boost/tree/algorithm.hpp>
-#define BOOST_TEST_MODULE cursor_algorithm test
+//#define BOOST_TEST_MODULE cursor_algorithm test
+
//#define BOOST_TEST_DYN_LINK
#include <boost/test/included/unit_test.hpp>
+#include <boost/test/parameterized_test.hpp>
+
+using namespace boost::unit_test;
#include "fake_binary_tree.hpp"
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(binary_tree_search_test, fake_binary_tree_fixture<int>)
+template <class T>
+struct val_less
+: public std::binary_function <T, int, bool>
+{
+ bool operator() (const T& x, const int y) const
+ {
+ return x.val < y;
+ }
+};
+
+void lower_bound_test(int i)
+{
+ fake_binary_tree_fixture<int> f;
+ fake_binary_tree<int>::cursor c(f.fbt1, 0), d(f.fbt1, 0);
+
+ test_data_set mpo;
+ mock_cursor_data(mpo);
+
+ c = lower_bound(f.fbt1.root(), i);
+ test_data_set::index<inorder>::type::const_iterator ci
+ = std::lower_bound(mpo.get<inorder>().begin(), mpo.get<inorder>().end(), i
+ , val_less<test_data_set::value_type>());
+ BOOST_CHECK_EQUAL(*c, ci->val);
+}
-BOOST_AUTO_TEST_CASE( lower_bound_test )
+void lower_bound_pred_test(int i)
{
- fake_binary_tree<int>::cursor c(fbt1, 0), d(fbt1, 0);
+ fake_binary_tree_fixture<int> f;
+ fake_binary_tree<int>::cursor c(f.fbt1, 0), d(f.fbt1, 0);
- c = lower_bound(fbt1.root(), 4); // (Left) Leaf
+ test_data_set mpo;
+ mock_cursor_data(mpo);
-// TODO: Test by applying std::lower_bound to the inorder sorted data and comparing
-// with the result of that operation.
-// test_data_set mpo;
-// mock_cursor_data(mpo);
-// test_data_set::index<inorder>::type::const_iterator ci
-// = std::lower_bound(mpo.get<inorder>().begin(), mpo.get<inorder>().end(), 4); // Need a predicate
-// BOOST_CHECK_EQUAL(*c, ci->val);
-
- BOOST_CHECK_EQUAL(*c, 4);
- c = lower_bound(fbt1.root(), 7); // (Right) Leaf
- BOOST_CHECK_EQUAL(*c, 7);
- c = lower_bound(fbt1.root(), 6); // Non-Leaf
- BOOST_CHECK_EQUAL(*c, 6);
- c = lower_bound(fbt1.root(), 8); // Non-Leaf: root
- BOOST_CHECK_EQUAL(*c, 8);
-
- c = lower_bound(fbt1.root(), 5); // Not in tree
- BOOST_CHECK_EQUAL(*c, 6);
+ c = lower_bound(f.fbt1.root(), i, std::less<int>());
+ test_data_set::index<inorder>::type::const_iterator ci
+ = std::lower_bound(mpo.get<inorder>().begin(), mpo.get<inorder>().end(), i
+ , val_less<test_data_set::value_type>());
+ BOOST_CHECK_EQUAL(*c, ci->val);
}
-BOOST_AUTO_TEST_CASE( lower_bound_pred_test )
-{
- fake_binary_tree<int>::cursor c(fbt1, 0), d(fbt1, 0);
-
- c = lower_bound(fbt1.root(), 4, std::less<int>()); // (Left) Leaf
- BOOST_CHECK_EQUAL(*c, 4);
- c = lower_bound(fbt1.root(), 7, std::less<int>()); // (Right) Leaf
- BOOST_CHECK_EQUAL(*c, 7);
- c = lower_bound(fbt1.root(), 6, std::less<int>()); // Non-Leaf
- BOOST_CHECK_EQUAL(*c, 6);
- c = lower_bound(fbt1.root(), 8, std::less<int>()); // Non-Leaf: root
- BOOST_CHECK_EQUAL(*c, 8);
-
- c = lower_bound(fbt1.root(), 5, std::less<int>()); // Not in tree
- BOOST_CHECK_EQUAL(*c, 6);
-}
+test_suite*
+init_unit_test_suite( int argc, char* argv[] )
+{
+ int params[] = { 4, 7, 6, 8, 5 };
+// 4: Left Leaf
+// 7: Right Leaf
+// 6: Non-Leaf
+// 8: Non-Leaf, Root
+// 5: Not in Tree
+
+ framework::master_test_suite().
+ add( BOOST_PARAM_TEST_CASE( &lower_bound_test, params, params+5 ) );
+ framework::master_test_suite().
+ add( BOOST_PARAM_TEST_CASE( &lower_bound_pred_test, params, params+5 ) );
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+ return 0;
+}
\ No newline at end of file
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/upper_bound_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/upper_bound_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/upper_bound_test.cpp 2009-10-18 13:56:37 EDT (Sun, 18 Oct 2009)
@@ -6,48 +6,72 @@
#include <boost/tree/algorithm.hpp>
-#define BOOST_TEST_MODULE cursor_algorithm test
+//#define BOOST_TEST_MODULE cursor_algorithm test
+
//#define BOOST_TEST_DYN_LINK
#include <boost/test/included/unit_test.hpp>
+#include <boost/test/parameterized_test.hpp>
+
+using namespace boost::unit_test;
#include "fake_binary_tree.hpp"
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(binary_tree_search_test, fake_binary_tree_fixture<int>)
+template <class T>
+struct less_val
+: public std::binary_function <int, T, bool>
+{
+ bool operator() (const int x, const T& y) const
+ {
+ return x < y.val;
+ }
+};
+
+void upper_bound_test(int i)
+{
+ fake_binary_tree_fixture<int> f;
+ fake_binary_tree<int>::cursor c(f.fbt1, 0), d(f.fbt1, 0);
+
+ test_data_set mpo;
+ mock_cursor_data(mpo);
+
+ c = upper_bound(f.fbt1.root(), i);
+ test_data_set::index<inorder>::type::const_iterator ci
+ = std::upper_bound(mpo.get<inorder>().begin(), mpo.get<inorder>().end(), i
+ , less_val<test_data_set::value_type>());
+ BOOST_CHECK_EQUAL(*c, ci->val);
+}
-BOOST_AUTO_TEST_CASE( upper_bound_test )
+void upper_bound_pred_test(int i)
{
- fake_binary_tree<int>::cursor c(fbt1, 0), d(fbt1, 0);
+ fake_binary_tree_fixture<int> f;
+ fake_binary_tree<int>::cursor c(f.fbt1, 0), d(f.fbt1, 0);
- c = upper_bound(fbt1.root(), 4); // (Left) Leaf
- BOOST_CHECK_EQUAL(*c, 6);
- c = upper_bound(fbt1.root(), 7); // (Right) Leaf
- BOOST_CHECK_EQUAL(*c, 8);
- c = upper_bound(fbt1.root(), 6); // Non-Leaf
- BOOST_CHECK_EQUAL(*c, 7);
- c = upper_bound(fbt1.root(), 8); // Non-Leaf: root
- BOOST_CHECK_EQUAL(*c, 10);
+ test_data_set mpo;
+ mock_cursor_data(mpo);
- c = upper_bound(fbt1.root(), 5); // Not in tree
- BOOST_CHECK_EQUAL(*c, 6);
+ c = upper_bound(f.fbt1.root(), i, std::less<int>());
+ test_data_set::index<inorder>::type::const_iterator ci
+ = std::upper_bound(mpo.get<inorder>().begin(), mpo.get<inorder>().end(), i
+ , less_val<test_data_set::value_type>());
+ BOOST_CHECK_EQUAL(*c, ci->val);
}
-BOOST_AUTO_TEST_CASE( upper_bound_pred_test )
-{
- fake_binary_tree<int>::cursor c(fbt1, 0), d(fbt1, 0);
-
- c = upper_bound(fbt1.root(), 4, std::less<int>()); // (Left) Leaf
- BOOST_CHECK_EQUAL(*c, 6);
- c = upper_bound(fbt1.root(), 7, std::less<int>()); // (Right) Leaf
- BOOST_CHECK_EQUAL(*c, 8);
- c = upper_bound(fbt1.root(), 6, std::less<int>()); // Non-Leaf
- BOOST_CHECK_EQUAL(*c, 7);
- c = upper_bound(fbt1.root(), 8, std::less<int>()); // Non-Leaf: root
- BOOST_CHECK_EQUAL(*c, 10);
-
- c = upper_bound(fbt1.root(), 5, std::less<int>()); // Not in tree
- BOOST_CHECK_EQUAL(*c, 6);
-}
+test_suite*
+init_unit_test_suite( int argc, char* argv[] )
+{
+ int params[] = { 4, 7, 6, 8, 5 };
+// 4: Left Leaf
+// 7: Right Leaf
+// 6: Non-Leaf
+// 8: Non-Leaf, Root
+// 5: Not in Tree
+
+ framework::master_test_suite().
+ add( BOOST_PARAM_TEST_CASE( &upper_bound_test, params, params+5 ) );
+ framework::master_test_suite().
+ add( BOOST_PARAM_TEST_CASE( &upper_bound_pred_test, params, params+5 ) );
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+ return 0;
+}
\ No newline at end of file
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk