diff options
author | Andreas Kling <kling@serenityos.org> | 2020-10-15 23:59:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-16 00:02:23 +0200 |
commit | 544f2f3c96f2bf3aaac1f407091a337874a2f50c (patch) | |
tree | b3492d213a0d76f9a4647a65f444500b09eb2df1 /AK | |
parent | 4e50079f3654a95f7296f8f632aa6aa92784678f (diff) | |
download | serenity-544f2f3c96f2bf3aaac1f407091a337874a2f50c.zip |
AK: Add some more checks to the HashMap test
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Tests/TestHashMap.cpp | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/AK/Tests/TestHashMap.cpp b/AK/Tests/TestHashMap.cpp index cb4ff4c3b2..4a77894f05 100644 --- a/AK/Tests/TestHashMap.cpp +++ b/AK/Tests/TestHashMap.cpp @@ -50,9 +50,9 @@ TEST_CASE(populate) TEST_CASE(range_loop) { HashMap<int, String> number_to_string; - number_to_string.set(1, "One"); - number_to_string.set(2, "Two"); - number_to_string.set(3, "Three"); + EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry); + EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry); + EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry); int loop_counter = 0; for (auto& it : number_to_string) { @@ -65,15 +65,15 @@ TEST_CASE(range_loop) TEST_CASE(map_remove) { HashMap<int, String> number_to_string; - number_to_string.set(1, "One"); - number_to_string.set(2, "Two"); - number_to_string.set(3, "Three"); + EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry); + EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry); + EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry); - number_to_string.remove(1); + EXPECT_EQ(number_to_string.remove(1), true); EXPECT_EQ(number_to_string.size(), 2u); EXPECT(number_to_string.find(1) == number_to_string.end()); - number_to_string.remove(3); + EXPECT_EQ(number_to_string.remove(3), true); EXPECT_EQ(number_to_string.size(), 1u); EXPECT(number_to_string.find(3) == number_to_string.end()); EXPECT(number_to_string.find(2) != number_to_string.end()); @@ -124,11 +124,62 @@ TEST_CASE(many_strings) { HashMap<String, int> strings; for (int i = 0; i < 999; ++i) { - strings.set(String::number(i), i); + EXPECT_EQ(strings.set(String::number(i), i), AK::HashSetResult::InsertedNewEntry); } + EXPECT_EQ(strings.size(), 999u); for (auto& it : strings) { EXPECT_EQ(it.key.to_int().value(), it.value); } + for (int i = 0; i < 999; ++i) { + EXPECT_EQ(strings.remove(String::number(i)), true); + } + EXPECT_EQ(strings.is_empty(), true); +} + +TEST_CASE(basic_remove) +{ + HashMap<int, int> map; + map.set(1, 10); + map.set(2, 20); + map.set(3, 30); + + EXPECT_EQ(map.remove(3), true); + EXPECT_EQ(map.remove(3), false); + EXPECT_EQ(map.size(), 2u); + + EXPECT_EQ(map.remove(1), true); + EXPECT_EQ(map.remove(1), false); + EXPECT_EQ(map.size(), 1u); + + EXPECT_EQ(map.remove(2), true); + EXPECT_EQ(map.remove(2), false); + EXPECT_EQ(map.size(), 0u); +} + +TEST_CASE(basic_contains) +{ + HashMap<int, int> map; + map.set(1, 10); + map.set(2, 20); + map.set(3, 30); + + EXPECT_EQ(map.contains(1), true); + EXPECT_EQ(map.contains(2), true); + EXPECT_EQ(map.contains(3), true); + EXPECT_EQ(map.contains(4), false); + + EXPECT_EQ(map.remove(3), true); + EXPECT_EQ(map.contains(3), false); + EXPECT_EQ(map.contains(1), true); + EXPECT_EQ(map.contains(2), true); + + EXPECT_EQ(map.remove(2), true); + EXPECT_EQ(map.contains(2), false); + EXPECT_EQ(map.contains(3), false); + EXPECT_EQ(map.contains(1), true); + + EXPECT_EQ(map.remove(1), true); + EXPECT_EQ(map.contains(1), false); } TEST_MAIN(HashMap) |