3 #include "sh_tinyhash.h"
6 // Tests sh_list, sh_tinyhash, sh_vector
10 #define CHECK_COND(c, err) if (!(c)) { error = err; return false; }
18 Hmm(const Hmm &other) : m_Int(other.m_Int)
30 void operator = (const Hmm &other)
40 #define LIST_THIS_CHECK(lst, err) \
41 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter) \
42 CHECK_COND(&(*iter) == iter->m_This, err);
44 bool DoTestList(std::string &error)
46 typedef SourceHook::List<Hmm> ListType;
49 CHECK_COND(lst.empty(), "Part1");
51 for (int i = 1; i <= 100; ++i)
54 LIST_THIS_CHECK(lst, "PartA1");
56 CHECK_COND(!lst.empty(), "Part2");
60 CHECK_COND(lst.empty(), "Part3");
62 for (int i = 1; i <= 100; ++i)
65 CHECK_COND(lst.back() == 100, "Part4");
66 LIST_THIS_CHECK(lst, "PartA2");
69 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
70 CHECK_COND(*iter == ver++, "Part5");
72 CHECK_COND(ver == 101, "Part 6");
74 ListType::iterator iter50 = lst.find(50);
75 CHECK_COND(*iter50 == 50, "Part7");
77 iter50 = lst.erase(iter50);
78 CHECK_COND(*iter50 == 51, "Part8");
79 CHECK_COND(*--iter50 == 49, "Part8.2");
84 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
86 CHECK_COND(*iter == ver++, "Part9");
87 if (ver == 50 || ver == 80)
90 CHECK_COND(ver == 101, "Part10");
91 LIST_THIS_CHECK(lst, "PartA3");
95 CHECK_COND(lst.empty(), "Part11");
97 for (int i = 1; i <= 100; ++i)
100 CHECK_COND(lst2.size() == 100, "Part11.2");
102 LIST_THIS_CHECK(lst, "PartA4");
103 LIST_THIS_CHECK(lst2, "PartA5");
106 for (ListType::iterator iter = lst2.begin(); iter != lst2.end(); ++iter)
107 CHECK_COND(*iter == ver++, "Part12");
110 for (int i = 401; i <= 500; ++i)
113 CHECK_COND(lst2.size() == 100, "Part13");
116 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
117 CHECK_COND(*iter == ver++, "Part14");
119 LIST_THIS_CHECK(lst, "PartA6");
120 LIST_THIS_CHECK(lst2, "PartA7");
125 bool DoTestTinyHash(std::string &error)
127 const int mymax = 5000;
129 typedef SourceHook::THash<int, int> HashType;
132 for (int i = 1; i <= mymax; ++i)
135 for (int i = 1; i <= mymax; ++i)
136 CHECK_COND(hash[i] == i + 5000, "Part1");
140 HashType::iterator iter;
141 for (iter = hash.begin(); iter != hash.end(); ++iter)
142 CHECK_COND(iter->key == ver && iter->val == (ver++) + 5000, "Part2");
144 CHECK_COND(ver == mymax+1, "Part2.1");
146 iter = hash.find(300);
147 CHECK_COND(iter != hash.end() && iter->val == 300+5000, "Part3.1");
148 iter = hash.find(mymax+200);
149 CHECK_COND(iter == hash.end(), "Part3.2");
152 for (int i = 1; i <= mymax; ++i)
155 hash2.erase(mymax - 100);
156 CHECK_COND(hash2.find(mymax - 101) != hash2.end(), "Part 4.1");
157 CHECK_COND(hash2.find(mymax - 99) != hash2.end(), "Part 4.2");
158 CHECK_COND(hash2.find(mymax - 100) == hash2.end(), "Part 4.3");
159 hash2.erase(mymax - 99);
160 CHECK_COND(hash2.find(mymax - 101) != hash2.end(), "Part 4.4");
161 CHECK_COND(hash2.find(mymax - 99) == hash2.end(), "Part 4.5");
162 CHECK_COND(hash2.find(mymax - 100) == hash2.end(), "Part 4.6");
168 bool TestList(std::string &error)
170 if (!DoTestList(error))
173 if (!DoTestTinyHash(error))