Lolly
1.4.28
Loading...
Searching...
No Matches
tests
Kernel
Containers
iterator_test.cpp
Go to the documentation of this file.
1
#include "
a_lolly_test.hpp
"
2
#include "
iterator.hpp
"
3
#include "
string.hpp
"
4
5
TEST_CASE
(
"iterate on empty object"
) {
6
7
SUBCASE
(
"test empty hashset"
) {
8
hashset<int>
set
;
9
iterator<int>
it
=
iterate
(
set
);
10
CHECK
(!
it
->busy ());
11
}
12
13
SUBCASE
(
"test empty hashmap"
) {
14
hashmap<int, int>
map
;
15
iterator<int>
it
=
iterate
(
map
);
16
CHECK
(!
it
->busy ());
17
}
18
}
19
20
TEST_CASE
(
"iterate on hashset"
) {
21
hashset<int>
set
;
22
set
->insert (1);
23
set
->insert (2);
24
hashset<string>
set1
;
25
set1
->insert (
string
(
"string1"
));
26
set1
->insert (
string
(
"string2"
));
27
SUBCASE
(
"Test iterator busy"
) {
28
iterator<int>
it
=
iterate
(
set
);
29
iterator<string>
it1
=
iterate
(
set1
);
30
CHECK
(
it
->busy ());
31
CHECK
(
it1
->busy ());
32
}
33
SUBCASE
(
"Test iterator remains"
) {
34
iterator<int>
it
=
iterate
(
set
);
35
iterator<string>
it1
=
iterate
(
set1
);
36
CHECK
(
it
->remains () == -1);
37
CHECK
(
it1
->remains () == -1);
38
}
39
SUBCASE
(
"Test iterator next"
) {
40
iterator<int>
it
=
iterate
(
set
);
41
iterator<string>
it1
=
iterate
(
set1
);
42
CHECK
(
it
->next ());
43
CHECK_EQ
(
it1
->next () ==
string
(
"string1"
),
true
);
44
}
45
}
46
47
TEST_CASE
(
"iterate on hashmap"
) {
48
hashmap<int, int>
h;
49
h (1) = 1;
50
h (2) = 4;
51
h (3) = 6;
52
iterator<int>
it
=
iterate
(h);
53
auto
a =
string
();
54
while
(
it
->busy ()) {
55
a= a *
as_string
(
it
->next ());
56
}
57
CHECK_EQ
(a ==
string
(
"123"
),
true
);
58
}
59
60
TEST_CASE
(
"ranged for on hashmap"
) {
61
SUBCASE
(
"ordinary"
) {
62
hashmap<int, int>
h;
63
h (1)= 1;
64
h (2)= 4;
65
h (3)= 6;
66
string
a;
67
for
(
auto
i :
iterate
(h)) {
68
a= a *
as_string
(i);
69
}
70
string_eq
(a,
"123"
);
71
};
72
SUBCASE
(
"empty"
) {
73
hashmap<int, int>
h;
74
string
a;
75
for
(
auto
i :
iterate
(h)) {
76
a= a *
as_string
(i);
77
}
78
string_eq
(a,
""
);
79
};
80
}
81
82
TEST_CASE
(
"iterate on hashset"
) {
83
hashset<int>
h;
84
h->insert (1);
85
h->insert (2);
86
h->insert (3);
87
iterator<int>
it
=
iterate
(h);
88
string
a (
""
);
89
while
(
it
->busy ()) {
90
a <<
as_string
(
it
->next ());
91
}
92
CHECK_EQ
(a ==
string
(
"123"
),
true
);
93
}
94
95
TEST_CASE
(
"ranged for on hashset"
) {
96
SUBCASE
(
"ordinary"
) {
97
hashset<int>
h;
98
h->insert (1);
99
h->insert (2);
100
h->insert (3);
101
string
a;
102
for
(
auto
i :
iterate
(h)) {
103
a <<
as_string
(i);
104
}
105
string_eq
(a,
"123"
);
106
};
107
SUBCASE
(
"empty"
) {
108
hashset<int>
h;
109
string
a;
110
for
(
auto
i :
iterate
(h)) {
111
a= a *
as_string
(i);
112
}
113
string_eq
(a,
""
);
114
}
115
}
a_lolly_test.hpp
list
The list class represents a linked list.
Definition
list.hpp:48
string
Definition
string.hpp:40
iterator.hpp
iterate
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition
iterator.ipp:166
string_eq
void string_eq(string left, string right)
Definition
lolly_doctests.hpp:14
TEST_CASE
TEST_CASE("test for operator+= and advance()")
Definition
parse_string_test.cpp:85
as_string
string as_string(int16_t i)
Definition
string.cpp:272
string.hpp
Generated by
1.10.0