[Freegis-list] Strange behavior in Tree::R CPAN module

Brandon Forehand b4hand at users.sourceforge.net
Wed Jul 29 21:34:14 CEST 2009


So, I was using the Tree::R module, and I ran into a strange problem, so
I wrote a small unit test to test the problem, and it appears the source
of the bug may be in Tree::R itself.  The underlying cause seems to be
that when you remove everything from a Tree::R object and then insert
something back into the same Tree::R object, the resulting number of
objects in the Tree is no longer correct.  Here's a small unit test that
reproduces the bug:

use strict;
use warnings;

use Test::More tests => 5;

BEGIN { use_ok('Tree::R'); }

my $r_tree = Tree::R->new();

isa_ok($r_tree, 'Tree::R');

my $rects = {
    1 => [0, 0, 10, 20],
    2 => [20, 0, 10, 20],
    3 => [0, 30, 10, 20],
    4 => [20, 30, 10, 20],
};

for my $rect (keys %$rects) {
    $r_tree->insert($rect, @{$rects->{$rect}});
}

{
    my @objects;
    $r_tree->objects(\@objects);

    is(scalar(@objects), 4);
}

for my $rect (keys %$rects) {
    $r_tree->remove($rect);
}

{
    my @objects;
    $r_tree->objects(\@objects);

    is(scalar(@objects), 0);
}

$r_tree->insert($rects->{1}, @{$rects->{1}});

{
    my @objects;
    $r_tree->objects(\@objects);

    is(scalar(@objects), 1);
}

In this unit test, the last test fails for me.  Instead of the value 1,
I got 2.  I don't believe that this is the intended behavior

-- 
Brandon Forehand




More information about the Freegis-list mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)