Skip to content

Commit f7fa292

Browse files
committed
added tests for get_all_open_keys
1 parent ae2aba6 commit f7fa292

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/hashmaps/test_open_maps.f90

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ program test_open_maps
5353
call input_random_data( map, test_16, 'FNV-1', "16 byte words" )
5454
call test_inquire_data( map, test_16, 'FNV-1', "16 byte words" )
5555
call test_get_data( map, test_16, 'FNV-1', '16 byte words' )
56+
call test_get_all_keys( map, test_16, 'FNV-1', '16 byte words' )
5657
call report_rehash_times( map, fnv_1_hasher, 'FNV-1', '16 byte words' )
5758
call report_hash_statistics( map, 'FNV-1', '16 byte words' )
5859
call report_removal_times( map, test_16, 'FNV-1', '16 byte words' )
@@ -61,6 +62,7 @@ program test_open_maps
6162
call input_random_data( map, test_256, 'FNV-1', "256 byte words" )
6263
call test_inquire_data( map, test_256, 'FNV-1', "256 byte words" )
6364
call test_get_data( map, test_256, 'FNV-1', '256 byte words' )
65+
call test_get_all_keys( map, test_256, 'FNV-1', '256 byte words' )
6466
call report_rehash_times( map, fnv_1_hasher, 'FNV-1', '256 byte words' )
6567
call report_hash_statistics( map, 'FNV-1', '256 byte words' )
6668
call report_removal_times( map, test_256, 'FNV-1', '256 byte words' )
@@ -69,6 +71,7 @@ program test_open_maps
6971
call input_random_data( map, test_16, 'FNV-1A', "16 byte words" )
7072
call test_inquire_data( map, test_16, 'FNV-1A', "16 byte words" )
7173
call test_get_data( map, test_16, 'FNV-1A', '16 byte words' )
74+
call test_get_all_keys( map, test_16, 'FNV-1A', '16 byte words' )
7275
call report_rehash_times( map, fnv_1a_hasher, 'FNV-1', '16 byte words' )
7376
call report_hash_statistics( map, 'FNV-1A', '16 byte words' )
7477
call report_removal_times( map, test_16, 'FNV-1a', '16 byte words' )
@@ -77,6 +80,7 @@ program test_open_maps
7780
call input_random_data( map, test_256, 'FNV-1A', "256 byte words" )
7881
call test_inquire_data( map, test_256, 'FNV-1A', "256 byte words" )
7982
call test_get_data( map, test_256, 'FNV-1A', '256 byte words' )
83+
call test_get_all_keys( map, test_256, 'FNV-1A', '256 byte words' )
8084
call report_rehash_times( map, fnv_1_hasher, 'FNV-1A', '256 byte words' )
8185
call report_hash_statistics( map, 'FNV-1A', '256 byte words' )
8286
call report_removal_times( map, test_256, 'FNV-1A', '256 byte words' )
@@ -85,6 +89,7 @@ program test_open_maps
8589
call input_random_data( map, test_16, 'Seeded_Nmhash32', "16 byte words" )
8690
call test_inquire_data( map, test_16, 'Seeded_Nmhash32', "16 byte words" )
8791
call test_get_data( map, test_16, 'Seeded_Nmhash32', '16 byte words' )
92+
call test_get_all_keys( map, test_16, 'Seeded_Nmhash32', '16 byte words' )
8893
call report_rehash_times( map, seeded_nmhash32_hasher, 'Seeded_Nmhash32', &
8994
'16 byte words' )
9095
call report_hash_statistics( map, 'Seeded_Nmhash32', '16 byte words' )
@@ -95,6 +100,7 @@ program test_open_maps
95100
call input_random_data( map, test_256, 'Seeded_Nmhash32', "256 byte words" )
96101
call test_inquire_data( map, test_256, 'Seeded_Nmhash32', "256 byte words" )
97102
call test_get_data( map, test_256, 'Seeded_Nmhash32', '256 byte words' )
103+
call test_get_all_keys( map, test_256, 'Seeded_Nmhash32', '256 byte words' )
98104
call report_rehash_times( map, seeded_nmhash32_hasher, 'Seeded_Nmhash32', &
99105
'256 byte words' )
100106
call report_hash_statistics( map, 'Seeded_Nmhash32', '256 byte words' )
@@ -105,6 +111,7 @@ program test_open_maps
105111
call input_random_data( map, test_16, 'Seeded_Nmhash32x', "16 byte words" )
106112
call test_inquire_data( map, test_16, 'Seeded_Nmhash32x', "16 byte words" )
107113
call test_get_data( map, test_16, 'Seeded_Nmhash32x', '16 byte words' )
114+
call test_get_all_keys( map, test_16, 'Seeded_Nmhash32x', '16 byte words' )
108115
call report_rehash_times( map, seeded_nmhash32x_hasher, &
109116
'Seeded_Nmhash32x', '16 byte words' )
110117
call report_hash_statistics( map, 'Seeded_Nmhash32x', '16 byte words' )
@@ -117,6 +124,7 @@ program test_open_maps
117124
call test_inquire_data( map, test_256, 'Seeded_Nmhash32x', &
118125
"256 byte words" )
119126
call test_get_data( map, test_256, 'Seeded_Nmhash32x', '256 byte words' )
127+
call test_get_all_keys( map, test_256, 'Seeded_Nmhash32x', '256 byte words' )
120128
call report_rehash_times( map, seeded_nmhash32x_hasher, &
121129
'Seeded_Nmhash32x', '256 byte words' )
122130
call report_hash_statistics( map, 'Seeded_Nmhash32x', '256 byte words' )
@@ -127,6 +135,7 @@ program test_open_maps
127135
call input_random_data( map, test_16, 'Seeded_Water', "16 byte words" )
128136
call test_inquire_data( map, test_16, 'Seeded_Water', "16 byte words" )
129137
call test_get_data( map, test_16, 'Seeded_Water', '16 byte words' )
138+
call test_get_all_keys( map, test_16, 'Seeded_Water', '16 byte words' )
130139
call report_rehash_times( map, seeded_water_hasher, &
131140
'Seeded_Water', '16 byte words' )
132141
call report_hash_statistics( map, 'Seeded_Water', '16 byte words' )
@@ -139,6 +148,7 @@ program test_open_maps
139148
call test_inquire_data( map, test_256, 'Seeded_Water', &
140149
"256 byte words" )
141150
call test_get_data( map, test_256, 'Seeded_Water', '256 byte words' )
151+
call test_get_all_keys( map, test_256, 'Seeded_Water', '256 byte words' )
142152
call report_rehash_times( map, seeded_water_hasher, &
143153
'Seeded_Water', '256 byte words' )
144154
call report_hash_statistics( map, 'Seeded_Water', '256 byte words' )
@@ -228,6 +238,37 @@ subroutine test_get_data( map, test_block, hash_name, size_name )
228238
end subroutine test_get_data
229239

230240

241+
subroutine test_get_all_keys( map, test_block, hash_name, size_name )
242+
type(open_hashmap_type), intent(inout) :: map
243+
integer(int_index), intent(in) :: test_block
244+
character(*), intent(in) :: hash_name, size_name
245+
integer :: index2, key_idx
246+
type(key_type) :: key
247+
type(key_type), allocatable :: all_keys(:)
248+
real :: t1, t2, tdiff
249+
250+
call cpu_time(t1)
251+
call map % get_all_keys(all_keys)
252+
call cpu_time(t2)
253+
tdiff = t2-t1
254+
255+
if (size( all_keys ) /= size( test_8_bits )/test_block) &
256+
error stop "Number of keys is different from that of keys in a map."
257+
258+
do index2=1, size(test_8_bits), test_block
259+
call set( key, test_8_bits( index2:index2+test_block-1 ) )
260+
261+
key_idx = ( index2/test_block ) + 1
262+
if (.not. ( all_keys(key_idx) == key )) &
263+
error stop "Invalid value of a key."
264+
end do
265+
266+
write(lun, '("|", a18, " | ", a12, " | ", a15, " | ", f10.5, " |")') &
267+
trim(hash_name), 'Get all keys', size_name, tdiff
268+
269+
end subroutine test_get_all_keys
270+
271+
231272
subroutine report_rehash_times( map, hasher, hash_name, size_name )
232273
type(open_hashmap_type), intent(inout) :: map
233274
procedure(hasher_fun) :: hasher

0 commit comments

Comments
 (0)