openMSX
SimpleHashSet_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2
3#include "SimpleHashSet.hh"
4
5
6TEST_CASE("SimpleHashSet")
7{
8 // construct
9 SimpleHashSet<-1, std::hash<int>, std::equal_to<>> s;
10 CHECK(s.capacity() == 0);
11 CHECK(s.size() == 0);
12 CHECK(s.empty());
13
14 // insert 42
15 CHECK(!s.contains(42));
16 CHECK(!s.find(42));
17 CHECK(s.insert(42)); // {42}
18 CHECK(s.contains(42));
19 CHECK(*(s.find(42)) == 42);
20 CHECK(s.capacity() == 2);
21 CHECK(s.size() == 1);
22 CHECK(!s.empty());
23
24 // reserve
25 s.reserve(4);
26 CHECK(s.capacity() == 4);
27 CHECK(s.size() == 1);
28
29 // insert 42 again
30 CHECK(!s.insert(42)); // {42}
31 CHECK(s.contains(42));
32 CHECK(*(s.find(42)) == 42);
33 CHECK(s.capacity() == 4);
34 CHECK(s.size() == 1);
35
36 // insert 1, 2, 3
37 CHECK(s.insert(1));
38 CHECK(s.insert(2));
39 CHECK(s.insert(3)); // {1, 2, 3, 42}
40 CHECK(*s.find(42) == 42);
41 CHECK(*s.find(1) == 1);
42 CHECK(*s.find(2) == 2);
43 CHECK(*s.find(3) == 3);
44 CHECK(!s.find(4));
45 CHECK(!s.find(5));
46 CHECK(s.size() == 4);
47 CHECK(s.capacity() == 4);
48
49 // insert 10, must grow
50 CHECK(s.insert(10)); // {1, 2, 3, 10, 42}
51 CHECK(*s.find(42) == 42);
52 CHECK(*s.find(1) == 1);
53 CHECK(*s.find(2) == 2);
54 CHECK(*s.find(3) == 3);
55 CHECK(!s.find(4));
56 CHECK(!s.find(5));
57 CHECK(*s.find(10) == 10);
58 CHECK(s.size() == 5);
59 CHECK(s.capacity() == 8);
60
61 // erase non-existing
62 CHECK(!s.erase(99));
63 CHECK(s.size() == 5);
64
65 // erase 1, 3
66 CHECK(s.erase(1));
67 CHECK(s.erase(3)); // {2, 10, 42}
68 CHECK(*s.find(42) == 42);
69 CHECK(!s.find(1));
70 CHECK(*s.find(2) == 2);
71 CHECK(!s.find(3));
72 CHECK(!s.find(4));
73 CHECK(!s.find(5));
74 CHECK(*s.find(10) == 10);
75 CHECK(s.size() == 3);
76 CHECK(s.capacity() == 8);
77}
TEST_CASE("SimpleHashSet")
CHECK(m3==m3)