From 1c00f6ed444dab15430a955e41cf155049e3cec4 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 14 Jan 2025 00:01:55 +0100 Subject: Start work on hash_set --- asl/tests/hash_set_tests.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 asl/tests/hash_set_tests.cpp (limited to 'asl/tests') diff --git a/asl/tests/hash_set_tests.cpp b/asl/tests/hash_set_tests.cpp new file mode 100644 index 0000000..e8d744b --- /dev/null +++ b/asl/tests/hash_set_tests.cpp @@ -0,0 +1,59 @@ +#include "asl/hash_set.hpp" +#include "asl/testing/testing.hpp" +#include "asl/string.hpp" +#include "asl/string_view.hpp" + +ASL_TEST(empty) +{ + asl::hash_set set; + + ASL_TEST_EXPECT(set.size() == 0); + + for (int i = 0; i < 100; ++i) + { + ASL_TEST_EXPECT(!set.contains(i)); + } +} + +ASL_TEST(a_bunch_of_strings) +{ + asl::hash_set> set; + + set.insert("Hello, world!"); + ASL_TEST_EXPECT(set.size() == 1); + + set.insert("Hello, puppy!"); + ASL_TEST_EXPECT(set.size() == 2); + + set.insert("Hello, puppy!"); + ASL_TEST_EXPECT(set.size() == 2); + + ASL_TEST_EXPECT(set.contains("Hello, world!"_sv)); + ASL_TEST_EXPECT(set.contains("Hello, puppy!"_sv)); + ASL_TEST_EXPECT(!set.contains("Hello, Steven!"_sv)); + +} + +ASL_TEST(a_bunch_of_ints) +{ + asl::hash_set set; + + int count = 3000; + + for (int i = 0; i < count; ++i) + { + set.insert(i); + } + + ASL_TEST_EXPECT(set.size() == count); + + for (int i = 0; i < count * 2; ++i) + { + ASL_TEST_EXPECT(set.contains(i) == (i < count)); + } +} + +// @Todo Remove elements + +// @Todo Test destructors + -- cgit