From 0737a4ad84f5ed57c2a0e026fffc337ab08850fe Mon Sep 17 00:00:00 2001
From: Fons Rademakers <Fons.Rademakers@cern.ch>
Date: Thu, 24 Apr 2008 16:24:31 +0000
Subject: [PATCH] From Anar: -  added  tests for  the following  cases:    *
 TBtree with std::for_each (Full iteration: from the Begin up to the End)    *
 TBtree with std::find_if    * TBtree with std::count_if    * TOrdCollection
 with std::for_each (Full iteration: from the Begin      up to the End)    *
 TOrdCollection with std::find_if    * TOrdCollection with std::count_if    *
 TRefArray with std::for_each (Full iteration: from the Begin up to the End)  
  * TRefArray with std::find_if    * TRefArray with std::count_if

git-svn-id: http://root.cern.ch/svn/root/trunk@23532 27541ba8-7e3a-0410-8455-c3a389f83636
---
 test/stressIterators.cxx | 189 +++++++++++++++++++++++++++------------
 1 file changed, 134 insertions(+), 55 deletions(-)

diff --git a/test/stressIterators.cxx b/test/stressIterators.cxx
index 2c60319b91d..8f3eebe477e 100644
--- a/test/stressIterators.cxx
+++ b/test/stressIterators.cxx
@@ -14,7 +14,15 @@
 // 8  - TMap with std::for_each (Partial iteration: from the Begin up to the 3rd element)
 // 9  - TMap with std::find_if
 // 10 - TMap with std::count_if
-
+// 11 - TBtree with std::for_each (Full iteration: from the Begin up to the End)
+// 12 - TBtree with std::find_if
+// 13 - TBtree with std::count_if
+// 14 - TOrdCollection with std::for_each (Full iteration: from the Begin up to the End)
+// 15 - TOrdCollection with std::find_if
+// 16 - TOrdCollection with std::count_if
+// 17 - TRefArray with std::for_each (Full iteration: from the Begin up to the End)
+// 18 - TRefArray with std::find_if
+// 19 - TRefArray with std::count_if
 
 
 // STD
@@ -28,85 +36,156 @@
 #include "TObjString.h"
 #include "TObjArray.h"
 #include "TMap.h"
+#include "TBtree.h"
+#include "TOrdCollection.h"
+#include "TRefArray.h"
 // Local
 #include "stressIterators.h"
 
+const char * const cszValue("value");
+
 using namespace std;
 
-//______________________________________________________________________________
-void stressIterators() throw(exception)
+template<class __T>
+void fill_container(__T* _container, Int_t _count)
 {
-   const Int_t size = 15;
+   _container->SetOwner();
 
    ostringstream ss;
+   for (int i = 0; i < _count; ++i) {
+      ss << "test string #" << i;
+      TObjString *s(new TObjString(ss.str().c_str()));
+      _container->Add(s);
+      ss.str("");
+   }
+}
+
+template<>
+void fill_container<TMap>(TMap* _container, Int_t _count)
+{
+   _container->SetOwner();
 
-   // TList
-   TList list;
-   for (int i = 0; i < size; ++i) {
+   ostringstream ss;
+   for (int i = 0; i < _count; ++i) {
       ss << "test string #" << i;
       TObjString *s(new TObjString(ss.str().c_str()));
-      list.Add(s);
+      _container->Add(s, new TObjString(cszValue));
       ss.str("");
    }
+}
+
+//______________________________________________________________________________
+void stressIterators() throw(exception)
+{
+   const Int_t size = 15;
 
-   cout << "#1 ====================================" << endl;
-   cout << "-----> " << "TestContainer_for_each<TList>(list, list.GetSize())" << endl;
-   TestContainer_for_each<TList>(list, list.GetSize());
+   ostringstream ss;
 
-   cout << "\n#2 ====================================" << endl;
-   cout << "-----> " << "TestContainer_find_if<TList>(list, \"test string #3\")" << endl;
-   TestContainer_find_if<TList>(list, "test string #3");
+   {
+      // TList
+      TList list;
+      fill_container(&list, size);
 
-   cout << "\n#3 ====================================" << endl;
-   cout << "-----> " << "TestContainer_count_if<TList>(list, \"test string #3\", 1)" << endl;
-   // we suppose to find exactly one match
-   TestContainer_count_if<TList>(list, "test string #3", 1);
+      cout << "#1 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each<TList>(list, list.GetSize())" << endl;
+      TestContainer_for_each<TList>(list, list.GetSize());
 
+      cout << "\n#2 ====================================" << endl;
+      cout << "-----> " << "TestContainer_find_if<TList>(list, \"test string #3\")" << endl;
+      TestContainer_find_if<TList>(list, "test string #3");
 
-   // TObjArray
-   TObjArray obj_array(size);
-   for (int i = 0; i < size; ++i) {
-      ss << "test string #" << i;
-      TObjString *s(new TObjString(ss.str().c_str()));
-      obj_array.Add(s);
-      ss.str("");
+      cout << "\n#3 ====================================" << endl;
+      cout << "-----> " << "TestContainer_count_if<TList>(list, \"test string #3\", 1)" << endl;
+      // we suppose to find exactly one match
+      TestContainer_count_if<TList>(list, "test string #3", 1);
    }
 
-   cout << "\n#4 ====================================" << endl;
-   cout << "-----> " << "TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize())" << endl;
-   TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize());
+   {
+      // TObjArray
+      TObjArray obj_array(size);
+      fill_container(&obj_array, size);
 
-   cout << "\n#5 ====================================" << endl;
-   cout << "-----> " << "TestContainer_find_if<TObjArray>(obj_array, \"test string #3\")" << endl;
-   TestContainer_find_if<TObjArray>(obj_array, "test string #3");
+      cout << "\n#4 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize())" << endl;
+      TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize());
 
-   cout << "\n#6 ====================================" << endl;
-   cout << "-----> " << "TestContainer_count_if<TObjArray>(obj_array, \"test string #3\", 1)" << endl;
-   // we suppose to find exactly one match
-   TestContainer_count_if<TObjArray>(obj_array, "test string #3", 1);
+      cout << "\n#5 ====================================" << endl;
+      cout << "-----> " << "TestContainer_find_if<TObjArray>(obj_array, \"test string #3\")" << endl;
+      TestContainer_find_if<TObjArray>(obj_array, "test string #3");
 
-   // TMap
-   const char * const cszValue("value");
-   TMap map_container(size);
-   for (int i = 0; i < size; ++i) {
-      ss << "test string #" << i;
-      TObjString *s(new TObjString(ss.str().c_str()));
-      map_container.Add(s, new TObjString(cszValue));
-      ss.str("");
+      cout << "\n#6 ====================================" << endl;
+      cout << "-----> " << "TestContainer_count_if<TObjArray>(obj_array, \"test string #3\", 1)" << endl;
+      // we suppose to find exactly one match
+      TestContainer_count_if<TObjArray>(obj_array, "test string #3", 1);
+   }
+
+   {
+      // TMap
+      TMap map_container(size);
+      fill_container(&map_container, size);
+
+      cout << "\n#7 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each<TMap>(map_container, map_container.GetSize())" << endl;
+      TestContainer_for_each<TMap>(map_container, map_container.GetSize());
+      cout << "\n#8 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each2<TMap>(map_container)" << endl;
+      TestContainer_for_each2<TMap>(map_container);
+      cout << "\n#9 ====================================" << endl;
+      cout << "-----> " << "TestContainer_find_if<TMap>(map_container, cszValue)" << endl;
+      TestContainer_find_if<TMap>(map_container, cszValue);
+      cout << "\n#10 ====================================" << endl;
+      cout << "-----> " << "TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize())" << endl;
+      TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize());
+   }
+
+   {
+      // TBtree
+      TBtree btree_container;
+      fill_container(&btree_container, size);
+
+      cout << "\n#11 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each<TBtree>(btree_container, btree_container.GetSize())" << endl;
+      TestContainer_for_each<TBtree>(btree_container, btree_container.GetSize());
+      cout << "\n#12 ====================================" << endl;
+      cout << "-----> " << "TestContainer_find_if<TBtree>(btree_container, \"test string #3\")" << endl;
+      TestContainer_find_if<TBtree>(btree_container, "test string #3");
+      cout << "\n#13 ====================================" << endl;
+      cout << "-----> " << "TestContainer_count_if<TBtree>(btree_container, \"test string #3\", 1)" << endl;
+      TestContainer_count_if<TBtree>(btree_container, "test string #3", 1);
+   }
+
+   {
+      // TOrdCollection
+      TOrdCollection container;
+      fill_container(&container, size);
+
+      cout << "\n#14 ====================================" << endl;
+      cout << "-----> " << "TestContainer_for_each<TOrdCollection>(container, container.GetSize())" << endl;
+      TestContainer_for_each<TOrdCollection>(container, container.GetSize());
+      cout << "\n#15 ====================================" << endl;
+      cout << "-----> " << "TestContainer_find_if<TOrdCollection>(container, \"test string #3\");" << endl;
+      TestContainer_find_if<TOrdCollection>(container, "test string #3");
+      cout << "\n#16 ====================================" << endl;
+      cout << "-----> " << "TestContainer_count_if<TOrdCollection>(container, \"test string #3\", 1)" << endl;
+      TestContainer_count_if<TOrdCollection>(container, "test string #3", 1);
+   }
+
+   {
+      // TRefArray
+     TRefArray container;
+     fill_container(&container, size);
+
+     cout << "\n#17 ====================================" << endl;
+     cout << "-----> " << "TestContainer_for_each<TRefArray>(container, container.GetSize())" << endl;
+     TestContainer_for_each<TRefArray>(container, container.GetLast()+1); // TODO: why container.GetSize() returns 16 instead of 15
+     cout << "\n#18 ====================================" << endl;
+     cout << "-----> " << "TestContainer_find_if<TOrdCollection>(container, \"test string #3\");" << endl;
+     TestContainer_find_if<TRefArray>(container, "test string #3");
+     cout << "\n#19 ====================================" << endl;
+     cout << "-----> " << "TestContainer_count_if<TOrdCollection>(container, \"test string #3\", 1)" << endl;
+     TestContainer_count_if<TRefArray>(container, "test string #3", 1);
    }
 
-   cout << "\n#7 ====================================" << endl;
-   cout << "-----> " << "TestContainer_for_each<TMap>(map_container, map_container.GetSize())" << endl;
-   TestContainer_for_each<TMap>(map_container, map_container.GetSize());
-   cout << "\n#8 ====================================" << endl;
-   cout << "-----> " << "TestContainer_for_each2<TMap>(map_container)" << endl;
-   TestContainer_for_each2<TMap>(map_container);
-   cout << "\n#9 ====================================" << endl;
-   cout << "-----> " << "TestContainer_find_if<TMap>(map_container, cszValue)" << endl;
-   TestContainer_find_if<TMap>(map_container, cszValue);
-   cout << "\n#10 ====================================" << endl;
-   cout << "-----> " << "TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize());" << endl;
-   TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize());
 }
 
 //______________________________________________________________________________
-- 
GitLab