Lolly 1.4.27
Loading...
Searching...
No Matches
Functions
iterator_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "iterator.hpp"
#include "string.hpp"
Include dependency graph for iterator_test.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("iterate on empty object")
 
 TEST_CASE ("iterate on hashset")
 
 TEST_CASE ("iterate on hashmap")
 
 TEST_CASE ("ranged for on hashmap")
 
 TEST_CASE ("ranged for on hashset")
 

Function Documentation

◆ TEST_CASE() [1/5]

TEST_CASE ( "iterate on empty object" )

Definition at line 5 of file iterator_test.cpp.

5 {
6
7 SUBCASE ("test empty hashset") {
10 CHECK (!it->busy ());
11 }
12
13 SUBCASE ("test empty hashmap") {
16 CHECK (!it->busy ());
17 }
18}
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

◆ TEST_CASE() [2/5]

TEST_CASE ( "iterate on hashset" )

Definition at line 20 of file iterator_test.cpp.

20 {
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}

◆ TEST_CASE() [3/5]

TEST_CASE ( "iterate on hashmap" )

Definition at line 47 of file iterator_test.cpp.

47 {
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}
string as_string(int16_t i)
Definition string.cpp:310

◆ TEST_CASE() [4/5]

TEST_CASE ( "ranged for on hashmap" )

Definition at line 60 of file iterator_test.cpp.

60 {
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}
void string_eq(string left, string right)

◆ TEST_CASE() [5/5]

TEST_CASE ( "ranged for on hashset" )

Definition at line 95 of file iterator_test.cpp.

95 {
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}