Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57259 - in sandbox/SOC/2006/tree/trunk: boost/tree libs/tree/test
From: ockham_at_[hidden]
Date: 2009-10-31 09:59:54


Author: bernhard.reiter
Date: 2009-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
New Revision: 57259
URL: http://svn.boost.org/trac/boost/changeset/57259

Log:
Add tests for inorder to_past() and related; plus some doxygen fixes.
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/inorder_algorithms.hpp | 31 +++++++++++++++++++++----------
   sandbox/SOC/2006/tree/trunk/boost/tree/postorder_algorithms.hpp | 16 +++++++++++-----
   sandbox/SOC/2006/tree/trunk/boost/tree/preorder_algorithms.hpp | 16 ++++++++++------
   sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp | 3 ++-
   sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp | 23 ++++++++++++++++++++++-
   5 files changed, 66 insertions(+), 23 deletions(-)

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/inorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/inorder_algorithms.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/inorder_algorithms.hpp 2009-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
@@ -34,9 +34,13 @@
 };
 
 /**
- * @brief Inorder successor
- * @param c MultiwayCursor to be set to its inorder successor
- * @ingroup traversal
+ * @brief Inorder successor
+ * @param c MultiwayCursor to be set to its inorder successor
+ * @return true if the operation succeeded;
+ * false if c already was the last element in inorder
+ * @ingroup traversal
+ *
+ * Note that this is equivalent to the reverse inorder successor.
  */
 template <class MultiwayCursor>
 inline
@@ -51,7 +55,6 @@
         return true;
     }
 
- //MultiwayCursor d = c;
     while (index(c) && !c.is_root())
         c.to_parent();
 
@@ -59,14 +62,18 @@
         c.to_parent();
         return true;
     }
- else // Move past the last inorder element
- return false; //c = d; //to_last(inorder(), c);
+ else
+ return false;
     return true;
 }
 
 /**
- * @brief Inorder predecessor
- * @param c MultiwayCursor to be set to its inorder predecessor
+ * @brief Inorder predecessor
+ * @param c MultiwayCursor to be set to its inorder predecessor
+ * @return true if the operation succeeded;
+ * false if c already was the first element in inorder
+ *
+ * Note that this is equivalent to the reverse inorder predecessor.
  */
 template <class MultiwayCursor>
 inline
@@ -88,14 +95,16 @@
         c.to_parent();
         return true;
     }
- else // Move past the last inorder element
- return false; //c = d; //to_last(inorder(), c);
+ else
+ return false;
 }
 
 /**
  * @brief First element of a subtree in inorder traversal
  * @param c Subtree root cursor that will be set to the first inorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse inorder to_last.
  */
 template <class Cursor>
 BOOST_CONCEPT_REQUIRES(
@@ -134,6 +143,8 @@
  * @brief Last element of a subtree in inorder traversal
  * @param c Subtree root cursor that will be set to the last inorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse inorder to_first.
  */
 template <class Cursor>
 BOOST_CONCEPT_REQUIRES(

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/postorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/postorder_algorithms.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/postorder_algorithms.hpp 2009-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
@@ -33,8 +33,10 @@
 /**
  * @brief Postorder successor
  * @param c Cursor to be set to its postorder successor
+ * @return true if the operation succeeded;
+ * false if c already was the last element in postorder
  *
- * Note that this is the reverse preorder predecessor.
+ * Note that this is equivalent to the reverse preorder predecessor.
  */
 template <class Cursor>
 inline
@@ -66,8 +68,10 @@
 /**
  * @brief Postorder predecessor
  * @param c Cursor to be set to its postorder predecessor
+ * @return true if the operation succeeded;
+ * false if c already was the first element in postorder
  *
- * Note that this is the reverse preorder successor.
+ * Note that this is equivalent to the reverse preorder successor.
  */
 template <class Cursor>
 inline
@@ -97,6 +101,8 @@
  * @brief First element of a subtree in postorder traversal
  * @param c Subtree root cursor that will be set to the first postorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse preorder to_last.
  */
 template <class Cursor>
 BOOST_CONCEPT_REQUIRES(
@@ -113,16 +119,16 @@
             c = d;
             d.to_begin();
         } else {
- //--c;
             return;
         }
 }
 
 /**
- * @brief One position past the last element of a subtree in postorder
- * traversal
+ * @brief Last element of a subtree in postorder traversal
  * @param c Subtree root cursor that will be set to the last postorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse preorder to_first.
  */
 template <class Cursor>
 void to_last(postorder, Cursor& c)

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/preorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/preorder_algorithms.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/preorder_algorithms.hpp 2009-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
@@ -33,6 +33,8 @@
 /**
  * @brief Preorder successor
  * @param c Cursor to be set to its preorder successor
+ * @return true if the operation succeeded;
+ * false if c already was the last element in preorder
  *
  * Note that this is the reverse postorder predecessor.
  */
@@ -63,8 +65,7 @@
             if (!(++c).is_leaf())
                 return true;
     }
-
- //to_last(preorder(), c);
+
     return false;
 }
 
@@ -112,6 +113,8 @@
 /**
  * @brief Preorder predecessor
  * @param c Cursor to be set to its preorder predecessor
+ * @return true if the operation succeeded;
+ * false if c already was the first element in preorder
  *
  * Note that this is the reverse postorder successor.
  */
@@ -146,6 +149,8 @@
  * @brief First element of a subtree in preorder traversal
  * @param c Subtree root cursor that will be set to the first preorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse postorder to_last.
  */
 template <class Cursor>
 BOOST_CONCEPT_REQUIRES(
@@ -155,10 +160,11 @@
 {}
 
 /**
- * @brief One position past the last element of a subtree in preorder
- * traversal
+ * @brief Last element of a subtree in preorder traversal
  * @param c Subtree root cursor that will be set to the last preorder
  * position in the subtree.
+ *
+ * Note that this is equivalent to the reverse postorder to_first.
  */
 template <class Cursor>
 void to_last(preorder, Cursor& c)
@@ -166,8 +172,6 @@
     while (!c.is_leaf())
         if (c.to_end().is_leaf())
             --c;
- //if (!index(c))
- // ++c;
     c.to_parent();
 }
 

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-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
@@ -46,13 +46,14 @@
     typename container_type::const_reverse_iterator ci = order_index.rbegin();
     typename container_type::const_reverse_iterator cie = order_index.rend();
 
- //BOOST_CHECK_EQUAL(*c, ci->val);
     --cie;
     for (; ci!=cie; ++ci) {
         BOOST_CHECK_EQUAL(*c, ci->val);
         BOOST_CHECK_EQUAL(boost::tree::predecessor(Order(), c), true);
     }
 
+ BOOST_CHECK_EQUAL(*c, ci->val);
+
     fake_root_tracking_binary_tree<int>::cursor d = frbt1.root();
     fake_to_first(Order(), d);
     BOOST_CHECK(c == d);

Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp 2009-10-31 09:59:54 EDT (Sat, 31 Oct 2009)
@@ -36,4 +36,25 @@
 // BOOST_CHECK_EQUAL(*c, cie->val);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+BOOST_AUTO_TEST_CASE( test_to_past )
+{
+ fake_root_tracking_binary_tree<int> frbt1(fbt1);
+ fake_root_tracking_binary_tree<int>::cursor c = frbt1.root();
+ fake_root_tracking_binary_tree<int>::cursor d = frbt1.root();
+
+ boost::tree::to_past(inorder(), c);
+ fake_to_past(inorder(), d);
+ BOOST_CHECK(c == d);
+
+ c = frbt1.root();
+ fake_to_last(inorder(), c);
+ boost::tree::last_to_past(inorder(), c);
+ BOOST_CHECK(c == d);
+
+ d = frbt1.root();
+ fake_to_last(inorder(), d);
+ boost::tree::past_to_last(inorder(), c);
+ BOOST_CHECK(c == d);
+}
+
+BOOST_AUTO_TEST_SUITE_END()


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