SourceHook tests pass again! Added test for list (and a small bit of tinyhash). Woot.
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_This(this), m_Int(other.m_Int)
21 Hmm(int i) : m_This(this), m_Int(i)
24 Hmm() : m_This(this), m_Int(0)
27 void operator = (const Hmm &other)
37 #define LIST_THIS_CHECK(lst, err) \
38 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter) \
39 CHECK_COND(&(*iter) == iter->m_This, err);
41 bool DoTestList(std::string &error)
43 typedef SourceHook::List<Hmm> ListType;
46 CHECK_COND(lst.empty(), "Part1");
48 for (int i = 1; i <= 100; ++i)
51 LIST_THIS_CHECK(lst, "PartA1");
53 CHECK_COND(!lst.empty(), "Part2");
57 CHECK_COND(lst.empty(), "Part3");
59 for (int i = 1; i <= 100; ++i)
62 CHECK_COND(lst.back() == 100, "Part4");
63 LIST_THIS_CHECK(lst, "PartA2");
66 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
67 CHECK_COND(*iter == ver++, "Part5");
69 CHECK_COND(ver == 101, "Part 6");
71 ListType::iterator iter50 = lst.find(50);
72 CHECK_COND(*iter50 == 50, "Part7");
74 iter50 = lst.erase(iter50);
75 CHECK_COND(*iter50 == 51, "Part8");
76 CHECK_COND(*--iter50 == 49, "Part8.2");
81 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
83 CHECK_COND(*iter == ver++, "Part9");
84 if (ver == 50 || ver == 80)
87 CHECK_COND(ver == 101, "Part10");
88 LIST_THIS_CHECK(lst, "PartA3");
92 CHECK_COND(lst.empty(), "Part11");
94 for (int i = 1; i <= 100; ++i)
97 CHECK_COND(lst2.size() == 100, "Part11.2");
99 LIST_THIS_CHECK(lst, "PartA4");
100 LIST_THIS_CHECK(lst2, "PartA5");
103 for (ListType::iterator iter = lst2.begin(); iter != lst2.end(); ++iter)
104 CHECK_COND(*iter == ver++, "Part12");
107 for (int i = 401; i <= 500; ++i)
110 CHECK_COND(lst2.size() == 100, "Part13");
113 for (ListType::iterator iter = lst.begin(); iter != lst.end(); ++iter)
114 CHECK_COND(*iter == ver++, "Part14");
116 LIST_THIS_CHECK(lst, "PartA6");
117 LIST_THIS_CHECK(lst2, "PartA7");
122 bool DoTestTinyHash(std::string &error)
124 const int mymax = 5000;
126 typedef SourceHook::THash<int, int> HashType;
129 for (int i = 1; i <= mymax; ++i)
132 for (int i = 1; i <= mymax; ++i)
133 CHECK_COND(hash[i] == i + 5000, "Part1");
137 for (HashType::iterator iter = hash.begin(); iter != hash.end(); ++iter)
138 CHECK_COND(iter->key == ver && iter->val == (ver++) + 5000, "Part2");
140 CHECK_COND(ver == mymax+1, "Part2.1");
142 HashType::iterator iter = hash.find(300);
143 CHECK_COND(iter != hash.end() && iter->val == 300+5000, "Part3.1");
144 iter = hash.find(mymax+200);
145 CHECK_COND(iter == hash.end(), "Part3.2");
148 for (int i = 1; i <= mymax; ++i)
155 bool TestList(std::string &error)
157 if (!DoTestList(error))
160 if (!DoTestTinyHash(error))