Add check if tree is symmetric or not (fixes #3471) (#3472)

Co-authored-by: Amit Kumar <akumar@indeed.com>
Co-authored-by: Andrii Siriak <siryaka@gmail.com>
This commit is contained in:
Amit Kumar
2022-10-30 13:59:22 +05:30
committed by GitHub
parent 23eec39a29
commit 3542f1c4c1
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.thealgorithms.datastructures.trees;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author kumanoit on 10/10/22 IST 1:02 AM
*/
public class CheckTreeIsSymmetricTest {
@Test
public void testRootNull() {
assertTrue(CheckTreeIsSymmetric.isSymmetric(null));
}
@Test
public void testSingleNodeTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[]{100});
assertTrue(CheckTreeIsSymmetric.isSymmetric(root));
}
@Test
public void testSymmetricTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[]{1,2,2,3,4,4,3});
assertTrue(CheckTreeIsSymmetric.isSymmetric(root));
}
@Test
public void testNonSymmetricTree() {
final BinaryTree.Node root = TreeTestUtils.createTree(new Integer[]{1,2,2,3,5,4,3});
assertFalse(CheckTreeIsSymmetric.isSymmetric(root));
}
}