### ----------------------------------------------------
### -- Tree::Binary
### -- Licenses: Artistic-2.0
### -- Authors: Scimon Proctor
### -- File: t/simple-int-trees.rakutest
### ----------------------------------------------------
use Test;

use Tree::Binary;

class IntTree does Tree::Binary::Role::BinaryTree[Int] {};

ok my IntTree(Str) $tree = "1(2)(3)";
ok $tree ~~ IntTree;
ok $tree ~~ Tree::Binary::Role::BinaryTree;
is "1(2)(3)", $tree.Str;

my $pretty = q:to/END/.chomp();
 1 
┌┴┐
2 3
END

is $pretty, $tree.gist();
is $tree.elems, 2;
is $tree.elems(:all), 3;
is $tree.elems(:leaf), 2;

my $tree2 = Tree::Binary::Role::BinaryTree.from-Str("1(2(3))(4(5)(6))");

is $tree2.elems, 2;
is $tree2.elems(:all), 6;
is $tree2.elems(:leaf), 3;
dies-ok { $tree.elems(:leaf, :all) };

is $tree.reverse.Str, "1(3)(2)";
is $tree2.reverse.Str, "1(4(6)(5))(2(3))";

my $tree3 = IntTree.from-Str("1(2(3))(4(5)(6))");

is $tree2, $tree3;

done-testing;


