File tree 3 files changed +7
-24
lines changed
main/java/com/thealgorithms/datastructures/stacks
test/java/com/thealgorithms/datastructures
3 files changed +7
-24
lines changed Original file line number Diff line number Diff line change @@ -95,15 +95,4 @@ public boolean isEmpty() {
95
95
public int size () {
96
96
return size ;
97
97
}
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
- }
109
98
}
Original file line number Diff line number Diff line change @@ -70,16 +70,4 @@ void testSize() {
70
70
stack .pop ();
71
71
assertEquals (0 , stack .size (), "Size should be 0 after popping all elements." );
72
72
}
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
- }
85
73
}
Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .datastructures .trees ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .fail ;
4
5
5
6
import org .junit .jupiter .api .Test ;
6
7
@@ -35,7 +36,12 @@ void test2() {
35
36
t .remove (5 );
36
37
t .remove (7 );
37
38
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
+ }
39
45
}
40
46
41
47
// checks that removing an unexistend node returns false
You can’t perform that action at this time.
0 commit comments