Lolly 1.4.28
Loading...
Searching...
No Matches
hashset_test.cpp
Go to the documentation of this file.
1#include "a_lolly_test.hpp"
2#include "hashset.hpp"
3#include "string.hpp"
4
5TEST_CASE ("test contains") {
6 auto set= hashset<string> ();
7 set->insert ("Hello");
8 CHECK_EQ (set->contains ("Hello"), true);
9 CHECK_EQ (set->contains ("hello"), false);
10 auto empty= hashset<string> ();
11 CHECK_EQ (set->contains ("hello"), false);
12}
13
14TEST_CASE ("test init") {
15 auto set= hashset<string> ();
16 set << string ("hello") << string ("world");
17 CHECK_EQ (set->contains ("hello"), true);
18 CHECK_EQ (set->contains ("world"), true);
19 CHECK_EQ (N (set), 2);
20}
21
22TEST_CASE ("test remove") {
23 auto set1= hashset<string> ();
24 auto set2= hashset<string> ();
25 CHECK_EQ (N (set1), N (set2));
26 set1 << string ("aaa") << string ("bbb");
27 CHECK_EQ (N (set1), N (set2) + 2);
28 set2 << string ("aaa") << string ("bbb") << string ("ccc");
29 set2->remove (string ("bbb"));
30 CHECK_EQ (N (set1), N (set2));
31}
32
33TEST_CASE ("test operator <=") {
34 auto out= tm_ostream ();
35 auto set= hashset<string> ();
36 set << string ("aaa") << string ("bbb");
37 auto set1= hashset<string> ();
38 set1 << string ("aaa") << string ("bbb") << string ("ccc");
39 auto out1= tm_ostream ();
40 CHECK_EQ (set <= set1, true);
41}
42
43TEST_CASE ("test copy") {
45 set1 << string ("a") << string ("b") << string ("c");
46 set2= copy (set1);
47 CHECK_EQ (set2->contains (string ("a")), true);
48 CHECK_EQ (set2->contains (string ("b")), true);
49 CHECK_EQ (set2->contains (string ("c")), true);
50 CHECK_EQ (N (set1) == N (set2), true);
51 // Test utf-8 for Chinese
52 set1 << string ("你好") << string ("世界");
53 set2= copy (set1);
54 CHECK_EQ (set2->contains (string ("你好")), true);
55 CHECK_EQ (set2->contains (string ("世界")), true);
56}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
int copy(int x)
Returns a copy of an integer.
Definition basic.hpp:249
The list class represents a linked list.
Definition list.hpp:48
TEST_CASE("test for operator+= and advance()")