Lolly
1.4.28
Loading...
Searching...
No Matches
tests
Kernel
Containers
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
5
TEST_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
14
TEST_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
22
TEST_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
33
TEST_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
43
TEST_CASE
(
"test copy"
) {
44
auto
set1
=
hashset<string>
(),
set2
=
hashset<string>
();
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
}
a_lolly_test.hpp
N
int N(array< T > a)
Get the length of the array.
Definition
array.hpp:170
copy
int copy(int x)
Returns a copy of an integer.
Definition
basic.hpp:249
list
The list class represents a linked list.
Definition
list.hpp:48
string
Definition
string.hpp:40
tm_ostream
Definition
tm_ostream.hpp:36
hashset.hpp
TEST_CASE
TEST_CASE("test for operator+= and advance()")
Definition
parse_string_test.cpp:85
string.hpp
Generated by
1.10.0