|
| 1 | +package com.fishercoder.secondthousand; |
| 2 | + |
| 3 | +import com.fishercoder.common.classes.TreeNode; |
| 4 | +import com.fishercoder.common.utils.TreeUtils; |
| 5 | +import com.fishercoder.solutions.secondthousand._1080; |
| 6 | +import org.junit.jupiter.api.BeforeEach; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +import java.util.Arrays; |
| 10 | + |
| 11 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 12 | + |
| 13 | +public class _1080Test { |
| 14 | + private static _1080.Solution1 solution1; |
| 15 | + |
| 16 | + @BeforeEach |
| 17 | + public void setup() { |
| 18 | + solution1 = new _1080.Solution1(); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + public void test1() { |
| 23 | + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, -3, -5, null, 4, null)); |
| 24 | + TreeUtils.printBinaryTree(root); |
| 25 | + TreeNode expected = TreeUtils.constructBinaryTree(Arrays.asList(1, null, -3, 4)); |
| 26 | + TreeUtils.printBinaryTree(expected); |
| 27 | + assertEquals(expected, solution1.sufficientSubset(root, -1)); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void test2() { |
| 32 | + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, -3, -5, 3, null, 4, null)); |
| 33 | + TreeUtils.printBinaryTree(root); |
| 34 | + TreeNode expected = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, -3, null, 3, null, 4)); |
| 35 | + TreeUtils.printBinaryTree(expected); |
| 36 | + assertEquals(expected, solution1.sufficientSubset(root, -1)); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void test3() { |
| 41 | + TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(5, 4, 8, 11, null, 17, 4, 7, 1, null, null, 5, 3)); |
| 42 | + TreeUtils.printBinaryTree(root); |
| 43 | + TreeNode expected = TreeUtils.constructBinaryTree(Arrays.asList(5, 4, 8, 11, null, 17, 4, 7, null, null, null, 5)); |
| 44 | + TreeUtils.printBinaryTree(expected); |
| 45 | + assertEquals(expected, solution1.sufficientSubset(root, 22)); |
| 46 | + } |
| 47 | +} |
0 commit comments