From 8dc24d0256314265053a9e4b93d0542d14f8d8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Tue, 8 Mar 2022 00:43:21 +0100 Subject: [PATCH] Tests: Test non-trivial re-hashing in HashTable This caused a system-wide crash because of a previous bug relating to non-trivial types in HashTable. Therefore, check that such types actually work under various workloads. --- Tests/AK/TestHashTable.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tests/AK/TestHashTable.cpp b/Tests/AK/TestHashTable.cpp index 2e3ddc5582..4f5aa422b5 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) {