AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
AVLTreeTest.java
Go to the documentation of this file.
1package aud.test;
2
3import aud.AVLTree;
5
6import org.junit.*;
7import static org.junit.Assert.*;
8
9public class AVLTreeTest {
10
11 @Test
12 public void testAVLTree() {
13 String[] keys={"a","b","c","d","e","f","g","h","i"};
14 int n=keys.length;
15 int maxHeight=0;
16
17 { int k=n; while (k>0) { k>>=1; ++maxHeight; } }
18 maxHeight=2*maxHeight+2;
19
20 for (int[] p : new Permutations(n)) {
21
22 AVLTree<String,String> tree=new AVLTree<String,String>();
23
24 for (int i : p) {
25 String k=tree.find(keys[i]);
26 assertEquals(k,null);
27 tree.insert(keys[i],keys[i]);
28 k=tree.find(keys[i]);
29 assertTrue(k!=null);
30 assertTrue(k.compareTo(keys[i])==0);
31 tree.checkConsistency();
32 }
33 assertTrue(tree.getHeight()<=maxHeight);
34 }
35 }
36
37 public static void main(String args[]) {
38 org.junit.runner.JUnitCore.main("aud.test.AVLTreeTest");
39 }
40}
static void main(String args[])
Generate permutations.
utilities (not related to AuD lecture)
Definition: Colormap.java:1
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1