@@ -22,6 +22,7 @@ subroutine collect_tbl(testsuite)
22
22
& new_unittest(" fhash-tbl-pointer-value" , test_fhash_pointer_value), &
23
23
& new_unittest(" fhash-tbl-derived-type-value" , test_fhash_derived_type_value), &
24
24
& new_unittest(" fhash-tbl-invalid-keys" , test_fhash_invalid_keys), &
25
+ & new_unittest(" fhash-tbl-stats-empty" , test_fhash_stats_empty), &
25
26
& new_unittest(" fhash-tbl-unset" , test_fhash_unset), &
26
27
& new_unittest(" fhash-tbl-high-load" , test_fhash_balanced_load) &
27
28
]
@@ -367,6 +368,41 @@ subroutine test_fhash_invalid_keys(error)
367
368
368
369
end subroutine test_fhash_invalid_keys
369
370
371
+ ! > Check stats for empty table
372
+ subroutine test_fhash_stats_empty (error )
373
+ type (error_t), allocatable , intent (out ) :: error
374
+
375
+ type (fhash_tbl_t) :: tbl
376
+ integer :: num_buckets, num_items, num_collisions, max_depth
377
+
378
+ call tbl% stats(num_buckets,num_items,num_collisions,max_depth)
379
+
380
+ if (num_buckets /= 0 ) then
381
+ print * , ' num_buckets: ' , num_buckets
382
+ call test_failed(error,' empty table returned non-zero for num_buckets' )
383
+ return
384
+ end if
385
+
386
+ if (num_items /= 0 ) then
387
+ print * , ' num_items: ' , num_items
388
+ call test_failed(error,' empty table returned non-zero for num_items' )
389
+ return
390
+ end if
391
+
392
+ if (num_collisions /= 0 ) then
393
+ print * , ' num_collisions: ' , num_collisions
394
+ call test_failed(error,' empty table returned non-zero for num_collisions' )
395
+ return
396
+ end if
397
+
398
+ if (max_depth > 0 ) then
399
+ print * , ' max_depth: ' , max_depth
400
+ call test_failed(error,' empty table returned positive for max_depth' )
401
+ return
402
+ end if
403
+
404
+ end subroutine test_fhash_stats_empty
405
+
370
406
371
407
! > Store lots of values and check stats
372
408
subroutine test_fhash_balanced_load (error )
0 commit comments