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 60 61 62 63 64
|
use strict;
use Test::More tests => 23;
use Tree::RedBlack;
my $tree = Tree::RedBlack->new();
isa_ok($tree, 'Tree::RedBlack');
is($tree->root, undef);
is($tree->find(42), undef);
is($tree->max, undef);
is($tree->min, undef);
$tree->insert(3, 'cat');
is($tree->find(3), 'cat');
is($tree->min->val, 'cat');
is($tree->max->val, 'cat');
is($tree->find(42), undef);
$tree->insert(3, 'dog');
is($tree->find(3), 'dog');
$tree->insert(4);
is($tree->max->val, undef);
is($tree->find(4), undef);
isa_ok($tree->node(4), 'Tree::RedBlack::Node');
$tree->insert(7, 'dude');
$tree->insert(5, 'really');
$tree->insert(6, 'cool');
is($tree->min->val, 'dog');
is($tree->max->val, 'dude');
is($tree->find(5), 'really');
$tree->delete(3);
is($tree->min->val, undef);
is($tree->node(14), undef);
my $tree2 = Tree::RedBlack->new();
$tree2->cmp(sub { $_[0] <=> $_[1] });
$tree2->insert(10);
$tree2->insert(2);
is($tree2->max->key, 10);
is($tree2->min->key, 2);
is($tree2->node(10), $tree2->max);
is($tree2->node(2), $tree2->min);
SKIP: {
skip 'delete not working correctly' => 1;
$tree2->delete(10);
is($tree2->max->key, 2);
};
|