
BEGIN { 
  open OLDSTDOUT, ">&STDOUT" or die $!;
  open STDOUT, ">", "/dev/null" or die $!;
      }

END {
  use ExampleTree;
  use ExampleTree2;
  use ExampleTree3;
  use ExampleTree4;
  use ExampleTree5;
  print STDERR "$0\n";
  open OUTA, ">", "output/$0.out" or die $!;
  my $N = 1;
  for my $t (
             ExampleTree->new("top", ["a", ["a1"], ["a2"]], ["b"], ["c"],),
             ExampleTree->new("1", ["2", ["3", ["4", ["5"]]]],),
             ExampleTree->new("top", ["a", ["b", ["c"], ["d"]], 
                                           ["e", ["f"]]], 
                              ["g", ["h"]]),
             ExampleTree->new(11, [12, [13, [14], [24], [34]],
                                   [43, [44]]],
                              [22, [23], [33]]
                             ),
             ExampleTree2->new(5), # n-branching
             ExampleTree3->new([7]), # partition
             ExampleTree4->new("top", ["a", ["a1"], ["a2"]], ["b"], ["c"],),
             ExampleTree5->new(6, [3], [3], [3], [3], [3]),
             ExampleTree5->new(19, [7, [3]], [3]),
             ExampleTree5->new(1, [3, [9], [9]], [3, [9], [9]]),
            ) {
    open OUTS, ">>", "output/out$N" or die $!;
    my $aref = eval { layout_tree($t) };
    if ($@) {
      print OUTS "\n\n$0\n\n", "FAILED:\n$@\n", "\n--------\n";
      print OUTA "\n\nExample $N\n\n", "FAILED:\n$@\n", "\n--------\n";
      $N++;
      next;
    }
    $aref = [layout_tree($t)] unless ref $aref;
    print OUTS "\n\n$0\n\n", join("\n", @$aref, ""), "\n\n--------\n";
    print OUTA "\n\nExample $N\n\n", join("\n", @$aref, ""), "\n\n--------\n";
    $N++;
  }
}

1;
