diff --git a/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java b/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java index 384cf3c03..bbcdfe1cc 100644 --- a/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java +++ b/src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java @@ -95,15 +95,4 @@ public class NodeStack { public int size() { return size; } - - /** - * Prints the contents of the stack from top to bottom. - */ - public void print() { - Node current = head; - while (current != null) { - System.out.println(current.data); - current = current.previous; - } - } } diff --git a/src/test/java/com/thealgorithms/datastructures/stacks/NodeStackTest.java b/src/test/java/com/thealgorithms/datastructures/stacks/NodeStackTest.java index e05319359..7ac0d8bc3 100644 --- a/src/test/java/com/thealgorithms/datastructures/stacks/NodeStackTest.java +++ b/src/test/java/com/thealgorithms/datastructures/stacks/NodeStackTest.java @@ -70,16 +70,4 @@ class NodeStackTest { stack.pop(); assertEquals(0, stack.size(), "Size should be 0 after popping all elements."); } - - @Test - void testPrint() { - NodeStack stack = new NodeStack<>(); - stack.push(1); - stack.push(2); - stack.push(3); - - // Output verification would ideally be handled through a different means - // but you can print as a basic check to confirm method runs without errors. - stack.print(); - } } diff --git a/src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java b/src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java index b153c5d66..08a82e50c 100644 --- a/src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java +++ b/src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java @@ -1,6 +1,7 @@ package com.thealgorithms.datastructures.trees; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import org.junit.jupiter.api.Test; @@ -35,7 +36,12 @@ public class BinaryTreeTest { t.remove(5); t.remove(7); - assertEquals(t.getRoot().data, 9); + // Checks whether the root is null before accessing date + if (t.getRoot() != null) { + assertEquals(t.getRoot().data, 9); + } else { + fail("The root node is null after removal."); + } } // checks that removing an unexistend node returns false