Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50685 - sandbox/SOC/2006/tree/trunk/libs/tree/test
From: ockham_at_[hidden]
Date: 2009-01-20 07:45:45


Author: bernhard.reiter
Date: 2009-01-20 07:45:45 EST (Tue, 20 Jan 2009)
New Revision: 50685
URL: http://svn.boost.org/trac/boost/changeset/50685

Log:
Make mock_tree also check for correct insertion position.
Text files modified:
   sandbox/SOC/2006/tree/trunk/libs/tree/test/copy_test.cpp | 31 +++++++++++++++++--------------
   sandbox/SOC/2006/tree/trunk/libs/tree/test/fake_binary_tree.hpp | 6 ++++--
   sandbox/SOC/2006/tree/trunk/libs/tree/test/mock_binary_cursor.hpp | 35 +++++++++++++++++++++++++++--------
   3 files changed, 48 insertions(+), 24 deletions(-)

Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/copy_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/copy_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/copy_test.cpp 2009-01-20 07:45:45 EST (Tue, 20 Jan 2009)
@@ -29,20 +29,23 @@
 
 BOOST_AUTO_TEST_CASE( alternate_test_copy_descending )
 {
- std::vector<int> po(11);
- po[0] = 8;
- po[1] = 3;
- po[2] = 1;
- po[3] = 6;
- po[4] = 4;
- po[5] = 7;
- po[6] = 10;
- po[7] = 14;
- po[8] = 13;
- po[9] = 11;
- po[10] = 12;
- std::vector<int>::const_iterator ci = po.begin();
- mock_binary_cursor< std::vector<int>::const_iterator > mc(ci);
+ using std::make_pair;
+ typedef std::vector< std::pair<std::size_t, int> > container_type;
+ container_type po(11);
+ po[0] = make_pair(0, 8);
+ po[1] = make_pair(1, 3);
+ po[2] = make_pair(3, 1);
+ po[3] = make_pair(4, 6);
+ po[4] = make_pair(9, 4);
+ po[5] = make_pair(10, 7);
+ po[6] = make_pair(2, 10);
+ po[7] = make_pair(6, 14);
+ po[8] = make_pair(13, 13);
+ po[9] = make_pair(27, 11);
+ po[10] = make_pair(56, 12);
+ 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::copy(preorder(), fbt1.descending_root(), mc);
 }

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-20 07:45:45 EST (Tue, 20 Jan 2009)
@@ -108,6 +108,8 @@
     return !(x == y);
 }
 
+// This should be easily extensible to nary by replacing the
+// factor 2 by n in dereference, left, right and idx.
 template <class T>
 class fake_descending_binary_cursor
 : public boost::tree::cursor_facade<
@@ -170,14 +172,14 @@
 
     void left()
     {
- m_pos <<= 1;
+ m_pos *= 2;
         ++m_pos;
     }
 
     void right()
     {
         ++m_pos;
- m_pos <<= 1;
+ m_pos *= 2;
     }
     
     bool const empty_() const

Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/mock_binary_cursor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/mock_binary_cursor.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/mock_binary_cursor.hpp 2009-01-20 07:45:45 EST (Tue, 20 Jan 2009)
@@ -10,6 +10,12 @@
 template <class Iter>
 class mock_binary_cursor;
 
+// Mock template class to check the correct value
+// to be assigned to a given position within a tree,
+// and if these assignments are done in a given order.
+//
+// The position checking logic is identical to that of fake_binary_tree,
+// so we might want to factor that part out to a position_tracking_nary_cursor.
 template <class Iter>
 class mock_binary_cursor
 : public boost::tree::cursor_facade<
@@ -20,21 +26,28 @@
>
 {
 private:
- Iter& m_iter;
+ Iter& m_iter, m_end;
+ std::size_t m_pos;
 public:
     typedef mock_binary_cursor<Iter> cursor;
     typedef mock_binary_cursor<Iter/* const*/> const_cursor;
 
     typedef typename mock_binary_cursor<Iter>::cursor_facade_::size_type size_type;
     
- mock_binary_cursor(Iter& iter)
- : m_iter(iter)
- {
- }
+ mock_binary_cursor(Iter& iter, Iter& end, std::size_t pos = 0)
+ : m_iter(iter), m_end(end), m_pos(pos) {}
+
+ mock_binary_cursor(mock_binary_cursor<Iter> const& other)
+ : m_iter(other.m_iter), m_end(other.m_end), m_pos(other.m_pos) {}
 
- void operator=(typename Iter::value_type const& val)
+ void operator=(typename Iter::value_type::second_type const& val)
     {
- BOOST_CHECK_EQUAL(val, *m_iter++);
+ BOOST_CHECK(m_iter != m_end);
+ if (m_iter == m_end)
+ return;
+ BOOST_CHECK_EQUAL((m_pos-1)/2, m_iter->first);
+ BOOST_CHECK_EQUAL(val, m_iter->second);
+ ++m_iter;
     }
     
 private:
@@ -54,18 +67,24 @@
 
     void increment()
     {
+ ++m_pos;
     }
     
     void decrement()
     {
+ --m_pos;
     }
 
     void left()
     {
+ m_pos *= 2;
+ ++m_pos;
     }
 
     void right()
     {
+ ++m_pos;
+ m_pos *= 2;
     }
     
     bool const empty_() const
@@ -75,7 +94,7 @@
 
     size_type const idx() const
     {
- return 0;
+ return (m_pos + 1) % 2;
     }
 };
 


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