Debian Codegraph @

t/3unique/v1.t

raw
1 use strict;
2 use warnings;
3 use MyTest;
4 use MyTmpTimer;
5 use UUID;
6
7 my $N = 4_000;
8 my %seen = ();
9 my $count = 0;
10
11 my $fh = tmptimer( $N, sub {
12 my ($N, $fh) = @_;
13 my ($bin, $str);
14 for (1 .. $N) {
15 UUID::generate_v1($bin);
16 UUID::unparse($bin, $str);
17 print $fh $str. "\n";
18 }
19 });
20
21 while (my $str = <$fh>) {
22 chomp $str;
23 note $str if $count++ < 3;;
24 ++$seen{$str};
25 }
26
27 # avoid cleanup race
28 $fh->close;
29
30 {
31 my $expected = $N;
32 my $got = scalar keys %seen;
33 is $count, $expected, 'count ok';
34 is $got, $expected, 'unique ok';
35
36 # show the repeats, if any
37 my $reps = scalar grep { $seen{$_} > 1 } keys %seen;
38 next unless $reps;
39 diag q( repeats: '). $reps. q(');
40 }
41
42 done_testing;