forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadedBinaryTreeTest.java
More file actions
50 lines (40 loc) · 1.26 KB
/
ThreadedBinaryTreeTest.java
File metadata and controls
50 lines (40 loc) · 1.26 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
/*
* TheAlgorithms (https://github.com/TheAlgorithms/Java)
* Author: Shewale41
* This file is licensed under the MIT License.
*/
package com.thealgorithms.datastructures.trees;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* Basic tests for ThreadedBinaryTree inorder traversal.
*/
public class ThreadedBinaryTreeTest {
@Test
public void testInorderTraversalSimple() {
ThreadedBinaryTree tree = new ThreadedBinaryTree();
tree.insert(50);
tree.insert(30);
tree.insert(70);
tree.insert(20);
tree.insert(40);
tree.insert(60);
tree.insert(80);
List<Integer> expected = List.of(20, 30, 40, 50, 60, 70, 80);
List<Integer> actual = tree.inorderTraversal();
assertEquals(expected, actual);
}
@Test
public void testInorderWithDuplicates() {
ThreadedBinaryTree tree = new ThreadedBinaryTree();
tree.insert(5);
tree.insert(3);
tree.insert(7);
tree.insert(7); // duplicate
tree.insert(2);
List<Integer> expected = List.of(2, 3, 5, 7, 7);
List<Integer> actual = tree.inorderTraversal();
assertEquals(expected, actual);
}
}