Created
May 16, 2017 19:14
-
-
Save lironsade/30817ca17419f71c9d58e22527e25708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop.ex4.data_structures; | |
/** | |
* Created by liron on 5/6/17. | |
*/ | |
public class Test { | |
public static void main(String[] args) { | |
// AvlTree a = new AvlTree(new int[] {5,4,6,7,15,23,50,71}); | |
System.out.println("Test 1: " + test1()); | |
System.out.println("Test 2: " + test2()); | |
System.out.println("Test 3: " + test3()); | |
System.out.println("Test 4: " + test4()); | |
System.out.println("Test 5: " + test5()); | |
System.out.println("Test 6: " + test6()); | |
System.out.println("Test 7: " + test7()); | |
System.out.println("Test 8: " + test8()); | |
System.out.println("Test 9: " + test9()); | |
} | |
static boolean test1() { | |
AvlTree a = new AvlTree(); | |
a.add(5); | |
a.delete(5); | |
return a.size() == 0; | |
} | |
static boolean test2() { | |
AvlTree a = new AvlTree(); | |
a.add(5); | |
a.add(6); | |
a.delete(6); | |
return a.size() == 1; | |
} | |
static boolean test3() { | |
AvlTree a = new AvlTree(); | |
a.add(5); | |
a.add(6); | |
return a.delete(5) && | |
a.contains(6) == 0 && | |
a.size() == 1; | |
} | |
static boolean test4() { | |
AvlTree a = new AvlTree(); | |
a.add(5); | |
a.add(6); | |
a.add(4); | |
return a.delete(5) && | |
a.contains(6) == 0 && | |
a.size() == 2; | |
} | |
static boolean test5() { | |
AvlTree a = new AvlTree(); | |
a.add(5); | |
a.add(6); | |
a.add(4); | |
a.add(3); | |
return a.delete(5) && | |
a.contains(4) == 0 && | |
a.contains(3) == 1 && | |
a.contains(6) == 1 && | |
a.size() == 3; | |
} | |
static boolean test6() { | |
AvlTree a = null; | |
AvlTree b = new AvlTree(a); | |
return b.size() == 0; | |
} | |
static boolean test7() { | |
AvlTree a = new AvlTree(); | |
AvlTree b = new AvlTree(a); | |
return b.size() == 0; | |
} | |
static boolean test8() { | |
AvlTree a = new AvlTree(); | |
a.add(4); | |
a.add(5); | |
a.add(6); | |
AvlTree b = new AvlTree(a); | |
return b.contains(4) == 1 && | |
b.contains(5) == 0 && | |
b.contains(6) == 1 && | |
b.size() == 3; | |
} | |
static boolean test9() { | |
int[] a = {4,5,6,7,8,9}; | |
int i = 0; | |
AvlTree b = new AvlTree(a); | |
boolean flag = true; | |
for (int x : | |
b) { | |
if (x != a[i]) | |
flag = false; | |
i++; | |
} | |
return flag; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment