File: random_kv.t

package info (click to toggle)
liblist-objects-withutils-perl 2.028003-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,292 kB
  • sloc: perl: 1,957; makefile: 17; sh: 6
file content (18 lines) | stat: -rw-r--r-- 439 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Test::More;
use strict; use warnings;

use Lowu 'hash';

my $hs = hash(a => 1, b => 2, c => 3);
my $kv = $hs->random_kv;

cmp_ok ref $kv, 'eq', 'ARRAY', 'random_kv returned ARRAY';
my ($key, $val) = @$kv;

ok $hs->exists($key), 'randomly retrieved key exists';
cmp_ok $hs->get($key), '==', $val, 'retrieved value matches key';

my @r = hash->random_kv;
ok @r == 1 && !defined $r[0], 'empty hash returns undef random_kv';

done_testing