File: test_leaks2.t

package info (click to toggle)
libheap-perl 0.80-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 196 kB
  • ctags: 87
  • sloc: perl: 1,161; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env perl

BEGIN {
    chdir 't' if -d 't';
    use lib '../lib';
    $| = 1;
    print "1..13\n";
}

END {print "not ok 1\n" unless $loaded;}
$loaded = 1;
print "ok 1\n";

use Heap::Fibonacci;
use Heap::Elem::Num( NumElem );

my $heapsize;
my $extractsize;
my $test = 1;

my $allocated;

sub Heap::Elem::Num::DESTROY {
    --$allocated;
}

for (
	$extractsize = 5;
	$extractsize < 20000;
	$extractsize = $heapsize) {
    $heapsize = $extractsize*5;
    $allocated = 0;

    my $heap = Heap::Fibonacci->new;

    for (1..$heapsize) {
	my $val = int(rand(1000));
	my $heapElem = NumElem( $val );
	$heap->add($heapElem);
	++$allocated;
    }

    print( (($allocated == $heapsize) ? "" : "not "),
	    "ok ",
	    ++$test,
	    "\n" );

    for (1..$extractsize){ 
	my $elem = $heap->extract_top;
    }
	
    undef $heap;

    print( (($allocated == 0) ? "" : "not "),
	    "ok ",
	    ++$test,
	    "\n" );

}