Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,4 @@ public boolean isEmpty() {
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,4 @@ void testSize() {
stack.pop();
assertEquals(0, stack.size(), "Size should be 0 after popping all elements.");
}

@Test
void testPrint() {
NodeStack<Integer> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -35,7 +36,12 @@ void test2() {
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
Expand Down