Boost logo

Boost-Commit :

From: chintanraoh_at_[hidden]
Date: 2008-06-08 13:09:00


Author: chintanraoh
Date: 2008-06-08 13:08:59 EDT (Sun, 08 Jun 2008)
New Revision: 46249
URL: http://svn.boost.org/trac/boost/changeset/46249

Log:
added test for const functions
Text files modified:
   sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_trie_string.cpp | 68 ++++++++++++++++++++++++++++-----------
   1 files changed, 48 insertions(+), 20 deletions(-)

Modified: sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_trie_string.cpp
==============================================================================
--- sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_trie_string.cpp (original)
+++ sandbox/SOC/2008/digital_searching/dsearch/libs/dsearch/test/test_trie_string.cpp 2008-06-08 13:08:59 EDT (Sun, 08 Jun 2008)
@@ -12,13 +12,6 @@
 using namespace boost::dsearch;
 using std::make_pair;
 
-/*template<class T>
-void print(const T &tr)
-{
- T::iterator it=tr.begin();
- void
-}*/
-
 //testing insert function
 template<class T>
 T test_insert()
@@ -62,7 +55,7 @@
 
 //testing copy contructor
 template <class T>
-void test_copy(T tr)
+void test_copy(const T &tr)
 {
         BOOST_CHECK( tr.find("hello")!=tr.end() );
         BOOST_CHECK( *tr.find("hello")==1 );
@@ -92,8 +85,9 @@
         BOOST_CHECK( tr.find("worldy")==tr.end() );
 }
 
+
 template<class T>
-void test_bound(T tr)
+void test_bound(const T &tr)
 {
         //""=3<"hel"=4<"hellish"=7<"hello"=1<"wor"=5<"world"=2<"worry"=6
         BOOST_CHECK(tr.upper_bound("")==tr.find(""));
@@ -127,13 +121,14 @@
         BOOST_CHECK(tr.lower_bound("a")==tr.find(""));
         BOOST_CHECK(tr.lower_bound("")==tr.find(""));
 
- tr.erase("");//made sure at least this works :)
- BOOST_CHECK(tr.lower_bound("a")==tr.end());
- BOOST_CHECK(tr.lower_bound("")==tr.end());
- BOOST_CHECK(tr.lower_bound("abcd")==tr.end());
-
+ T tr1=tr;
+ tr1.erase("");//made sure at least this works :)
+ BOOST_CHECK(tr1.lower_bound("a")==tr1.end());
+ BOOST_CHECK(tr1.lower_bound("")==tr1.end());
+ BOOST_CHECK(tr1.lower_bound("abcd")==tr1.end());
 }
 
+
 template<class T>
 void test_erase(T tr)
 {
@@ -165,10 +160,10 @@
 void test_iteration(T tr)
 {
         //"" 3<"hel" 4<"hellish" 7<"hello" 1<"wor" 5<"world" 2<"worry" 6
- std::cout<<"bloody gods"<<std::endl;
+ //std::cout<<"bloody gods"<<std::endl;
         typename T::iterator it=tr.begin();
 
- std::cout<<"test_iteration:"<<*(tr.find(""))<<std::endl;
+// std::cout<<"test_iteration:"<<*(tr.find(""))<<std::endl;
         BOOST_CHECK(it==tr.find(""));
         it++;
 
@@ -238,7 +233,6 @@
         tr.erase(it);
         BOOST_CHECK(tr.find("hello")==tr.end());
 
- //it=cit; //TODO:MAKE THIS NOT COMPILE
         cit=it; //should compile properly
 
         //"" 3<"hel" 4<"hellish" 7<"hello" 1<"wor" 5<"world" 2<"worry" 6
@@ -303,19 +297,53 @@
         //BOOST_CHECK( tr.empty() );
 }
 
+template<class T>
+void test_prefix_range(const T &tr)
+{
+ typedef typename T::const_iterator iterator;
+ std::pair<iterator,iterator> pair_range;
+ //"" 3<"hel" 4<"hellish" 7<"hello" 1<"wor" 5<"world" 2<"worry" 6
+ pair_range=tr.prefix_range("");
+ BOOST_CHECK(tr.begin()==pair_range.first);
+ BOOST_CHECK(tr.end()==pair_range.second);
+
+ pair_range=tr.prefix_range("h");
+ //std::cout<<"pair range ("<<*pair_range.first<<" , "<<*pair_range.second<<" )"<<std::endl;
+ BOOST_CHECK(tr.find("hel")==pair_range.first);
+ BOOST_CHECK(tr.find("wor")==pair_range.second);
+
+ pair_range=tr.prefix_range("hel");
+ BOOST_CHECK(tr.find("hel")==pair_range.first);
+ //std::cout<<"pair range ("<<*pair_range.first<<" , "<<*pair_range.second<<" )"<<std::endl;
+ BOOST_CHECK(tr.find("wor")==pair_range.second);
+}
+
+template<class T>
+void test_insert_simple()
+{
+ T tr;
+ tr["hello"]=10;
+ BOOST_REQUIRE(tr.find("hello")!=tr.end());
+ //std::cout<<"required "<<*tr.find("hello")<<"= 10"<<std::endl;
+ BOOST_REQUIRE(*tr.find("hello")==10);
+}
+
 int test_main(int,char **)
 {
         typedef trie<std::string,int,trie_array_node,string_traits> trie_type;
- trie_type tr;
+
+ test_insert_simple<trie_type>();
         test_copy_simple<trie_type>();
+
+ trie_type tr;
         tr=test_insert<trie_type>();
 
         test_copy(tr);
         test_bound(tr);
         test_erase(tr);
         test_iteration(tr);
- test_erase_iterator<trie_type>();
-
+ //test_erase_iterator<trie_type>();
+ test_prefix_range(test_insert<trie_type>());
         //test_erase_range(tr);
 
         return 0;


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