Doubly

 view release on metacpan or  search on metacpan

t/22-memory-leaks.t  view on Meta::CPAN

    }, 'remove_from_start/end operations do not leak');
};

# Test 12: insert_at_start/insert_at_end operations
subtest 'insert_at_start/end operations' => sub {
    plan tests => 1;
    no_leaks_ok(sub {
        for (1..100) {
            my $list = Doubly->new(1);
            $list->insert_at_start(0);
            $list->insert_at_end(2);
            $list->destroy();
        }
    }, 'insert_at_start/end operations do not leak');
};

# Test 13: insert_before/after operations
subtest 'insert_before/after operations' => sub {
    plan tests => 1;
    no_leaks_ok(sub {
        for (1..50) {
            my $list = Doubly->new(1);
            $list->insert_after(2);
            $list->insert_before(0);
            $list->insert_at_start(-1);
            $list->insert_at_end(3);
            $list->destroy();
        }
    }, 'insert operations do not leak');
};

# Test 14: Navigation operations (prev/next/start/end)
subtest 'navigation operations' => sub {
    plan tests => 1;
    no_leaks_ok(sub {
        for (1..100) {
            my $list = Doubly->new(1);
            $list->add(2);
            $list->add(3);
            $list = $list->next();
            $list = $list->prev();
            $list = $list->start();
            $list = $list->end();
            $list->destroy();
        }
    }, 'navigation operations do not leak');
};

# Test 15: bulk_add operation
subtest 'bulk_add operation' => sub {
    plan tests => 1;
    no_leaks_ok(sub {
        for (1..100) {
            my $list = Doubly->new();
            $list->bulk_add(1, 2, 3, 4, 5);
            $list->destroy();
        }
    }, 'bulk_add does not leak');
};

# Test 16: Verify no accumulating leaks over many iterations
subtest 'no accumulating leaks' => sub {
    plan tests => 1;
    my $baseline = leaked_count(sub {
        for (1..10) {
            my $list = Doubly->new($_);
            $list->add($_*2) for 1..5;
            $list->destroy();
        }
    });
    
    my $larger = leaked_count(sub {
        for (1..100) {
            my $list = Doubly->new($_);
            $list->add($_*2) for 1..5;
            $list->destroy();
        }
    });
    
    my $ratio = $larger / ($baseline || 1);
    ok($ratio < 2, "leak count does not scale with iterations (ratio: $ratio)")
        or diag("baseline=$baseline, larger=$larger - indicates per-iteration leak");
};

done_testing();



( run in 0.933 second using v1.01-cache-2.11-cpan-71847e10f99 )