$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r50469 - sandbox/SOC/2006/tree/trunk/libs/tree/test
From: ockham_at_[hidden]
Date: 2009-01-04 16:27:36
Author: bernhard.reiter
Date: 2009-01-04 16:27:36 EST (Sun, 04 Jan 2009)
New Revision: 50469
URL: http://svn.boost.org/trac/boost/changeset/50469
Log:
Test insert_cursor with hard-wired *order algorithms (don't rely on the actual proper function of copy algorithms).
Text files modified: 
   sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp         |    22 ------                                  
   sandbox/SOC/2006/tree/trunk/libs/tree/test/insert_cursor_test.cpp       |   127 ++++++++++++++++++++++++++++++++------- 
   sandbox/SOC/2006/tree/trunk/libs/tree/test/test_tree_traversal_data.hpp |     2                                         
   3 files changed, 104 insertions(+), 47 deletions(-)
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-04 16:27:36 EST (Sun, 04 Jan 2009)
@@ -208,28 +208,6 @@
     }
 };
 
-//template <class T>
-//struct fake_ascending_binary_cursor
-//: public fake_descending_binary_cursor<T> {
-//    fake_ascending_binary_cursor(fake_binary_tree<T>& t
-//                                    , typename fake_binary_tree<T>::size_type p)
-//    : fake_descending_binary_cursor<T>(t, p) {}
-//    
-//    fake_ascending_binary_cursor& to_parent()
-//    {
-//        --fake_descending_binary_cursor<T>::m_pos;
-//        fake_descending_binary_cursor<T>::m_pos >>= 1;
-//        return *this;
-//    }
-//    
-//    fake_ascending_binary_cursor parent()
-//    {
-//        fake_ascending_binary_cursor tmp(*this);
-//        tmp.to_parent();
-//        return tmp;
-//    }
-//};
-
 fake_binary_tree<int> generate_fake_binary_tree()
 {
     fake_binary_tree<int> mt(57);
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/insert_cursor_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/insert_cursor_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/insert_cursor_test.cpp	2009-01-04 16:27:36 EST (Sun, 04 Jan 2009)
@@ -19,14 +19,13 @@
 
 #include "fake_binary_tree.hpp"
 
+// TODO: Actually use fake binary tree.
+
 using namespace boost::tree;
 
 BOOST_FIXTURE_TEST_SUITE(insert_cursor_test, test_binary_tree_fixture<int>)
 
-// Maybe suffix this by "_preorder", and add
-// emulated inorder and postorder versions, so
-// we can check whether insert_cursor works in all cases
-// without relying on algorithms. 
+
 template <class Cursor>
 void fill_subtree_with_data(Cursor cur)
 {
@@ -47,39 +46,119 @@
 void fill_subtree_with_data_in_preorder(Cursor cur)
 {
     *cur.to_begin() = 8;
+    Cursor c2(cur);
     *cur.to_begin() = 3;
-    *cur.to_begin() = 1;  //Leaf
-    *cur.begin().end().begin() = 6;
-    *cur.begin().end().begin().begin() = 4; //Leaf
-    *cur.begin().end().end().begin() = 7; //Leaf
-    *cur.end().begin() = 10;
-    *cur.end().end().begin() = 14;
-    *cur.end().end().begin().begin() = 13;
-    *cur.end().end().begin().begin().begin() = 11; 
-    *cur.end().end().begin().begin().end().begin() = 12; //Leaf
+    Cursor c3(cur);
+    *cur.to_begin() = 1;
+    *(++c3).to_begin() = 6;
+    Cursor c4(c3);
+    *c3.to_begin() = 4;
+    *(++c4).to_begin() = 7;
+
+    *(++c2).to_begin() = 10;
+    *(++c2).to_begin() = 14;
+    *c2.to_begin() = 13;
+    *c2.to_begin() = 11;
+    *(++c2).to_begin() = 12;
+}
+
+template <class Cursor>
+void fill_subtree_with_data_in_inorder(Cursor cur)
+{
+    cur.to_begin();
+    Cursor c2(cur);
+    cur.to_begin();
+    Cursor c3(cur);
+    *cur.to_begin() = 1;
+    *c3 = 3;
+    Cursor c4(c3);
+    *(++c3).to_begin();
+    Cursor c5(c3);
+    *c3.to_begin() = 4;
+    *c5 = 6;
+    *(++c5).to_begin() = 7;
+    *c2 = 8;
+    
+    *(++c2).to_begin() = 10;
+    (++c2).to_begin();
+    Cursor c14(c2);
+    c2.to_begin();
+    Cursor c13(c2);
+    *c2.to_begin() = 11;
+    *(++c2).to_begin() = 12;
+    *c13 = 13;
+    *c14 = 14;
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE ( test_desc_copy_using_insert_cursor, Order, orders )
+template <class Cursor>
+void fill_subtree_with_data_in_postorder(Cursor cur)
+{
+    cur.to_begin();
+    Cursor c2(cur);
+    cur.to_begin();
+    Cursor c3(cur);
+    *cur.to_begin() = 1;
+    Cursor c4(c3);
+    *(++c4).to_begin();
+    Cursor c6(c4);
+    Cursor c7(c4);
+    *c4.to_begin() = 4;
+    *(++c7).to_begin() = 7;
+    *c6 = 6;
+    *c3 = 3;
+    
+    Cursor c8(c2);
+    (++c2).to_begin();
+    Cursor c10(c2);
+    (++c2).to_begin();
+    Cursor c14(c2);
+    c2.to_begin();
+    Cursor c13(c2);
+    c2.to_begin();
+    Cursor c11(c2);
+    *(++c2).to_begin() = 12;
+    *c11 = 11;
+    *c13 = 13;
+    *c14 = 14;
+    *c10 = 10;
+    *c8 = 8;
+}
+
+BOOST_AUTO_TEST_CASE ( test_desc_copy_using_insert_cursor_preorder )
 {
     bt2.clear();
+    fill_subtree_with_data_in_preorder(tree_inserter(bt2, bt2.root()));
 
-    boost::tree::copy(Order(), bt.root(), tree_inserter(bt2, bt2.root())
-                    , boost::tree::descending_vertical_traversal_tag());
-//    fill_subtree_with_data(tree_inserter(bt2, bt2.root())); //FIXME
+    validate_test_dataset1_tree(bt2.root());
+}
+
+BOOST_AUTO_TEST_CASE ( test_desc_copy_using_insert_cursor_inorder )
+{
+    bt2.clear();
+    fill_subtree_with_data_in_inorder(tree_inserter(bt2, bt2.root()));
 
     validate_test_dataset1_tree(bt2.root());
-    BOOST_CHECK_EQUAL(size(bt2.root()), size(bt.root()));
 }
 
-BOOST_AUTO_TEST_CASE_TEMPLATE ( test_asc_copy_using_insert_cursor, Order, orders )
-{    
+BOOST_AUTO_TEST_CASE ( test_desc_copy_using_insert_cursor_postorder )
+{
     bt2.clear();
-        
-    boost::tree::copy(Order(), bt.root(), tree_inserter(bt2, bt2.root())
-                    , boost::tree::ascending_vertical_traversal_tag());
+    fill_subtree_with_data_in_postorder(tree_inserter(bt2, bt2.root()));
 
     validate_test_dataset1_tree(bt2.root());
-    BOOST_CHECK_EQUAL(size(bt2.root()), size(bt.root())); 
 }
 
+// FIXME: Should also work with fill_subtree_with_data
+
+//BOOST_AUTO_TEST_CASE_TEMPLATE ( test_asc_copy_using_insert_cursor, Order, orders )
+//{    
+//    bt2.clear();
+//        
+//    boost::tree::copy(Order(), bt.root(), tree_inserter(bt2, bt2.root())
+//                    , boost::tree::ascending_vertical_traversal_tag());
+//
+//    validate_test_dataset1_tree(bt2.root());
+//    BOOST_CHECK_EQUAL(size(bt2.root()), size(bt.root())); 
+//}
+
 BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
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-04 16:27:36 EST (Sun, 04 Jan 2009)
@@ -251,7 +251,7 @@
 template <class Iterator>
 void test_traversal(boost::tree::postorder, Iterator a, Iterator b)
 {    
-    BOOST_CHECK_EQUAL(*a++, 1);    
+    BOOST_CHECK_EQUAL(*a++, 1); 
     BOOST_CHECK_EQUAL(*a++, 4);
     BOOST_CHECK_EQUAL(*a++, 7);
     BOOST_CHECK_EQUAL(*a++, 6);