Skip to content

Commit a2e526b

Browse files
authored
Add tests for NodeStack (#6009)
1 parent a163816 commit a2e526b

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,4 @@ public boolean isEmpty() {
9595
public int size() {
9696
return size;
9797
}
98-
99-
/**
100-
* Prints the contents of the stack from top to bottom.
101-
*/
102-
public void print() {
103-
Node current = head;
104-
while (current != null) {
105-
System.out.println(current.data);
106-
current = current.previous;
107-
}
108-
}
10998
}

src/test/java/com/thealgorithms/datastructures/stacks/NodeStackTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,4 @@ void testSize() {
7070
stack.pop();
7171
assertEquals(0, stack.size(), "Size should be 0 after popping all elements.");
7272
}
73-
74-
@Test
75-
void testPrint() {
76-
NodeStack<Integer> stack = new NodeStack<>();
77-
stack.push(1);
78-
stack.push(2);
79-
stack.push(3);
80-
81-
// Output verification would ideally be handled through a different means
82-
// but you can print as a basic check to confirm method runs without errors.
83-
stack.print();
84-
}
8573
}

src/test/java/com/thealgorithms/datastructures/trees/BinaryTreeTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thealgorithms.datastructures.trees;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.fail;
45

56
import org.junit.jupiter.api.Test;
67

@@ -35,7 +36,12 @@ void test2() {
3536
t.remove(5);
3637
t.remove(7);
3738

38-
assertEquals(t.getRoot().data, 9);
39+
// Checks whether the root is null before accessing date
40+
if (t.getRoot() != null) {
41+
assertEquals(t.getRoot().data, 9);
42+
} else {
43+
fail("The root node is null after removal.");
44+
}
3945
}
4046

4147
// checks that removing an unexistend node returns false

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy