1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

AK: Add a new TestSuite.h from my own work, adapted to match the existing one a bit

This gives a few new features:

* benchmarks
* the ability to run individual testcases easily
* timing of tests
This commit is contained in:
Robin Burchell 2019-07-16 10:08:39 +02:00 committed by Andreas Kling
parent df3e295ba6
commit 41d2c674d7
8 changed files with 386 additions and 136 deletions

View file

@ -1,27 +1,46 @@
#include "TestHelpers.h"
#include <AK/TestSuite.h>
#include <AK/AKString.h>
#include <AK/HashMap.h>
typedef HashMap<int, int> IntIntMap;
int main()
TEST_CASE(construct)
{
typedef HashMap<int, int> IntIntMap;
EXPECT(IntIntMap().is_empty());
EXPECT(IntIntMap().size() == 0);
EXPECT_EQ(IntIntMap().size(), 0);
}
TEST_CASE(populate)
{
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.is_empty(), false);
EXPECT_EQ(number_to_string.size(), 3);
}
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");
int loop_counter = 0;
for (auto& it : number_to_string) {
EXPECT(!it.value.is_null());
EXPECT_EQ(it.value.is_null(), false);
++loop_counter;
}
EXPECT_EQ(loop_counter, 3);
}
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");
number_to_string.remove(1);
EXPECT_EQ(number_to_string.size(), 2);
@ -30,16 +49,16 @@ int main()
number_to_string.remove(3);
EXPECT_EQ(number_to_string.size(), 1);
EXPECT(number_to_string.find(3) == number_to_string.end());
EXPECT_EQ(loop_counter, 3);
{
HashMap<String, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(String("nickserv").to_lowercase(), String("NickServ").to_lowercase());
casemap.set("nickserv", 3);
casemap.set("NickServ", 3);
EXPECT_EQ(casemap.size(), 1);
}
return 0;
EXPECT(number_to_string.find(2) != number_to_string.end());
}
TEST_CASE(case_insensitive)
{
HashMap<String, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(String("nickserv").to_lowercase(), String("NickServ").to_lowercase());
casemap.set("nickserv", 3);
casemap.set("NickServ", 3);
EXPECT_EQ(casemap.size(), 1);
}
TEST_MAIN(HashMap)