diff options
author | Andreas Kling <kling@serenityos.org> | 2022-04-10 12:27:08 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-10 12:39:44 +0200 |
commit | ae6b09f4dcea65e4ba0e9bb70d7c0322bab958a6 (patch) | |
tree | 4daeabc71930387cceca67fc9c1c932a119e7255 /Tests | |
parent | 69ca27d3d7868ca2e19153b636455e2e8fbfada1 (diff) | |
download | serenity-ae6b09f4dcea65e4ba0e9bb70d7c0322bab958a6.zip |
AK: Add hash traits for floating-point primitives
This allows us to use float and double as hash keys.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/TestHashTable.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp index 02c94c6b62..51e864cf4f 100644 --- a/Tests/AK/TestHashTable.cpp +++ b/Tests/AK/TestHashTable.cpp @@ -256,6 +256,30 @@ TEST_CASE(non_trivial_type_table) EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), false); } +TEST_CASE(floats) +{ + HashTable<float> table; + table.set(0); + table.set(1.0f); + table.set(2.0f); + EXPECT_EQ(table.size(), 3u); + EXPECT(table.contains(0)); + EXPECT(table.contains(1.0f)); + EXPECT(table.contains(2.0f)); +} + +TEST_CASE(doubles) +{ + HashTable<double> table; + table.set(0); + table.set(1.0); + table.set(2.0); + EXPECT_EQ(table.size(), 3u); + EXPECT(table.contains(0)); + EXPECT(table.contains(1.0)); + EXPECT(table.contains(2.0)); +} + // Inserting and removing a bunch of elements will "thrash" the table, leading to a lot of "deleted" markers. BENCHMARK_CASE(benchmark_thrashing) { |