-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Expand file tree
/
Copy pathRightViewOfBinaryTreeTest.java
More file actions
41 lines (33 loc) · 1.49 KB
/
RightViewOfBinaryTreeTest.java
File metadata and controls
41 lines (33 loc) · 1.49 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
package com.thealgorithms.datastructures.trees;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class RightViewOfBinaryTreeTest {
@Test
public void testRightViewOfBalancedTree() {
RightViewOfBinaryTree.Node root = new RightViewOfBinaryTree.Node(1);
root.left = new RightViewOfBinaryTree.Node(2);
root.right = new RightViewOfBinaryTree.Node(3);
root.left.left = new RightViewOfBinaryTree.Node(4);
root.left.right = new RightViewOfBinaryTree.Node(5);
root.right.right = new RightViewOfBinaryTree.Node(6);
List<Integer> expected = List.of(1, 3, 6);
assertEquals(expected, RightViewOfBinaryTree.rightViewDFS(root));
}
@Test
public void testRightSkewedTree() {
RightViewOfBinaryTree.Node root = new RightViewOfBinaryTree.Node(1);
root.right = new RightViewOfBinaryTree.Node(2);
root.right.right = new RightViewOfBinaryTree.Node(3);
List<Integer> expected = List.of(1, 2, 3);
assertEquals(expected, RightViewOfBinaryTree.rightViewDFS(root));
}
@Test
public void testLeftSkewedTree() {
RightViewOfBinaryTree.Node root = new RightViewOfBinaryTree.Node(1);
root.left = new RightViewOfBinaryTree.Node(2);
root.left.left = new RightViewOfBinaryTree.Node(3);
List<Integer> expected = List.of(1, 2, 3);
assertEquals(expected, RightViewOfBinaryTree.rightViewBFS(root));
}
}