Skip to content

Commit 3bb4eca

Browse files
add test for 110
1 parent fa9208b commit 3bb4eca

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/main/java/com/fishercoder/solutions/_110.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* 110. Balanced Binary Tree
77
*
88
* Given a binary tree, determine if it is height-balanced.
9-
* For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
9+
* For this problem, a height-balanced binary tree is defined as a binary tree in which
10+
* the depth of the two subtrees of every node never differ by more than 1.
1011
1112
Example 1:
1213
Given the following tree [3,9,20,null,null,15,7]:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
import com.fishercoder.common.utils.TreeUtils;
5+
import com.fishercoder.solutions._110;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class _110Test {
14+
private static _110.Solution1 solution1;
15+
private static _110.Solution2 solution2;
16+
private static TreeNode treeNode;
17+
18+
@BeforeClass
19+
public static void setup() {
20+
solution1 = new _110.Solution1();
21+
solution2 = new _110.Solution2();
22+
}
23+
24+
@Test
25+
public void test1() {
26+
treeNode = TreeUtils.constructBinaryTree(Arrays.asList(3, 9, 20, null, null, 15, 7));
27+
assertEquals(true, solution1.isBalanced(treeNode));
28+
}
29+
30+
@Test
31+
public void test2() {
32+
treeNode = TreeUtils.constructBinaryTree(Arrays.asList(3, 9, 20, null, null, 15, 7));
33+
assertEquals(true, solution2.isBalanced(treeNode));
34+
}
35+
36+
@Test
37+
public void test3() {
38+
treeNode = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 2, 3, 3, null, null, 4, 4));
39+
assertEquals(false, solution1.isBalanced(treeNode));
40+
}
41+
42+
@Test
43+
public void test4() {
44+
treeNode = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 2, 3, 3, null, null, 4, 4));
45+
assertEquals(false, solution2.isBalanced(treeNode));
46+
}
47+
48+
49+
}

0 commit comments

Comments
 (0)