-
Notifications
You must be signed in to change notification settings - Fork 19.8k
/
Copy pathZigzagTraversalTest.java
51 lines (45 loc) · 1.39 KB
/
ZigzagTraversalTest.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 java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
/**
* @author Albina Gimaletdinova on 11/01/2023
*/
public class ZigzagTraversalTest {
@Test
public void testRootNull() {
assertEquals(Collections.emptyList(), ZigzagTraversal.traverse(null));
}
@Test
public void testSingleNodeTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {50});
assertEquals(List.of(List.of(50)), ZigzagTraversal.traverse(root));
}
/*
1
/ \
2 3
/\ /\
4 5 6 7
*/
@Test
public void testZigzagTraversalCompleteTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7});
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7)), ZigzagTraversal.traverse(root));
}
/*
1
/ \
2 3
/\ /\
4 5 6 7
/ \
8 9
*/
@Test
public void testZigzagTraversalDifferentHeight() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7, null, null, 8, null, null, 9});
assertEquals(List.of(List.of(1), List.of(3, 2), List.of(4, 5, 6, 7), List.of(9, 8)), ZigzagTraversal.traverse(root));
}
}