diff options
author | David Robillard <d@drobilla.net> | 2007-07-26 08:16:44 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-07-26 08:16:44 +0000 |
commit | ffe8ccde2157ef802b7876cef9489904c02bcece (patch) | |
tree | c02d6149a0cafa6542a86bbfd0cfab86e2906d0e /tests | |
parent | ca1c84d3d3df15ed62588c77bbbae537a83c016f (diff) | |
download | raul-ffe8ccde2157ef802b7876cef9489904c02bcece.tar.gz raul-ffe8ccde2157ef802b7876cef9489904c02bcece.tar.bz2 raul-ffe8ccde2157ef802b7876cef9489904c02bcece.zip |
Add Table unit test.
Match std::map interface for empty and insert (more powerful insert interface).
git-svn-id: http://svn.drobilla.net/lad/raul@631 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/table_test.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/table_test.cpp b/tests/table_test.cpp new file mode 100644 index 0000000..06bf489 --- /dev/null +++ b/tests/table_test.cpp @@ -0,0 +1,108 @@ +#include <string> +#include <iostream> +#include <utility> +#include <raul/Table.hpp> +#include <raul/TableImpl.hpp> + +using namespace Raul; +using namespace std; + +int +main() +{ + Table<int, int> t; + for (size_t i=0; i < 20; ++i) { + int val = rand()%10; + t.insert(make_pair(val, val)); + } + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) + cout << i->first << " "; + cout << endl; + + Table<int, int>::iterator first = t.begin(); + ++first; + Table<int, int>::iterator last = first; + ++last; ++last; ++last; + + cout << "Erasing elements 1..3:" << endl; + t.erase(first, last); + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) + cout << i->first << " "; + cout << endl; + + cout << "Erasing elements 0..3" << endl; + first = t.begin(); + last = first; + ++last; ++last; ++last; + t.erase(first, last); + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) + cout << i->first << " "; + cout << endl; + + cout << "Erasing elements end()-2..end()" << endl; + last = t.end(); + first = last; + --first; --first; + t.erase(first, last); + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) + cout << i->first << " "; + cout << endl; + + cout << "Erasing everything" << endl; + first = t.begin(); + last = t.end(); + t.erase(first, last); + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) + cout << i->first << " "; + cout << endl; + + /* **** */ + + cout << "Assuming you built with debugging, if this continues to run " + << "and chews your CPU without dying, everything's good." << endl; + srand(time(NULL)); + + Table<string, string> st; + + st.insert(make_pair("apple", "core")); + st.insert(make_pair("candy", "cane")); + st.insert(make_pair("banana", "peel")); + + st.erase("apple"); + + while (true) { + Table<int, int> t; + + size_t table_size = (rand() % 1000) + 1; + + for (size_t i=0; i < table_size; ++i) { + int val = rand()%100; + t.insert(make_pair(val, ((val + 3) * 17))); + } + + for (int i=0; i < (int)table_size; ++i) { + int val = rand()%100; + Table<int, int>::iterator iter = t.find(val); + assert(iter == t.end() || iter->second == (val + 3) * 17); + } + + /*cout << "CONTENTS:" << endl; + + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) { + cout << i->first << ": " << i->second << endl; + } + + Table<int,int>::iterator i = t.find(7); + if (i != t.end()) + cout << "Find: 7: " << i->second << endl; + */ + } + + return 0; +} + |