Lolly 1.4.28
Loading...
Searching...
No Matches
Functions | Variables
hashmap_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "hashmap.hpp"
#include <string>
Include dependency graph for hashmap_test.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("test_resize")
 
 TEST_CASE ("test reset")
 
void routine (int key)
 
 TEST_CASE ("test generate")
 
 TEST_CASE ("test contains")
 
 TEST_CASE ("test empty")
 
 TEST_CASE ("test join")
 
 TEST_CASE ("test write back")
 
 TEST_CASE ("test pre patch")
 
 TEST_CASE ("test post patch")
 
 TEST_CASE ("test copy")
 
 TEST_CASE ("test equality")
 
 TEST_CASE ("test changes")
 
 TEST_CASE ("test invert")
 
 TEST_CASE ("test size")
 
 TEST_CASE ("hashmap default")
 

Variables

auto hm_generate = hashmap<int, int> (0, 10)
 

Function Documentation

◆ TEST_CASE() [1/15]

TEST_CASE ( "test_resize" )

Definition at line 5 of file hashmap_test.cpp.

5 {
6 auto hm= hashmap<int, int> (0, 10);
7 hm (1) = 10;
8 hm (2) = 20;
9
10 hm->resize (1);
11 CHECK_EQ (hm[1] == 10, true);
12 CHECK_EQ (hm[2] == 20, true);
13
14 hm->resize (20);
15 CHECK_EQ (hm[1] == 10, true);
16 CHECK_EQ (hm[2] == 20, true);
17}
The list class represents a linked list.
Definition list.hpp:48

◆ TEST_CASE() [2/15]

TEST_CASE ( "test reset" )

Definition at line 19 of file hashmap_test.cpp.

19 {
20 auto hm= hashmap<int, int> (0, 10);
21 hm (1) = 10;
22 hm (11)= 20;
23 hm->reset (1);
24
25 CHECK_EQ (hm->contains (1), false);
26 CHECK_EQ (hm->contains (11), true);
27}

◆ routine()

void routine ( int key)

Definition at line 31 of file hashmap_test.cpp.

31 {
32 CHECK_EQ (hm_generate->contains (key), true);
33}
auto hm_generate

◆ TEST_CASE() [3/15]

TEST_CASE ( "test generate" )

Definition at line 35 of file hashmap_test.cpp.

35 {
36 hm_generate (1)= 10;
37 hm_generate (2)= 20;
38 hm_generate->generate (routine);
39}
void routine(int key)

◆ TEST_CASE() [4/15]

TEST_CASE ( "test contains" )

Definition at line 41 of file hashmap_test.cpp.

41 {
42 auto hm= hashmap<int, void*> (nullptr, 2, 2);
43 hm (1) = nullptr;
44 CHECK_EQ (hm->contains (1), true);
45 CHECK_EQ (hm->contains (3), false);
46}

◆ TEST_CASE() [5/15]

TEST_CASE ( "test empty" )

Definition at line 48 of file hashmap_test.cpp.

48 {
49 auto hm= hashmap<int, int> ();
50 CHECK_EQ (hm->empty (), true);
51
52 hm (1);
53 CHECK_EQ (hm->empty (), false);
54}

◆ TEST_CASE() [6/15]

TEST_CASE ( "test join" )

Definition at line 56 of file hashmap_test.cpp.

56 {
57 auto hm1= hashmap<int, int> ();
58 auto hm2= hashmap<int, int> ();
59 hm1 (1) = 10;
60 hm1 (2) = 20;
61 hm2 (2) = -20;
62 hm2 (3) = -30;
63 hm1->join (hm2);
64
65 CHECK_EQ (hm1[1] == 10, true);
66 CHECK_EQ (hm1[2] == -20, true);
67 CHECK_EQ (hm1[3] == -30, true);
68}

◆ TEST_CASE() [7/15]

TEST_CASE ( "test write back" )

Definition at line 70 of file hashmap_test.cpp.

70 {
71 auto hm1= hashmap<int, int> (0, 10);
72 auto hm2= hashmap<int, int> (0, 10);
73 hm1 (1) = 10;
74 hm1 (2) = 20;
75 hm2 (2) = -20;
76
77 hm1->write_back (2, hm2);
78 CHECK_EQ (hm1[2] == 20, true);
79
80 hm1->write_back (3, hm2);
81 CHECK_EQ (hm1[3] == 0, true);
82
83 hm2 (4)= -40;
84 hm1->write_back (4, hm2);
85 CHECK_EQ (hm2[4] == -40, true);
86}

◆ TEST_CASE() [8/15]

TEST_CASE ( "test pre patch" )

Definition at line 88 of file hashmap_test.cpp.

88 {
89 auto hm = hashmap<int, int> ();
91 auto hm_base = hashmap<int, int> ();
92
93 hm (1)= 10;
94 hm_patch (1);
95 hm->pre_patch (hm_patch, hm_base);
96 CHECK_EQ (hm[1] == 10, true);
97
98 hm (2) = 20;
99 hm_patch (2)= -20;
100 hm_base (2) = 20;
101 hm->pre_patch (hm_patch, hm_base);
102 CHECK_EQ (hm[2] == 0, true);
103
104 hm_patch (3)= -30;
105 hm->pre_patch (hm_patch, hm_base);
106 CHECK_EQ (hm[3] == -30, true);
107}

◆ TEST_CASE() [9/15]

TEST_CASE ( "test post patch" )

Definition at line 109 of file hashmap_test.cpp.

109 {
110 auto hm = hashmap<int, int> ();
112 auto hm_base = hashmap<int, int> ();
113
114 hm (1)= 10;
115 hm_patch (1);
116 hm->post_patch (hm_patch, hm_base);
117 CHECK_EQ (hm[1] == 0, true);
118
119 hm_patch (2)= -20;
120 hm->pre_patch (hm_patch, hm_base);
121 CHECK_EQ (hm[2] == -20, true);
122}

◆ TEST_CASE() [10/15]

TEST_CASE ( "test copy" )

Definition at line 124 of file hashmap_test.cpp.

124 {
125 auto hm = hashmap<int, int> ();
126 auto hm_c= hashmap<int, int> (0, 10, 2);
127 hm_c (1) = 10;
128 hm_c (11)= 110;
129 hm_c (2) = 20;
130
131 auto res_hm= copy (hm_c);
132 CHECK_EQ (res_hm[1] == 10, true);
133 CHECK_EQ (res_hm[11] == 110, true);
134 CHECK_EQ (res_hm[2] == 20, true);
135}
int copy(int x)
Returns a copy of an integer.
Definition basic.hpp:249

◆ TEST_CASE() [11/15]

TEST_CASE ( "test equality" )

Definition at line 137 of file hashmap_test.cpp.

137 {
138 auto hm1= hashmap<int, int> (0, 10, 3);
139 auto hm2= hashmap<int, int> (0, 100, 30);
140 hm1 (1) = 10;
141 hm2 (1) = 10;
142 CHECK_EQ (hm1 == hm2, true);
143
144 hm2 (2)= 20;
145 CHECK_EQ (hm1 != hm2, true);
146}

◆ TEST_CASE() [12/15]

TEST_CASE ( "test changes" )

Definition at line 148 of file hashmap_test.cpp.

148 {
149 auto base_m = hashmap<int, int> ();
150 auto patch_m= hashmap<int, int> ();
151 base_m (1) = 10;
152 base_m (2) = 20;
153 patch_m (2) = -20;
154 patch_m (3) = -30;
155 auto res = changes (patch_m, base_m);
156 CHECK_EQ (N (res) == 2, true);
157 CHECK_EQ (res[2] == -20, true);
158 CHECK_EQ (res[3] == -30, true);
159}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
hashmap< T, U > changes(hashmap< T, U > p, hashmap< T, U > b)
Creates a new hashmap containing entries that have changed in the 'patch' compared to 'base'.

◆ TEST_CASE() [13/15]

TEST_CASE ( "test invert" )

Definition at line 161 of file hashmap_test.cpp.

161 {
162 auto base_m = hashmap<int, int> ();
163 auto patch_m= hashmap<int, int> ();
164 base_m (1) = 10;
165 base_m (2) = 20;
166 patch_m (2) = -20;
167 patch_m (3) = -30;
168 auto res = invert (patch_m, base_m);
169 CHECK_EQ (N (res) == 2, true);
170 CHECK_EQ (res[2] == 20, true);
171 CHECK_EQ (res[3] == 0, true);
172}
hashmap< T, U > invert(hashmap< T, U > p, hashmap< T, U > b)
Creates a new hashmap containing entries that are different in the 'patch' compared to 'base',...

◆ TEST_CASE() [14/15]

TEST_CASE ( "test size" )

Definition at line 174 of file hashmap_test.cpp.

174 {
176 CHECK_EQ (N (empty_hm) == 0, true);
177
179 non_empty_hm (1) = nullptr;
180 CHECK_EQ (N (non_empty_hm) == 1, true);
181}

◆ TEST_CASE() [15/15]

TEST_CASE ( "hashmap default" )

Definition at line 183 of file hashmap_test.cpp.

183 {
184 // Create a hashmap object with integer keys and string values
185 hashmap<int, std::string> map ("default");
186 // Test the comparison operators
188 equal_map (1)= "one";
189 equal_map (2)= "two";
191 not_equal_map (1)= "one";
192 not_equal_map (2)= "three";
193 CHECK_EQ (map == equal_map, false);
195}

Variable Documentation

◆ hm_generate

auto hm_generate = hashmap<int, int> (0, 10)

Definition at line 29 of file hashmap_test.cpp.