File: bsearchidx.pm

package info (click to toggle)
liblist-moreutils-perl 0.430-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,228 kB
  • sloc: perl: 13,167; makefile: 17
file content (41 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (4)
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
41

use Test::More;
use Test::LMU;

my @list = my @in = 1 .. 1000;
for my $i (0 .. $#in)
{
    is($i, bsearchidx { $_ - $in[$i] } @list);
}
my @out = (-10 .. 0, 1001 .. 1011);
for my $elem (@out)
{
    my $r = bsearchidx { $_ - $elem } @list;
    is(-1, $r);
}

leak_free_ok(
    bsearch => sub {
        my $elem = int(rand(1000)) + 1;
        bsearchidx { $_ - $elem } @list;
    }
);

leak_free_ok(
    'bsearch with stack-growing' => sub {
        my $elem = int(rand(1000));
        bsearchidx { grow_stack(); $_ - $elem } @list;
    }
);

leak_free_ok(
    'bsearch with stack-growing and exception' => sub {
        my $elem = int(rand(1000));
        eval {
            bsearchidx { grow_stack(); $_ - $elem or die "Goal!"; $_ - $elem } @list;
        };
    }
);
is_dying('bsearchidx without sub' => sub { &bsearchidx(42, (1 .. 100)); });

done_testing;