diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp index 2e3ddc55825..4f5aa422b56 100644 --- a/Tests/AK/TestHashTable.cpp +++ b/Tests/AK/TestHashTable.cpp @@ -7,6 +7,7 @@ #include #include +#include #include TEST_CASE(construct) @@ -235,6 +236,26 @@ TEST_CASE(capacity_leak) EXPECT(table.capacity() < 100u); } +TEST_CASE(non_trivial_type_table) +{ + HashTable> table; + + table.set(make(3)); + table.set(make(11)); + + for (int i = 0; i < 1'000; ++i) { + table.set(make(-i)); + } + for (int i = 0; i < 10'000; ++i) { + table.set(make(i)); + table.remove(make(i)); + } + + EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), true); + EXPECT(table.is_empty()); + EXPECT_EQ(table.remove_all_matching([&](auto&) { return true; }), false); +} + // Inserting and removing a bunch of elements will "thrash" the table, leading to a lot of "deleted" markers. BENCHMARK_CASE(benchmark_thrashing) {