6 use Test::More tests => 21;
9 use Scalar::Util 'isweak';
24 predicate => 'has_parent',
31 predicate => 'has_left',
37 predicate => 'has_right',
40 before 'right', 'left' => sub {
41 my ($self, $tree) = @_;
42 $tree->parent($self) if defined $tree;
46 my $root = BinaryTree->new();
47 isa_ok($root, 'BinaryTree');
49 is($root->left, undef, '... no left node yet');
50 is($root->right, undef, '... no right node yet');
52 ok(!$root->has_left, '... no left node yet');
53 ok(!$root->has_right, '... no right node yet');
55 ok(!$root->has_parent, '... no parent for root node');
57 my $left = BinaryTree->new();
58 isa_ok($left, 'BinaryTree');
60 ok(!$left->has_parent, '... left does not have a parent');
64 is($root->left, $left, '... got a left node now (and it is $left)');
65 ok($root->has_left, '... we have a left node now');
67 ok($left->has_parent, '... lefts has a parent');
68 is($left->parent, $root, '... lefts parent is the root');
70 ok(isweak($left->{parent}), '... parent is a weakened ref');
72 my $right = BinaryTree->new();
73 isa_ok($right, 'BinaryTree');
75 ok(!$right->has_parent, '... right does not have a parent');
79 is($root->right, $right, '... got a right node now (and it is $right)');
80 ok($root->has_right, '... we have a right node now');
82 ok($right->has_parent, '... rights has a parent');
83 is($right->parent, $root, '... rights parent is the root');
85 ok(isweak($right->{parent}), '... parent is a weakened ref');