123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "../Tests.hpp"
- #include "core/data/HashMap.hpp"
- #include "core/utils/HashedString.hpp"
- template class Core::HashedString<32>;
- using HString = Core::HashedString<32>;
- static void testComparison() {
- HString a("test");
- HString b("testA");
- HString c("");
- HString d("Btest");
- CORE_TEST_TRUE(a == a);
- CORE_TEST_TRUE(b == b);
- CORE_TEST_TRUE(c == c);
- CORE_TEST_TRUE(d == d);
- CORE_TEST_TRUE(a != b);
- CORE_TEST_TRUE(a != c);
- CORE_TEST_TRUE(a != d);
- CORE_TEST_TRUE(b != a);
- CORE_TEST_TRUE(b != c);
- CORE_TEST_TRUE(b != d);
- CORE_TEST_TRUE(c != a);
- CORE_TEST_TRUE(c != b);
- CORE_TEST_TRUE(c != d);
- CORE_TEST_TRUE(d != a);
- CORE_TEST_TRUE(d != b);
- CORE_TEST_TRUE(d != c);
- }
- static void testLength() {
- HString s("test");
- CORE_TEST_EQUAL(4, s.getLength());
- CORE_TEST_EQUAL(31, s.getCapacity());
- }
- static void testHashCode() {
- HString a;
- HString b("wusi");
- CORE_TEST_EQUAL(a.hashCode(), 0lu);
- CORE_TEST_TRUE(b.hashCode() != 0u);
- }
- static void testAsHashMapKey() {
- Core::HashMap<HString, int> map;
- map.add("wusi", 3).add("hiThere", 7).add("baum123", 5);
- int* a = map.search("wusi");
- int* b = map.search("hiThere");
- int* c = map.search("baum123");
- int* d = map.search("423hifd");
- CORE_TEST_NOT_NULL(a);
- CORE_TEST_NOT_NULL(b);
- CORE_TEST_NOT_NULL(c);
- CORE_TEST_NULL(d);
- if(a != nullptr && b != nullptr && c != nullptr) {
- CORE_TEST_EQUAL(3, *a);
- CORE_TEST_EQUAL(7, *b);
- CORE_TEST_EQUAL(5, *c);
- }
- }
- void Core::testHashedString() {
- testComparison();
- testLength();
- testHashCode();
- testAsHashMapKey();
- }
|