@@ -10,162 +10,138 @@ GTEST_TEST(hashmap, find_in_empty_hashmap)
1010GTEST_TEST (hashmap, find_in_hashmap_trivial_type)
1111{
1212
13- hud_test::for_each_value (std::make_integer_sequence<usize, 128 >(), []<usize maxx>()
14- {
15- const auto test = [](usize max)
16- {
17- using KeyType = usize;
18- using ValueType = usize;
19- hud::hashmap<KeyType, ValueType> map;
20-
21- for (u32 index = 0 ; index < max; index++)
22- {
23- map.add (index, index * index);
24- }
25-
26- bool is_find_ok = true ;
27- // Find elements that exists
28- for (u32 index = 0 ; index < max; index++)
29- {
30- const auto it = map.find (index);
31- if (it == map.end ())
32- {
33- is_find_ok = false ;
34- }
35- if (it->key () != index)
36- {
37- is_find_ok = false ;
38- }
39- if (it->value () != index * index)
40- {
41- is_find_ok = false ;
42- }
43- }
44-
45- // Find elements that not exists
46- for (u32 index = max; index < max * 2 ; index++)
47- {
48- const auto it = map.find (index);
49- if (it != map.end ())
50- {
51- is_find_ok = false ;
52- }
53- }
54- return is_find_ok;
55- };
56-
57- // Non constant
58- {
59- const auto result = test (maxx);
60- hud_assert_true (result);
13+ const auto test = [](usize max) {
14+ using KeyType = usize;
15+ using ValueType = usize;
16+ hud::hashmap<KeyType, ValueType> map;
17+
18+ for (u32 index = 0 ; index < max; index++) {
19+ map.add (index, index * index);
20+ }
21+
22+ bool is_find_ok = true ;
23+ // Find elements that exists
24+ for (u32 index = 0 ; index < max; index++) {
25+ const auto it = map.find (index);
26+ if (it == map.end ()) {
27+ is_find_ok = false ;
6128 }
29+ if (it->key () != index) {
30+ is_find_ok = false ;
31+ }
32+ if (it->value () != index * index) {
33+ is_find_ok = false ;
34+ }
35+ }
6236
63- // Constant
64- {
65- constexpr auto result = test (maxx);
66- hud_assert_true (result);
67- } });
37+ // Find elements that not exists
38+ for (u32 index = max; index < max * 2 ; index++) {
39+ const auto it = map.find (index);
40+ if (it != map.end ()) {
41+ is_find_ok = false ;
42+ }
43+ }
44+ return is_find_ok;
45+ };
46+
47+ // Non constant
48+ {
49+ const auto result = test (32768 );
50+ hud_assert_true (result);
51+ }
52+
53+ // Constant
54+ {
55+ hud_test::for_each_value (std::make_integer_sequence<usize, 2 >(), []<usize maxx>() {
56+ constexpr auto result = test (maxx);
57+ hud_assert_true (result);
58+ });
59+ }
6860}
6961
7062GTEST_TEST (hashmap, find_in_hashmap_non_trivial_type)
7163{
72- hud_test::for_each_value (std::make_integer_sequence<usize, 128 >(), []<usize maxx>()
73- {
74- const auto test_1 = [](usize max)
75- {
76- using KeyType = hud_test::non_bitwise_type;
77- using ValueType = hud_test::non_bitwise_type;
78- hud::hashmap<KeyType, ValueType> map;
79- for (u32 index = 0 ; index < max; index++)
80- {
81- map.add (index, index * index);
82- }
83-
84- bool is_find_ok = true ;
85- // Find elements that exists
86- for (u32 index = 0 ; index < max; index++)
87- {
88- const auto it = map.find (index);
89- if (it == map.end ())
90- {
91- is_find_ok = false ;
92- }
93- if (it->key () != index)
94- {
95- is_find_ok = false ;
96- }
97- if (it->value () != index * index)
98- {
99- is_find_ok = false ;
100- }
101- }
102-
103- // Find elements that not exists
104- for (u32 index = max; index < max * 2 ; index++)
105- {
106- const auto it = map.find (index);
107- if (it != map.end ())
108- {
109- is_find_ok = false ;
110- }
111- }
112- return is_find_ok;
113- };
114-
115- const auto test_2 = [](usize max)
116- {
117- using KeyType = hud_test::non_bitwise_type;
118- using ValueType = hud_test::non_bitwise_type;
119- hud::hashmap<KeyType, ValueType> map;
120- for (u32 index = 0 ; index < max; index++)
121- {
122- map.add (index, index * index);
123- }
124-
125- bool is_find_ok = true ;
126- // Find elements that exists
127- for (u32 index = 0 ; index < max; index++)
128- {
129- const auto it = map.find (KeyType (index));
130- if (it == map.end ())
131- {
132- is_find_ok = false ;
133- }
134- if (it->key () != index)
135- {
136- is_find_ok = false ;
137- }
138- if (it->value () != index * index)
139- {
140- is_find_ok = false ;
141- }
142- }
143-
144- // Find elements that not exists
145- for (u32 index = max; index < max * 2 ; index++)
146- {
147- const auto it = map.find (KeyType (index));
148- if (it != map.end ())
149- {
150- is_find_ok = false ;
151- }
152- }
153- return is_find_ok;
154- };
155-
156- // Non constant
157- {
158- const auto result = test_1 (maxx);
159- hud_assert_true (result);
160- auto result_2 = test_2 (maxx);
161- hud_assert_true (result_2);
64+ const auto test_1 = [](usize max) {
65+ using KeyType = hud_test::non_bitwise_type;
66+ using ValueType = hud_test::non_bitwise_type;
67+ hud::hashmap<KeyType, ValueType> map;
68+ for (u32 index = 0 ; index < max; index++) {
69+ map.add (index, index * index);
70+ }
71+
72+ bool is_find_ok = true ;
73+ // Find elements that exists
74+ for (u32 index = 0 ; index < max; index++) {
75+ const auto it = map.find (index);
76+ if (it == map.end ()) {
77+ is_find_ok = false ;
16278 }
79+ if (it->key () != index) {
80+ is_find_ok = false ;
81+ }
82+ if (it->value () != index * index) {
83+ is_find_ok = false ;
84+ }
85+ }
16386
164- // Constant
165- {
166- constexpr auto result = test_1 (maxx);
167- hud_assert_true (result);
168- constexpr auto result_2 = test_2 (maxx);
169- hud_assert_true (result_2);
170- } });
87+ // Find elements that not exists
88+ for (u32 index = max; index < max * 2 ; index++) {
89+ const auto it = map.find (index);
90+ if (it != map.end ()) {
91+ is_find_ok = false ;
92+ }
93+ }
94+ return is_find_ok;
95+ };
96+
97+ const auto test_2 = [](usize max) {
98+ using KeyType = hud_test::non_bitwise_type;
99+ using ValueType = hud_test::non_bitwise_type;
100+ hud::hashmap<KeyType, ValueType> map;
101+ for (u32 index = 0 ; index < max; index++) {
102+ map.add (index, index * index);
103+ }
104+
105+ bool is_find_ok = true ;
106+ // Find elements that exists
107+ for (u32 index = 0 ; index < max; index++) {
108+ const auto it = map.find (KeyType (index));
109+ if (it == map.end ()) {
110+ is_find_ok = false ;
111+ }
112+ if (it->key () != index) {
113+ is_find_ok = false ;
114+ }
115+ if (it->value () != index * index) {
116+ is_find_ok = false ;
117+ }
118+ }
119+
120+ // Find elements that not exists
121+ for (u32 index = max; index < max * 2 ; index++) {
122+ const auto it = map.find (KeyType (index));
123+ if (it != map.end ()) {
124+ is_find_ok = false ;
125+ }
126+ }
127+ return is_find_ok;
128+ };
129+
130+ // Non constant
131+ {
132+ const auto result = test_1 (32768 );
133+ hud_assert_true (result);
134+ const auto result_2 = test_2 (maxx);
135+ hud_assert_true (result_2);
136+ }
137+
138+ // Constant
139+ {
140+ hud_test::for_each_value (std::make_integer_sequence<usize, 2 >(), []<usize maxx>() {
141+ constexpr auto result = test_1 (maxx);
142+ hud_assert_true (result);
143+ constexpr auto result_2 = test_2 (maxx);
144+ hud_assert_true (result_2);
145+ });
146+ }
171147}
0 commit comments