Skip to content
Snippets Groups Projects
Commit 0737a4ad authored by Fons Rademakers's avatar Fons Rademakers
Browse files

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
parent 820fd91f
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,15 @@ ...@@ -14,7 +14,15 @@
// 8 - TMap with std::for_each (Partial iteration: from the Begin up to the 3rd element) // 8 - TMap with std::for_each (Partial iteration: from the Begin up to the 3rd element)
// 9 - TMap with std::find_if // 9 - TMap with std::find_if
// 10 - TMap with std::count_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 // STD
...@@ -28,85 +36,156 @@ ...@@ -28,85 +36,156 @@
#include "TObjString.h" #include "TObjString.h"
#include "TObjArray.h" #include "TObjArray.h"
#include "TMap.h" #include "TMap.h"
#include "TBtree.h"
#include "TOrdCollection.h"
#include "TRefArray.h"
// Local // Local
#include "stressIterators.h" #include "stressIterators.h"
const char * const cszValue("value");
using namespace std; using namespace std;
//______________________________________________________________________________ template<class __T>
void stressIterators() throw(exception) void fill_container(__T* _container, Int_t _count)
{ {
const Int_t size = 15; _container->SetOwner();
ostringstream ss; 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 ostringstream ss;
TList list; for (int i = 0; i < _count; ++i) {
for (int i = 0; i < size; ++i) {
ss << "test string #" << i; ss << "test string #" << i;
TObjString *s(new TObjString(ss.str().c_str())); TObjString *s(new TObjString(ss.str().c_str()));
list.Add(s); _container->Add(s, new TObjString(cszValue));
ss.str(""); ss.str("");
} }
}
//______________________________________________________________________________
void stressIterators() throw(exception)
{
const Int_t size = 15;
cout << "#1 ====================================" << endl; ostringstream ss;
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; // TList
TestContainer_find_if<TList>(list, "test string #3"); TList list;
fill_container(&list, size);
cout << "\n#3 ====================================" << endl; cout << "#1 ====================================" << endl;
cout << "-----> " << "TestContainer_count_if<TList>(list, \"test string #3\", 1)" << endl; cout << "-----> " << "TestContainer_for_each<TList>(list, list.GetSize())" << endl;
// we suppose to find exactly one match TestContainer_for_each<TList>(list, list.GetSize());
TestContainer_count_if<TList>(list, "test string #3", 1);
cout << "\n#2 ====================================" << endl;
cout << "-----> " << "TestContainer_find_if<TList>(list, \"test string #3\")" << endl;
TestContainer_find_if<TList>(list, "test string #3");
// TObjArray cout << "\n#3 ====================================" << endl;
TObjArray obj_array(size); cout << "-----> " << "TestContainer_count_if<TList>(list, \"test string #3\", 1)" << endl;
for (int i = 0; i < size; ++i) { // we suppose to find exactly one match
ss << "test string #" << i; TestContainer_count_if<TList>(list, "test string #3", 1);
TObjString *s(new TObjString(ss.str().c_str()));
obj_array.Add(s);
ss.str("");
} }
cout << "\n#4 ====================================" << endl; {
cout << "-----> " << "TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize())" << endl; // TObjArray
TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize()); TObjArray obj_array(size);
fill_container(&obj_array, size);
cout << "\n#5 ====================================" << endl; cout << "\n#4 ====================================" << endl;
cout << "-----> " << "TestContainer_find_if<TObjArray>(obj_array, \"test string #3\")" << endl; cout << "-----> " << "TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize())" << endl;
TestContainer_find_if<TObjArray>(obj_array, "test string #3"); TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize());
cout << "\n#6 ====================================" << endl; cout << "\n#5 ====================================" << endl;
cout << "-----> " << "TestContainer_count_if<TObjArray>(obj_array, \"test string #3\", 1)" << endl; cout << "-----> " << "TestContainer_find_if<TObjArray>(obj_array, \"test string #3\")" << endl;
// we suppose to find exactly one match TestContainer_find_if<TObjArray>(obj_array, "test string #3");
TestContainer_count_if<TObjArray>(obj_array, "test string #3", 1);
// TMap cout << "\n#6 ====================================" << endl;
const char * const cszValue("value"); cout << "-----> " << "TestContainer_count_if<TObjArray>(obj_array, \"test string #3\", 1)" << endl;
TMap map_container(size); // we suppose to find exactly one match
for (int i = 0; i < size; ++i) { TestContainer_count_if<TObjArray>(obj_array, "test string #3", 1);
ss << "test string #" << i; }
TObjString *s(new TObjString(ss.str().c_str()));
map_container.Add(s, new TObjString(cszValue)); {
ss.str(""); // 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());
} }
//______________________________________________________________________________ //______________________________________________________________________________
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment