### Question:
RedBlackTree { public Pair<RedBlackNode<K, V>, Boolean> put(K key, V value) { if (root == null) { size++; root = new RedBlackNode<K,V>(key,value,null); return new Pair<RedBlackNode<K, V>, Boolean>( root, Boolean.TRUE ); } RedBlackNode<K,V> node = root; while (true) { int comp = comparator.compare(key, node.key); if (comp == 0 && !allowDuplicateKeys) { node.value = value; return new Pair<RedBlackNode<K, V>, Boolean>( node, Boolean.FALSE ); } else if (comp < 0) { if (node.left != null) { node = node.left; } else { size++; RedBlackNode<K, V> newNode = new RedBlackNode<K,V>(key, value, node); node.left = newNode; fixAfterInsertion(newNode); return new Pair<RedBlackNode<K, V>, Boolean>( newNode, Boolean.TRUE ); } } else { if (node.right != null) { node = node.right; } else { size++; RedBlackNode<K, V> newNode = new RedBlackNode<K,V>(key, value, node); node.right = newNode; fixAfterInsertion(newNode); return new Pair<RedBlackNode<K, V>, Boolean>( newNode, Boolean.TRUE ); } } } } RedBlackTree(Comparator<K> comparator, boolean allowDuplicateKeys);  RedBlackTree(RedBlackTree<K, V> tree); @Override String toString(); int size(); boolean containsKey(K key); RedBlackNode<K,V> getFirst(); RedBlackNode<K,V> getLast(); RedBlackNode<K,V> lowerBound(K key); RedBlackNode<K,V> upperBound(K key); Pair<RedBlackNode<K, V>, Boolean> put(K key, V value); RedBlackNode<K,V> findFirstNode(K key); RedBlackNode<K,V> findLastNode(K key); V remove(K key); void removeAll(); boolean isEmpty(); void deleteEntry(RedBlackNode<K,V> p); static final String EOL; }### Answer:
@Test public void testPut() { Pair<RedBlackNode<Integer, String>, Boolean> result = tree.put( 5, "five - dup" ); assertTrue( !result.second ); result = tree.put( 3, "three - dup" ); assertTrue( !result.second ); result = tree.put( 200, "two hundred" ); assertTrue( result.second ); treeWithDups.put( 5, "five - dup" ); assertTrue( result.second ); result = treeWithDups.put( 200, "two hundred" ); assertTrue( result.second ); }
@Test public void testDepth() { tree = new RedBlackTree<Integer, String>(new SelfComparator<Integer>(), false); tree.put(1, "one"); tree.put(2, "two"); tree.put(3, "three"); tree.put(4, "four"); tree.put(5, "five"); tree.put(6, "six"); tree.put(7, "seven"); tree.put(8, "eight"); tree.put(9, "nine"); tree.put(10, "ten"); assertEquals(4, getTreeDepth(tree)); tree = new RedBlackTree<Integer, String>(new SelfComparator<Integer>(), false); tree.put(10, "ten"); tree.put(9, "nine"); tree.put(8, "eight"); tree.put(7, "seven"); tree.put(6, "six"); tree.put(5, "five"); tree.put(4, "four"); tree.put(3, "three"); tree.put(2, "two"); tree.put(1, "one"); assertEquals(4, getTreeDepth(tree)); }