package com.yakovshklarov.branchy;

public class TestBranchy {
    public static void main (String[] args) {
        System.out.println("Testing branchy....");
        //Node n = new Node(Color.RED, 42);
        //n.setRight(new Node(Color.BLACK, 0));
        System.out.print("Creating a new tree. ");
        RedBlackTree testTree = new RedBlackTree(new Integer[]{5, 3, 1, 4, 7, 6, 8, 2});
        System.out.println("Displaying the tree: ");
        System.out.println(testTree);
        
        int size = testTree.size();
        System.out.printf("The tree has %d node", testTree.size());
        if (size != 1) System.out.printf("s");
        System.out.println(".");
        
        System.out.print("Converting to array: ");
        printArray(testTree.toArray());
        
        RedBlackTree testTreeClone = testTree.clone();
        Integer[] toRemove = new Integer[] {7,6,1,3,8,2,4,5};
        
        for (Integer n: toRemove) {
            System.out.println("Removing " + n + ": ");
            testTree.remove(n);
            System.out.println(testTree);
        }
        
        System.out.println("Original (cloned) tree: ");
        System.out.println(testTreeClone);
    }
    
    private static void printArray(Integer[] arr) {
        System.out.print("[ ");
        for (Integer elem: arr)
            System.out.print(elem + " ");
        System.out.println("]");
    }

}

@@ -29,16 +29,98 @@
 anchy;%0A%0A
+import java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.ArrayList;%0A%0A
 public c
@@ -235,24 +235,25 @@
 ....%22);%0A
+%0A
         
 //Node n
@@ -248,142 +248,245 @@
     
-//Node n = new Node(Color.RED, 42
+System.out.print(%22Creating a new tree. %22
 );%0A   
+  
+   %0A
      
-//n.setRight(new Node(Color.BLACK, 0));%0A        System.out.print(%22Creating a new tree. %22);
+   List%3CInteger%3E contents = new ArrayList%3CInteger%3E();%0A        for (int i = 1; i %3C= 15; i++) %7B%0A            contents.add(i);%0A        %7D%0A        Collections.shuffle(contents);%0A        
 %0A   
@@ -535,45 +535,40 @@
 ree(
-new Integer%5B%5D%7B5, 3, 1, 4, 7, 6, 8, 2%7D
+contents.toArray(new Integer%5B0%5D)
 );%0A 
@@ -1026,60 +1026,109 @@
     
-Integer%5B%5D toRemove = new Integer%5B%5D %7B7,6,1,3,8,2,4,5%7D
+%0A        Collections.shuffle(contents);%0A        Integer%5B%5D toRemove = contents.toArray(new Integer%5B0%5D)
 ;%0A  
@@ -1238,16 +1238,20 @@
         
+if (
 testTree
@@ -1260,16 +1260,100 @@
 emove(n)
+ == null)%0A                System.out.println(%22ERROR: %22 + n + %22 is not in the tree!%22)
 ;%0A      
@@ -1552,23 +1552,22 @@
 ntArray(
-Integer
+Object
 %5B%5D arr) 
@@ -1613,23 +1613,22 @@
    for (
-Integer
+Object
  elem: a

Improve tests