File: builtin.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (40 lines) | stat: -rw-r--r-- 1,296 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/perl -Tw

use strict;
use Test::More;

my @Exported_Funcs;
BEGIN {
    @Exported_Funcs = qw( bucket_ratio num_buckets used_buckets );
    plan tests => 13 + @Exported_Funcs;
    use_ok 'Hash::Util', @Exported_Funcs;
}
foreach my $func (@Exported_Funcs) {
    can_ok __PACKAGE__, $func;
}

my %hash;

is(bucket_ratio(%hash), 0, "Empty hash has no bucket_ratio");
is(num_buckets(%hash), 8, "Empty hash should have eight buckets");
is(used_buckets(%hash), 0, "Empty hash should have no used buckets");

$hash{1}= 1;
is(bucket_ratio(%hash), "1/8", "hash has expected bucket_ratio");
is(num_buckets(%hash), 8, "hash should have eight buckets");
is(used_buckets(%hash), 1, "hash should have one used buckets");

$hash{$_}= $_ for 2..7;

like(bucket_ratio(%hash), qr!/(?:8|16)!, "hash has expected number of buckets in bucket_ratio");
my $num= num_buckets(%hash);
ok(($num == 8 || $num == 16), "hash should have 8 or 16 buckets");
cmp_ok(used_buckets(%hash), "<", 8, "hash should have one used buckets");

$hash{8}= 8;
like(bucket_ratio(%hash), qr!/(?:8|16)!, "hash has expected number of buckets in bucket_ratio");
$num= num_buckets(%hash);
ok(($num == 8 || $num == 16), "hash should have 8 or 16 buckets");
cmp_ok(used_buckets(%hash), "<=", 8, "hash should have at most 8 used buckets");