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
56 lines (49 loc) · 1.52 KB
/
BinaryTreeTest.java
File metadata and controls
56 lines (49 loc) · 1.52 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
package com.dataStructures;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class BinaryTreeTest {
BinaryTreeTest() {
}
/**
* Test of insert method, of class BinaryTree.
*/
@Test
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();
Assertions.assertEquals("123", proof);
}
/**
* Test of search method, of class BinaryTree.
*/
@Test
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);
Assertions.assertEquals(1, result.getData());
}
/**
* Test of contains method, of class BinaryTree.
*/
@Test
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);
Assertions.assertFalse(result);
}
}