mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Cover BSTRecursive with tests (#4180)
This commit is contained in:

committed by
GitHub

parent
89b7ee42e6
commit
3a593d5d3c
@ -0,0 +1,61 @@
|
||||
package com.thealgorithms.datastructures.trees;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Albina Gimaletdinova on 06/05/2023
|
||||
*/
|
||||
public class BSTRecursiveTest {
|
||||
@Test
|
||||
public void testBSTIsCorrectlyConstructedFromOneNode() {
|
||||
BSTRecursive tree = new BSTRecursive();
|
||||
tree.add(6);
|
||||
|
||||
Assertions.assertTrue(CheckBinaryTreeIsValidBST.isBST(tree.getRoot()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBSTIsCorrectlyCleanedAndEmpty() {
|
||||
BSTRecursive tree = new BSTRecursive();
|
||||
|
||||
tree.add(6);
|
||||
tree.remove(6);
|
||||
|
||||
tree.add(12);
|
||||
tree.add(1);
|
||||
tree.add(2);
|
||||
|
||||
tree.remove(1);
|
||||
tree.remove(2);
|
||||
tree.remove(12);
|
||||
|
||||
Assertions.assertNull(tree.getRoot());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBSTIsCorrectlyCleanedAndNonEmpty() {
|
||||
BSTRecursive tree = new BSTRecursive();
|
||||
|
||||
tree.add(6);
|
||||
tree.remove(6);
|
||||
|
||||
tree.add(12);
|
||||
tree.add(1);
|
||||
tree.add(2);
|
||||
|
||||
Assertions.assertTrue(CheckBinaryTreeIsValidBST.isBST(tree.getRoot()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBSTIsCorrectlyConstructedFromMultipleNodes() {
|
||||
BSTRecursive tree = new BSTRecursive();
|
||||
tree.add(7);
|
||||
tree.add(1);
|
||||
tree.add(5);
|
||||
tree.add(100);
|
||||
tree.add(50);
|
||||
|
||||
Assertions.assertTrue(CheckBinaryTreeIsValidBST.isBST(tree.getRoot()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user