|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50717 - in sandbox/SOC/2006/tree/trunk: . boost/tree libs/tree/test
From: ockham_at_[hidden]
Date: 2009-01-21 17:57:36
Author: bernhard.reiter
Date: 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
New Revision: 50717
URL: http://svn.boost.org/trac/boost/changeset/50717
Log:
More mock objects.
Text files modified:
sandbox/SOC/2006/tree/trunk/TODO | 4
sandbox/SOC/2006/tree/trunk/boost/tree/cursor.hpp | 39 ----
sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp | 51 +++--
sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp | 16
sandbox/SOC/2006/tree/trunk/libs/tree/test/for_each_test.cpp | 64 ++++---
sandbox/SOC/2006/tree/trunk/libs/tree/test/iterator_algorithm_test.cpp | 132 ++++++++-------
sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp | 2
sandbox/SOC/2006/tree/trunk/libs/tree/test/test_tree_traversal_data.hpp | 326 ++++++++++++++++++++--------------------
sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp | 53 ++---
9 files changed, 332 insertions(+), 355 deletions(-)
Modified: sandbox/SOC/2006/tree/trunk/TODO
==============================================================================
--- sandbox/SOC/2006/tree/trunk/TODO (original)
+++ sandbox/SOC/2006/tree/trunk/TODO 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -14,6 +14,10 @@
[section TODO]
General:
+* Use Boost.MultiIndex for organising mock objects to avoid redundancy?
+ (The data pairs position--value
+ are always the same, but the order in which they are accessed depends on the order of the
+ algorithm acting on them).
* Get rid of lists used for order checking. Use mock cursor instead.
* Clean up binary_tree_test
* binary_tree_search_test -> lower_bound_test
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/cursor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/cursor.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/cursor.hpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -63,11 +63,6 @@
};
template <class Cursor>
-struct cursor_category {
- typedef typename Cursor::cursor_category type;
-};
-
-template <class Cursor>
struct cursor_horizontal_traversal {
typedef typename Cursor::horizontal_traversal type;
};
@@ -88,40 +83,6 @@
typedef Ref reference;
};
-// Deprecate?
-//struct cursor_tag {};
-//
-//struct descending_tag {};
-//struct descending_cursor_tag
-// : public cursor_tag, public descending_tag,
-// public input_iterator_tag, public output_iterator_tag {};
-//struct descending_forward_cursor_tag
-// : public cursor_tag, public descending_tag, public forward_iterator_tag {};
-//struct descending_bidirectional_cursor_tag
-// : public cursor_tag, public descending_tag, public bidirectional_iterator_tag {};
-//struct descending_random_access_cursor_tag
-// : public cursor_tag, public descending_tag, public random_access_iterator_tag {};
-//
-//struct ascending_tag {};
-//struct ascending_cursor_tag
-// : public descending_cursor_tag, public ascending_tag {};
-//struct ascending_forward_cursor_tag
-// : public descending_forward_cursor_tag, public ascending_tag {};
-//struct ascending_bidirectional_cursor_tag
-// : public descending_bidirectional_cursor_tag, public ascending_tag {};
-//struct ascending_random_access_cursor_tag
-// : public descending_random_access_cursor_tag, public ascending_tag {};
-
-/*
-template <class Hor, class Vert>
-struct produce_cursor_category;
-
-template <>
-struct produce_cursor_category<> {
- typedef descending_cursor_tag type;
-};
-*/
-
//define freestanding begin, end, size, empty using cursor's member fns?
} // namespace tree
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -20,51 +20,54 @@
#include <iterator>
#include "helpers.hpp"
+#include "fake_binary_tree.hpp"
#include "test_tree_traversal_data.hpp"
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(binary_tree_search_test, test_binary_tree_with_list_fixture<int>)
+BOOST_FIXTURE_TEST_SUITE(binary_tree_search_test, test_binary_tree_fixture<int>)
-template <class Cursor>
-void search_single_element(Cursor r, int v)
-{
- Cursor c, d;
- c = lower_bound(r, v);
- d = upper_bound(r, v);
-
- BOOST_CHECK_EQUAL(*c, v);
- //BOOST_CHECK_EQUAL(next(inorder(), c) , d);
-}
+//template <class Cursor>
+//void search_single_element(Cursor r, int v)
+//{
+// Cursor c, d;
+// c = lower_bound(r, v);
+// d = upper_bound(r, v);
+//
+// BOOST_CHECK_EQUAL(*c, v);
+// //BOOST_CHECK_EQUAL(next(inorder(), c) , d);
+//}
+
+// Use mock cursor for tests, especially position!
-BOOST_AUTO_TEST_CASE( binary_tree_search_test )
-{
+BOOST_AUTO_TEST_CASE( lower_bound_test )
+{
binary_tree<int>::cursor c, d;
- search_single_element(bt.root(), 4); // (Left) Leaf
- search_single_element(bt.root(), 7); // (Right) Leaf
- search_single_element(bt.root(), 6); // Non-Leaf
- search_single_element(bt.root(), 8); // root().begin()
+ c = lower_bound(bt.root(), 4); // (Left) Leaf
+ c = lower_bound(bt.root(), 7); // (Right) Leaf
+ c = lower_bound(bt.root(), 6); // Non-Leaf
+ c = lower_bound(bt.root(), 8); // root().begin()
c = lower_bound(bt.root(), 5); // Not in tree
d = lower_bound(bt.root(), 5);
BOOST_CHECK_EQUAL(*c, 6);
BOOST_CHECK_EQUAL(*d, 6);
- *c = 4;
+ //*c = 4;
c = lower_bound(bt.root(), 5); // Not in tree
- BOOST_CHECK_EQUAL(*c, 7);
+ BOOST_CHECK_EQUAL(*c, 6);
c = lower_bound(bt.root(), 4); // Twice in tree
- d = upper_bound(bt.root(), 4);
+ //d = upper_bound(bt.root(), 4);
BOOST_CHECK_EQUAL(*c, 4);
- BOOST_CHECK_EQUAL(*d, 7);
- BOOST_CHECK_EQUAL(*c.parent(), 4);
+ BOOST_CHECK_EQUAL(*d, 6);
+ //BOOST_CHECK_EQUAL(*c.parent(), 4);
//BOOST_CHECK(next(inorder(), c, 2) == d);
- *c.to_parent() = 6;
- validate_test_dataset1_tree(bt.root());
+ //*c.to_parent() = 6;
+ //validate_test_dataset1_tree(bt.root());
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -319,13 +319,13 @@
fake_binary_tree<T> fbt1, fbt2;
};
-template <class T = int>
-struct fake_binary_tree_with_list_fixture
-: public fake_binary_tree_fixture<T>
-, public test_with_list_fixture {
- fake_binary_tree_with_list_fixture()
- : fake_binary_tree_fixture<T>()
- , test_with_list_fixture() {}
-};
+//template <class T = int>
+//struct fake_binary_tree_with_list_fixture
+//: public fake_binary_tree_fixture<T>
+//, public test_with_list_fixture {
+// fake_binary_tree_with_list_fixture()
+// : fake_binary_tree_fixture<T>()
+// , test_with_list_fixture() {}
+//};
#endif // LIBS_TREE_TEST_FAKE_BINARY_TREE_HPP
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/for_each_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/for_each_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/for_each_test.cpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -19,48 +19,58 @@
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_with_list_fixture<int>)
+BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_fixture<int>)
+
+template <class Iter>
+class mock_unary_functor {
+private:
+ Iter& m_iter, m_end;
+
+public:
+ mock_unary_functor(Iter& iter, Iter& end)
+ : m_iter(iter), m_end(end) {}
+
+ mock_unary_functor(mock_unary_functor<Iter> const& other)
+ : m_iter(other.m_iter), m_end(other.m_end) {}
+
+ void operator()(typename Iter::value_type::second_type const& val)
+ {
+ BOOST_CHECK(m_iter != m_end);
+ if (m_iter == m_end)
+ return;
+ BOOST_CHECK_EQUAL(val, m_iter->second);
+ ++m_iter;
+ }
+};
BOOST_AUTO_TEST_CASE_TEMPLATE( test_for_each_descending, Order, orders)
{
+ typedef std::vector< std::pair<std::size_t, int> > container_type;
+ container_type po(11);
+ generate_mock_cursor_data(Order(), po);
+ container_type::const_iterator ci = po.begin();
+ container_type::const_iterator cie = po.end();
+ mock_unary_functor<container_type::const_iterator> muc(ci, cie);
boost::tree::for_each(
Order(),
fbt1.descending_root(),
- boost::lambda::bind(&std::list<int>::push_back, &l, boost::lambda::_1)
+ muc
);
- test_traversal(Order(), l.begin(), l.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE( test_for_each_ascending, Order, orders)
{
+ typedef std::vector< std::pair<std::size_t, int> > container_type;
+ container_type po(11);
+ generate_mock_cursor_data(Order(), po);
+ container_type::const_iterator ci = po.begin();
+ container_type::const_iterator cie = po.end();
+ mock_unary_functor<container_type::const_iterator> muc(ci, cie);
boost::tree::for_each(
Order(),
fbt1.ascending_root(),
- boost::lambda::bind(&std::list<int>::push_back, &l, boost::lambda::_1)
- );
- test_traversal(Order(), l.begin(), l.end());
-}
-
-BOOST_AUTO_TEST_CASE( test_for_each_subtree3_descending )
-{
- boost::tree::for_each(
- preorder(),
- fbt1.descending_root().begin(),
- boost::lambda::bind(&std::list<int>::push_back, &l, boost::lambda::_1)
- );
- test_subtree_traversal(preorder(), l.begin(), l.end(), 1);
- BOOST_CHECK_EQUAL(l.size(), 5);
-}
-
-BOOST_AUTO_TEST_CASE( test_for_each_subtree3_ascending )
-{
- boost::tree::for_each(
- preorder(),
- fbt1.ascending_root().begin(),
- boost::lambda::bind(&std::list<int>::push_back, &l, boost::lambda::_1)
+ muc
);
- test_subtree_traversal(preorder(), l.begin(), l.end(), 1);
- BOOST_CHECK_EQUAL(l.size(), 5);
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/iterator_algorithm_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/iterator_algorithm_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/iterator_algorithm_test.cpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -24,74 +24,80 @@
using namespace boost::tree;
// We should actually just check if operators++ and -- call next and prior
-// Pretty simple -- any actual need for a test file?
+// and also begin() and end() (call to_first(), to_last())
+// Use a mock cursor object?
-BOOST_FIXTURE_TEST_SUITE( iterator_algorithms_test, fake_binary_tree_with_list_fixture<int> )
+BOOST_FIXTURE_TEST_SUITE( iterator_algorithms_test, fake_binary_tree_fixture<int> )
-BOOST_AUTO_TEST_CASE_TEMPLATE( test_iterator_algorithms, Order, orders )
+BOOST_AUTO_TEST_CASE( test_iterator )
{
- test_traversal(Order(), begin(Order(), fbt1.ascending_root())
- , end(Order(), fbt1.ascending_root()));
- test_reverse_traversal(Order(), end(Order(), fbt1.ascending_root())
- , begin(Order(), fbt1.ascending_root()));
-
- BOOST_CHECK_EQUAL(std::distance(begin(Order(), fbt1.ascending_root())
- , end(Order(), fbt1.ascending_root())), 11);
}
-BOOST_AUTO_TEST_CASE( test_subtree3_iterator_algorithms )
-{
- test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().begin())
- , end(preorder(), fbt1.ascending_root().begin()), 1);
- BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().begin())
- , end(preorder(), fbt1.ascending_root().begin())), 5);
-
- test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().begin())
- , end(inorder(), fbt1.ascending_root().begin()), 0);
- BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().begin())
- , end(inorder(), fbt1.ascending_root().begin())), 5);
-
- test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().begin())
- , end(postorder(), fbt1.ascending_root().begin()), 0);
- BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().begin())
- , end(postorder(), fbt1.ascending_root().begin())), 5);
-}
-
-BOOST_AUTO_TEST_CASE( test_subtree6_iterator_algorithms )
-{
- test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().begin().end())
- , end(preorder(), fbt1.ascending_root().begin().end()), 3);
- BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().begin().end())
- , end(preorder(), fbt1.ascending_root().begin().end())), 3);
-
- test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().begin().end())
- , end(inorder(), fbt1.ascending_root().begin().end()), 2);
- BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().begin().end())
- , end(inorder(), fbt1.ascending_root().begin().end())), 3);
-
- test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().begin().end())
- , end(postorder(), fbt1.ascending_root().begin().end()), 1);
- BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().begin().end())
- , end(postorder(), fbt1.ascending_root().begin().end())), 3);
-}
-
-BOOST_AUTO_TEST_CASE( test_subtree10_iterator_algorithms )
-{
- test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().end())
- , end(preorder(), fbt1.ascending_root().end()), 6);
- BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().end())
- , end(preorder(), fbt1.ascending_root().end())), 5);
-
- test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().end())
- , end(inorder(), fbt1.ascending_root().end()), 6);
- BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().end())
- , end(inorder(), fbt1.ascending_root().end())), 5);
-
- test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().end())
- , end(postorder(), fbt1.ascending_root().end()), 5);
- BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().end())
- , end(postorder(), fbt1.ascending_root().end())), 5);
-}
+//BOOST_AUTO_TEST_CASE_TEMPLATE( test_iterator_algorithms, Order, orders )
+//{
+// test_traversal(Order(), begin(Order(), fbt1.ascending_root())
+// , end(Order(), fbt1.ascending_root()));
+//
+// test_reverse_traversal(Order(), end(Order(), fbt1.ascending_root())
+// , begin(Order(), fbt1.ascending_root()));
+//
+// BOOST_CHECK_EQUAL(std::distance(begin(Order(), fbt1.ascending_root())
+// , end(Order(), fbt1.ascending_root())), 11);
+//}
+//
+//BOOST_AUTO_TEST_CASE( test_subtree3_iterator_algorithms )
+//{
+// test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().begin())
+// , end(preorder(), fbt1.ascending_root().begin()), 1);
+// BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().begin())
+// , end(preorder(), fbt1.ascending_root().begin())), 5);
+//
+// test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().begin())
+// , end(inorder(), fbt1.ascending_root().begin()), 0);
+// BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().begin())
+// , end(inorder(), fbt1.ascending_root().begin())), 5);
+//
+// test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().begin())
+// , end(postorder(), fbt1.ascending_root().begin()), 0);
+// BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().begin())
+// , end(postorder(), fbt1.ascending_root().begin())), 5);
+//}
+//
+//BOOST_AUTO_TEST_CASE( test_subtree6_iterator_algorithms )
+//{
+// test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().begin().end())
+// , end(preorder(), fbt1.ascending_root().begin().end()), 3);
+// BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().begin().end())
+// , end(preorder(), fbt1.ascending_root().begin().end())), 3);
+//
+// test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().begin().end())
+// , end(inorder(), fbt1.ascending_root().begin().end()), 2);
+// BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().begin().end())
+// , end(inorder(), fbt1.ascending_root().begin().end())), 3);
+//
+// test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().begin().end())
+// , end(postorder(), fbt1.ascending_root().begin().end()), 1);
+// BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().begin().end())
+// , end(postorder(), fbt1.ascending_root().begin().end())), 3);
+//}
+//
+//BOOST_AUTO_TEST_CASE( test_subtree10_iterator_algorithms )
+//{
+// test_subtree_traversal(preorder(), begin(preorder(), fbt1.ascending_root().end())
+// , end(preorder(), fbt1.ascending_root().end()), 6);
+// BOOST_CHECK_EQUAL(std::distance(begin(preorder(), fbt1.ascending_root().end())
+// , end(preorder(), fbt1.ascending_root().end())), 5);
+//
+// test_subtree_traversal(inorder(), begin(inorder(), fbt1.ascending_root().end())
+// , end(inorder(), fbt1.ascending_root().end()), 6);
+// BOOST_CHECK_EQUAL(std::distance(begin(inorder(), fbt1.ascending_root().end())
+// , end(inorder(), fbt1.ascending_root().end())), 5);
+//
+// test_subtree_traversal(postorder(), begin(postorder(), fbt1.ascending_root().end())
+// , end(postorder(), fbt1.ascending_root().end()), 5);
+// BOOST_CHECK_EQUAL(std::distance(begin(postorder(), fbt1.ascending_root().end())
+// , end(postorder(), fbt1.ascending_root().end())), 5);
+//}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -17,7 +17,7 @@
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_with_list_fixture<int>)
+BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_fixture<int>)
BOOST_AUTO_TEST_CASE( test_predecessor_preorder )
{
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/test_tree_traversal_data.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/test_tree_traversal_data.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/test_tree_traversal_data.hpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -192,178 +192,178 @@
data[10] = make_pair(0, 8);
}
-template <class Iterator>
-void test_traversal(boost::tree::preorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*a++, 8);
- BOOST_CHECK_EQUAL(*a++, 3);
- BOOST_CHECK_EQUAL(*a++, 1);
- BOOST_CHECK_EQUAL(*a++, 6);
- BOOST_CHECK_EQUAL(*a++, 4);
- BOOST_CHECK_EQUAL(*a++, 7);
- BOOST_CHECK_EQUAL(*a++, 10);
- BOOST_CHECK_EQUAL(*a++, 14);
- BOOST_CHECK_EQUAL(*a++, 13);
- BOOST_CHECK_EQUAL(*a++, 11);
- BOOST_CHECK_EQUAL(*a++, 12);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_reverse_traversal(boost::tree::preorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*--a, 12);
- BOOST_CHECK_EQUAL(*--a, 11);
- BOOST_CHECK_EQUAL(*--a, 13);
- BOOST_CHECK_EQUAL(*--a, 14);
- BOOST_CHECK_EQUAL(*--a, 10);
- BOOST_CHECK_EQUAL(*--a, 7);
- BOOST_CHECK_EQUAL(*--a, 4);
- BOOST_CHECK_EQUAL(*--a, 6);
- BOOST_CHECK_EQUAL(*--a, 1);
- BOOST_CHECK_EQUAL(*--a, 3);
- BOOST_CHECK_EQUAL(*--a, 8);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_subtree_traversal(boost::tree::preorder, Iterator a, Iterator b
- , std::vector<int>::difference_type x = 0)
-{
- std::vector<int> preorder(11);
- preorder[0] = 8;
- preorder[1] = 3;
- preorder[2] = 1;
- preorder[3] = 6;
- preorder[4] = 4;
- preorder[5] = 7;
- preorder[6] = 10;
- preorder[7] = 14;
- preorder[8] = 13;
- preorder[9] = 11;
- preorder[10] = 12;
-
- BOOST_CHECK(std::equal(a, b, preorder.begin() + x));
-}
-
//template <class Iterator>
-//void test_subtree_traversal(boost::tree::preorder, Iterator a, Iterator b)
+//void test_traversal(boost::tree::preorder, Iterator a, Iterator b)
//{
+// BOOST_CHECK_EQUAL(*a++, 8);
// BOOST_CHECK_EQUAL(*a++, 3);
// BOOST_CHECK_EQUAL(*a++, 1);
// BOOST_CHECK_EQUAL(*a++, 6);
// BOOST_CHECK_EQUAL(*a++, 4);
// BOOST_CHECK_EQUAL(*a++, 7);
+// BOOST_CHECK_EQUAL(*a++, 10);
+// BOOST_CHECK_EQUAL(*a++, 14);
+// BOOST_CHECK_EQUAL(*a++, 13);
+// BOOST_CHECK_EQUAL(*a++, 11);
+// BOOST_CHECK_EQUAL(*a++, 12);
// BOOST_CHECK(a == b);
//}
-
-template <class Iterator>
-void test_traversal(boost::tree::inorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*a++, 1);
- BOOST_CHECK_EQUAL(*a++, 3);
- BOOST_CHECK_EQUAL(*a++, 4);
- BOOST_CHECK_EQUAL(*a++, 6);
- BOOST_CHECK_EQUAL(*a++, 7);
- BOOST_CHECK_EQUAL(*a++, 8);
- BOOST_CHECK_EQUAL(*a++, 10);
- BOOST_CHECK_EQUAL(*a++, 11);
- BOOST_CHECK_EQUAL(*a++, 12);
- BOOST_CHECK_EQUAL(*a++, 13);
- BOOST_CHECK_EQUAL(*a++, 14);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_reverse_traversal(boost::tree::inorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*--a, 14);
- BOOST_CHECK_EQUAL(*--a, 13);
- BOOST_CHECK_EQUAL(*--a, 12);
- BOOST_CHECK_EQUAL(*--a, 11);
- BOOST_CHECK_EQUAL(*--a, 10);
- BOOST_CHECK_EQUAL(*--a, 8);
- BOOST_CHECK_EQUAL(*--a, 7);
- BOOST_CHECK_EQUAL(*--a, 6);
- BOOST_CHECK_EQUAL(*--a, 4);
- BOOST_CHECK_EQUAL(*--a, 3);
- BOOST_CHECK_EQUAL(*--a, 1);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_subtree_traversal(boost::tree::inorder, Iterator a, Iterator b
- , std::vector<int>::difference_type x = 0)
-{
- std::vector<int> inorder(11);
- inorder[0] = 1;
- inorder[1] = 3;
- inorder[2] = 4;
- inorder[3] = 6;
- inorder[4] = 7;
- inorder[5] = 8;
- inorder[6] = 10;
- inorder[7] = 11;
- inorder[8] = 12;
- inorder[9] = 13;
- inorder[10] = 14;
-
- BOOST_CHECK(std::equal(a, b, inorder.begin() + x));
-}
-
-template <class Iterator>
-void test_traversal(boost::tree::postorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*a++, 1);
- BOOST_CHECK_EQUAL(*a++, 4);
- BOOST_CHECK_EQUAL(*a++, 7);
- BOOST_CHECK_EQUAL(*a++, 6);
- BOOST_CHECK_EQUAL(*a++, 3);
- BOOST_CHECK_EQUAL(*a++, 12);
- BOOST_CHECK_EQUAL(*a++, 11);
- BOOST_CHECK_EQUAL(*a++, 13);
- BOOST_CHECK_EQUAL(*a++, 14);
- BOOST_CHECK_EQUAL(*a++, 10);
- BOOST_CHECK_EQUAL(*a++, 8);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_reverse_traversal(boost::tree::postorder, Iterator a, Iterator b)
-{
- BOOST_CHECK_EQUAL(*--a, 8);
- BOOST_CHECK_EQUAL(*--a, 10);
- BOOST_CHECK_EQUAL(*--a, 14);
- BOOST_CHECK_EQUAL(*--a, 13);
- BOOST_CHECK_EQUAL(*--a, 11);
- BOOST_CHECK_EQUAL(*--a, 12);
- BOOST_CHECK_EQUAL(*--a, 3);
- BOOST_CHECK_EQUAL(*--a, 6);
- BOOST_CHECK_EQUAL(*--a, 7);
- BOOST_CHECK_EQUAL(*--a, 4);
- BOOST_CHECK_EQUAL(*--a, 1);
- BOOST_CHECK(a == b);
-}
-
-template <class Iterator>
-void test_subtree_traversal(boost::tree::postorder, Iterator a, Iterator b
- , std::vector<int>::difference_type x = 0)
-{
- std::vector<int> postorder(11);
- postorder[0] = 1;
- postorder[1] = 4;
- postorder[2] = 7;
- postorder[3] = 6;
- postorder[4] = 3;
- postorder[5] = 12;
- postorder[6] = 11;
- postorder[7] = 13;
- postorder[8] = 14;
- postorder[9] = 10;
- postorder[10] = 8;
-
- BOOST_CHECK(std::equal(a, b, postorder.begin() + x));
-}
+//
+//template <class Iterator>
+//void test_reverse_traversal(boost::tree::preorder, Iterator a, Iterator b)
+//{
+// BOOST_CHECK_EQUAL(*--a, 12);
+// BOOST_CHECK_EQUAL(*--a, 11);
+// BOOST_CHECK_EQUAL(*--a, 13);
+// BOOST_CHECK_EQUAL(*--a, 14);
+// BOOST_CHECK_EQUAL(*--a, 10);
+// BOOST_CHECK_EQUAL(*--a, 7);
+// BOOST_CHECK_EQUAL(*--a, 4);
+// BOOST_CHECK_EQUAL(*--a, 6);
+// BOOST_CHECK_EQUAL(*--a, 1);
+// BOOST_CHECK_EQUAL(*--a, 3);
+// BOOST_CHECK_EQUAL(*--a, 8);
+// BOOST_CHECK(a == b);
+//}
+//
+//template <class Iterator>
+//void test_subtree_traversal(boost::tree::preorder, Iterator a, Iterator b
+// , std::vector<int>::difference_type x = 0)
+//{
+// std::vector<int> preorder(11);
+// preorder[0] = 8;
+// preorder[1] = 3;
+// preorder[2] = 1;
+// preorder[3] = 6;
+// preorder[4] = 4;
+// preorder[5] = 7;
+// preorder[6] = 10;
+// preorder[7] = 14;
+// preorder[8] = 13;
+// preorder[9] = 11;
+// preorder[10] = 12;
+//
+// BOOST_CHECK(std::equal(a, b, preorder.begin() + x));
+//}
+//
+////template <class Iterator>
+////void test_subtree_traversal(boost::tree::preorder, Iterator a, Iterator b)
+////{
+//// BOOST_CHECK_EQUAL(*a++, 3);
+//// BOOST_CHECK_EQUAL(*a++, 1);
+//// BOOST_CHECK_EQUAL(*a++, 6);
+//// BOOST_CHECK_EQUAL(*a++, 4);
+//// BOOST_CHECK_EQUAL(*a++, 7);
+//// BOOST_CHECK(a == b);
+////}
+//
+//template <class Iterator>
+//void test_traversal(boost::tree::inorder, Iterator a, Iterator b)
+//{
+// BOOST_CHECK_EQUAL(*a++, 1);
+// BOOST_CHECK_EQUAL(*a++, 3);
+// BOOST_CHECK_EQUAL(*a++, 4);
+// BOOST_CHECK_EQUAL(*a++, 6);
+// BOOST_CHECK_EQUAL(*a++, 7);
+// BOOST_CHECK_EQUAL(*a++, 8);
+// BOOST_CHECK_EQUAL(*a++, 10);
+// BOOST_CHECK_EQUAL(*a++, 11);
+// BOOST_CHECK_EQUAL(*a++, 12);
+// BOOST_CHECK_EQUAL(*a++, 13);
+// BOOST_CHECK_EQUAL(*a++, 14);
+// BOOST_CHECK(a == b);
+//}
+//
+//template <class Iterator>
+//void test_reverse_traversal(boost::tree::inorder, Iterator a, Iterator b)
+//{
+// BOOST_CHECK_EQUAL(*--a, 14);
+// BOOST_CHECK_EQUAL(*--a, 13);
+// BOOST_CHECK_EQUAL(*--a, 12);
+// BOOST_CHECK_EQUAL(*--a, 11);
+// BOOST_CHECK_EQUAL(*--a, 10);
+// BOOST_CHECK_EQUAL(*--a, 8);
+// BOOST_CHECK_EQUAL(*--a, 7);
+// BOOST_CHECK_EQUAL(*--a, 6);
+// BOOST_CHECK_EQUAL(*--a, 4);
+// BOOST_CHECK_EQUAL(*--a, 3);
+// BOOST_CHECK_EQUAL(*--a, 1);
+// BOOST_CHECK(a == b);
+//}
+//
+//template <class Iterator>
+//void test_subtree_traversal(boost::tree::inorder, Iterator a, Iterator b
+// , std::vector<int>::difference_type x = 0)
+//{
+// std::vector<int> inorder(11);
+// inorder[0] = 1;
+// inorder[1] = 3;
+// inorder[2] = 4;
+// inorder[3] = 6;
+// inorder[4] = 7;
+// inorder[5] = 8;
+// inorder[6] = 10;
+// inorder[7] = 11;
+// inorder[8] = 12;
+// inorder[9] = 13;
+// inorder[10] = 14;
+//
+// BOOST_CHECK(std::equal(a, b, inorder.begin() + x));
+//}
+//
+//template <class Iterator>
+//void test_traversal(boost::tree::postorder, Iterator a, Iterator b)
+//{
+// BOOST_CHECK_EQUAL(*a++, 1);
+// BOOST_CHECK_EQUAL(*a++, 4);
+// BOOST_CHECK_EQUAL(*a++, 7);
+// BOOST_CHECK_EQUAL(*a++, 6);
+// BOOST_CHECK_EQUAL(*a++, 3);
+// BOOST_CHECK_EQUAL(*a++, 12);
+// BOOST_CHECK_EQUAL(*a++, 11);
+// BOOST_CHECK_EQUAL(*a++, 13);
+// BOOST_CHECK_EQUAL(*a++, 14);
+// BOOST_CHECK_EQUAL(*a++, 10);
+// BOOST_CHECK_EQUAL(*a++, 8);
+// BOOST_CHECK(a == b);
+//}
+//
+//template <class Iterator>
+//void test_reverse_traversal(boost::tree::postorder, Iterator a, Iterator b)
+//{
+// BOOST_CHECK_EQUAL(*--a, 8);
+// BOOST_CHECK_EQUAL(*--a, 10);
+// BOOST_CHECK_EQUAL(*--a, 14);
+// BOOST_CHECK_EQUAL(*--a, 13);
+// BOOST_CHECK_EQUAL(*--a, 11);
+// BOOST_CHECK_EQUAL(*--a, 12);
+// BOOST_CHECK_EQUAL(*--a, 3);
+// BOOST_CHECK_EQUAL(*--a, 6);
+// BOOST_CHECK_EQUAL(*--a, 7);
+// BOOST_CHECK_EQUAL(*--a, 4);
+// BOOST_CHECK_EQUAL(*--a, 1);
+// BOOST_CHECK(a == b);
+//}
+//
+//template <class Iterator>
+//void test_subtree_traversal(boost::tree::postorder, Iterator a, Iterator b
+// , std::vector<int>::difference_type x = 0)
+//{
+// std::vector<int> postorder(11);
+// postorder[0] = 1;
+// postorder[1] = 4;
+// postorder[2] = 7;
+// postorder[3] = 6;
+// postorder[4] = 3;
+// postorder[5] = 12;
+// postorder[6] = 11;
+// postorder[7] = 13;
+// postorder[8] = 14;
+// postorder[9] = 10;
+// postorder[10] = 8;
+//
+// BOOST_CHECK(std::equal(a, b, postorder.begin() + x));
+//}
template <class Iterator>
void test_traversal_from_leaf4(Iterator a, Iterator b)
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp 2009-01-21 17:57:35 EST (Wed, 21 Jan 2009)
@@ -12,47 +12,40 @@
#include "helpers.hpp"
#include "test_tree_traversal_data.hpp"
-
+#include "mock_binary_cursor.hpp"
#include "fake_binary_tree.hpp"
using namespace boost::tree;
-BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_with_list_fixture<int>)
+// TODO: Actually transform back and forth; eg, add 1 using STL transform, then subtract it
+// again using the subtree algorithm.
+
+BOOST_FIXTURE_TEST_SUITE(cursor_algorithms_test, fake_binary_tree_fixture<int>)
BOOST_AUTO_TEST_CASE_TEMPLATE( test_transform_descending, Order, orders)
{
- // First copy test_tree to test_tree2, by adding 1 to each element,
- // then copy test_tree2 to test_list, by subtracting 1 - so
- // test_list should hold test_tree's original elements in ORDER.
- boost::tree::transform(Order(), fbt1.descending_root(), fbt2.descending_root(), std::bind2nd(std::plus<int>(),1));
- boost::tree::transform(Order(), fbt2.descending_root(), o, std::bind2nd(std::minus<int>(),1));
- test_traversal(Order(), l.begin(), l.end());
+ typedef std::vector< std::pair<std::size_t, int> > container_type;
+ container_type po(11);
+ generate_mock_cursor_data(Order(), po);
+ //std::transform(po.begin(), po.end(), po.begin(), std::bind2nd(std::plus<int>(/*second member of pair*/),0))
+ container_type::const_iterator ci = po.begin();
+ container_type::const_iterator cie = po.end();
+ mock_binary_cursor< container_type::const_iterator > mc(ci, cie);
+
+ boost::tree::transform(Order(), fbt1.descending_root(), mc, std::bind2nd(std::plus<int>(),0));
}
BOOST_AUTO_TEST_CASE_TEMPLATE( test_transform_ascending, Order, orders)
{
- // First copy test_tree to test_tree2, by adding 1 to each element,
- // then copy test_tree2 to test_list, by subtracting 1 - so
- // test_list should hold test_tree's original elements in ORDER.
- boost::tree::transform(Order(), fbt1.ascending_root(), fbt2.ascending_root(), std::bind2nd(std::plus<int>(),1));
- boost::tree::transform(Order(), fbt2.ascending_root(), o, std::bind2nd(std::minus<int>(),1));
- test_traversal(Order(), l.begin(), l.end());
-}
-
-BOOST_AUTO_TEST_CASE_TEMPLATE( test_transform_trees_descending, Order, orders)
-{
- BOOST_CHECK(fbt1 != fbt2);
- boost::tree::transform(Order(), fbt1.descending_root(), fbt2.descending_root()
- , std::bind2nd(std::minus<int>(),1));
- validate_test_dataset1_minus_1_tree(fbt2.descending_root());
-}
-
-BOOST_AUTO_TEST_CASE_TEMPLATE( test_transform_trees_ascending, Order, orders)
-{
- BOOST_CHECK(fbt1 != fbt2);
- boost::tree::transform(Order(), fbt1.ascending_root(), fbt2.ascending_root()
- , std::bind2nd(std::minus<int>(),1));
- validate_test_dataset1_minus_1_tree(fbt2.ascending_root());
+ typedef std::vector< std::pair<std::size_t, int> > container_type;
+ container_type po(11);
+ generate_mock_cursor_data(Order(), po);
+ //std::transform(po.begin(), po.end(), po.begin(), std::bind2nd(std::plus<int>(/*second member of pair*/),0))
+ container_type::const_iterator ci = po.begin();
+ container_type::const_iterator cie = po.end();
+ mock_binary_cursor< container_type::const_iterator > mc(ci, cie);
+
+ boost::tree::transform(Order(), fbt1.ascending_root(), mc, std::bind2nd(std::plus<int>(),0));
}
BOOST_AUTO_TEST_SUITE_END()
\ 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