summaryrefslogtreecommitdiff
path: root/asl/tests/hash_tests.cpp
blob: d0df77aea436f208b3fc8a9936474f12e9afa06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "asl/testing/testing.hpp"
#include "asl/hash.hpp"
#include "asl/string_view.hpp"
#include "asl/string.hpp"

static_assert(asl::hashable<uint8_t>);
static_assert(asl::hashable<uint16_t>);
static_assert(asl::hashable<uint32_t>);
static_assert(asl::hashable<uint64_t>);
static_assert(asl::hashable<uint128_t>);

static_assert(asl::hashable<int8_t>);
static_assert(asl::hashable<int16_t>);
static_assert(asl::hashable<int32_t>);
static_assert(asl::hashable<int64_t>);

ASL_TEST(integers)
{
    uint64_t a = asl::hash_value<uint16_t>(45);
    uint64_t b = asl::hash_value<uint16_t>(45);
    uint64_t c = asl::hash_value<uint16_t>(46);
    uint64_t d = asl::hash_value<uint32_t>(45);

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

static_assert(asl::hashable<bool>);

ASL_TEST(bool)
{
    ASL_TEST_EXPECT(asl::hash_value(true) == asl::hash_value(true));
    ASL_TEST_EXPECT(asl::hash_value(false) == asl::hash_value(false));
    ASL_TEST_EXPECT(asl::hash_value(true) != asl::hash_value(false));
}

static_assert(asl::hashable<asl::string_view>);
static_assert(asl::hashable<asl::string<>>);

ASL_TEST(strings)
{
    ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value("hello"_sv));
    ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("hello "_sv));
    ASL_TEST_EXPECT(asl::hash_value("hello"_sv) != asl::hash_value("HELLO"_sv));
    
    ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) == asl::hash_value(asl::string("hello"_sv)));
    ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("hello "_sv)));
    ASL_TEST_EXPECT(asl::hash_value(asl::string("hello"_sv)) != asl::hash_value(asl::string("HELLO"_sv)));

    ASL_TEST_EXPECT(asl::hash_value("hello"_sv) == asl::hash_value(asl::string("hello"_sv)));
}

// @Todo span, buffer (add combine_contiguous (optimize uniquely_represented))
// @Todo enum classes
// @Todo option (optimize uniquely_represented + has_niche)
// @Todo status, status_or
// @Todo box