#include "../Tests.hpp"
#include "core/HashMap.hpp"
#include "core/HashedString.hpp"
#include "core/Test.hpp"

template class Core::HashedString<32>;
using HString = Core::HashedString<32>;

static void testComparison() {
    HString a("test");
    TEST_STRING("test", static_cast<const char*>(a));
    HString b("testA");
    HString c("");
    HString d("Btest");

    TEST_TRUE(a == a);
    TEST_TRUE(b == b);
    TEST_TRUE(c == c);
    TEST_TRUE(d == d);
    TEST_TRUE(a != b);
    TEST_TRUE(a != c);
    TEST_TRUE(a != d);
    TEST_TRUE(b != a);
    TEST_TRUE(b != c);
    TEST_TRUE(b != d);
    TEST_TRUE(c != a);
    TEST_TRUE(c != b);
    TEST_TRUE(c != d);
    TEST_TRUE(d != a);
    TEST_TRUE(d != b);
    TEST_TRUE(d != c);
}

static void testLength() {
    HString s("test");
    TEST(4, s.getLength());
    TEST(31, s.getCapacity());
}

static void testHashCode() {
    HString a;
    HString b("wusi");
    TEST(a.hashCode(), 0lu);
    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");
    TEST_NULL(map.search("423hifd"));

    if(TEST_NOT_NULL(a) && TEST_NOT_NULL(b) && TEST_NOT_NULL(c)) {
        TEST(3, *a);
        TEST(7, *b);
        TEST(5, *c);
    }
}

void testHashedString() {
    testComparison();
    testLength();
    testHashCode();
    testAsHashMapKey();
}