forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreeTest.java
More file actions
58 lines (50 loc) · 1.57 KB
/
BinaryTreeTest.java
File metadata and controls
58 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package src.test.java.com.dataStructures;
import org.junit.Test;
import src.main.java.com.dataStructures.BinaryTree;
import static org.junit.Assert.*;
public class BinaryTreeTest {
public BinaryTreeTest() {
}
/**
* Test of insert method, of class BinaryTree.
*/
@Test
public void testInsertBinaryTree() {
System.out.println("insert");
BinaryTree<String> lowerData = new BinaryTree<>("1");
BinaryTree<String> upperData = new BinaryTree<>("3");
BinaryTree<String> instance = new BinaryTree<>("2");
instance.insert(lowerData);
instance.insert(upperData);
String proof = instance.getLeft().toString()
+ instance.toString()
+ instance.getRight().toString();
assertEquals("123", proof);
}
/**
* Test of search method, of class BinaryTree.
*/
@Test
public void testSearch() {
System.out.println("search");
BinaryTree<Integer> instance = new BinaryTree<>(5);
for (int i = 1; i < 10; i++) {
instance.insert(i);
}
BinaryTree result = instance.search(1);
assertEquals(1, result.getData());
}
/**
* Test of contains method, of class BinaryTree.
*/
@Test
public void testContains() {
System.out.println("contains");
BinaryTree<Integer> instance = new BinaryTree<>(5);
for (int i = 1; i < 10; i++) {
instance.insert(i);
}
boolean result = instance.contains(2) && instance.contains(11);
assertFalse(result);
}
}