Lolly 1.4.27
Loading...
Searching...
No Matches
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
5TEST_CASE ("iterate on empty object") {
6
7 SUBCASE ("test empty hashset") {
10 CHECK (!it->busy ());
11 }
12
13 SUBCASE ("test empty hashmap") {
16 CHECK (!it->busy ());
17 }
18}
19
20TEST_CASE ("iterate on hashset") {
22 set->insert (1);
23 set->insert (2);
25 set1->insert (string ("string1"));
26 set1->insert (string ("string2"));
27 SUBCASE ("Test iterator busy") {
30 CHECK (it->busy ());
31 CHECK (it1->busy ());
32 }
33 SUBCASE ("Test iterator remains") {
36 CHECK (it->remains () == -1);
37 CHECK (it1->remains () == -1);
38 }
39 SUBCASE ("Test iterator next") {
42 CHECK (it->next ());
43 CHECK_EQ (it1->next () == string ("string1"), true);
44 }
45}
46
47TEST_CASE ("iterate on hashmap") {
49 h (1) = 1;
50 h (2) = 4;
51 h (3) = 6;
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
60TEST_CASE ("ranged for on hashmap") {
61 SUBCASE ("ordinary") {
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") {
74 string a;
75 for (auto i : iterate (h)) {
76 a= a * as_string (i);
77 }
78 string_eq (a, "");
79 };
80}
81
82TEST_CASE ("iterate on hashset") {
84 h->insert (1);
85 h->insert (2);
86 h->insert (3);
88 string a ("");
89 while (it->busy ()) {
90 a << as_string (it->next ());
91 }
92 CHECK_EQ (a == string ("123"), true);
93}
94
95TEST_CASE ("ranged for on hashset") {
96 SUBCASE ("ordinary") {
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}
The list class represents a linked list.
Definition list.hpp:48
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition iterator.ipp:166
void string_eq(string left, string right)
TEST_CASE("test for operator+= and advance()")
string as_string(int16_t i)
Definition string.cpp:310