mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
49d29c8298
commit
8dc24d0256
Notes:
sideshowbarker
2024-07-17 16:26:08 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/8dc24d0256 Pull-request: https://github.com/SerenityOS/serenity/pull/12937 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/davidot
1 changed files with 21 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
TEST_CASE(construct)
|
||||
|
@ -235,6 +236,26 @@ TEST_CASE(capacity_leak)
|
|||
EXPECT(table.capacity() < 100u);
|
||||
}
|
||||
|
||||
TEST_CASE(non_trivial_type_table)
|
||||
{
|
||||
HashTable<NonnullOwnPtr<int>> table;
|
||||
|
||||
table.set(make<int>(3));
|
||||
table.set(make<int>(11));
|
||||
|
||||
for (int i = 0; i < 1'000; ++i) {
|
||||
table.set(make<int>(-i));
|
||||
}
|
||||
for (int i = 0; i < 10'000; ++i) {
|
||||
table.set(make<int>(i));
|
||||
table.remove(make<int>(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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue