-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathCeilInBinarySearchTreeTest.java
51 lines (41 loc) · 1.75 KB
/
CeilInBinarySearchTreeTest.java
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
package com.thealgorithms.datastructures.trees;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import com.thealgorithms.datastructures.trees.BinaryTree.Node;
import org.junit.jupiter.api.Test;
public class CeilInBinarySearchTreeTest {
@Test
public void testRootNull() {
assertNull(CeilInBinarySearchTree.getCeil(null, 9));
}
@Test
public void testKeyPresentRootIsCeil() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200});
assertEquals(100, CeilInBinarySearchTree.getCeil(root, 100).data);
}
@Test
public void testKeyPresentLeafIsCeil() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200});
assertEquals(10, CeilInBinarySearchTree.getCeil(root, 10).data);
}
@Test
public void testKeyAbsentRootIsCeil() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200, 5, 50, 150, 300});
assertEquals(100, CeilInBinarySearchTree.getCeil(root, 75).data);
}
@Test
public void testKeyAbsentLeafIsCeil() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200, 5, 50, 150, 300});
assertEquals(50, CeilInBinarySearchTree.getCeil(root, 40).data);
}
@Test
public void testKeyAbsentLeftMostNodeIsCeil() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200, 5, 50, 150, 300});
assertEquals(5, CeilInBinarySearchTree.getCeil(root, 1).data);
}
@Test
public void testKeyAbsentCeilIsNull() {
final Node root = TreeTestUtils.createTree(new Integer[] {100, 10, 200, 5, 50, 150, 300});
assertNull(CeilInBinarySearchTree.getCeil(root, 400));
}
}