Skip to content

Commit c64d5ce

Browse files
author
Alex Klymenko
committed
checkstyle: fix comment formatting
1 parent 36eacc0 commit c64d5ce

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public T peek() {
5757
}
5858

5959
private void resize(int newSize) {
60-
@SuppressWarnings("unchecked")
61-
T[] newArray = (T[]) new Object[newSize];
60+
@SuppressWarnings("unchecked") T[] newArray = (T[]) new Object[newSize];
6261
System.arraycopy(stackArray, 0, newArray, 0, top + 1);
6362
stackArray = newArray;
6463
maxSize = newSize;
@@ -73,8 +72,7 @@ public boolean isEmpty() {
7372
return top == -1;
7473
}
7574

76-
@Override
77-
public void makeEmpty() { // Doesn't delete elements in the array but if you call
75+
@Override public void makeEmpty() { // Doesn't delete elements in the array but if you call
7876
top = -1; // push method after calling makeEmpty it will overwrite previous values
7977
}
8078

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class StackArrayTest {
1010

1111
@BeforeEach
1212
void setUp() {
13-
stack = new StackArray<>(5); // Initialize a stack with capacity of 5
13+
stack = new StackArray<>(5); // Initialize a stack with capacity of 5
1414
}
1515

1616
@Test
@@ -21,11 +21,11 @@ void testPushAndPop() {
2121
stack.push(4);
2222
stack.push(5);
2323

24-
Assertions.assertEquals(5, stack.pop()); // Stack follows LIFO, so 5 should be popped first
25-
Assertions.assertEquals(4, stack.pop()); // Next, 4 should be popped
26-
Assertions.assertEquals(3, stack.pop()); // Followed by 3
27-
Assertions.assertEquals(2, stack.pop()); // Then 2
28-
Assertions.assertEquals(1, stack.pop()); // Finally 1
24+
Assertions.assertEquals(5, stack.pop()); // Stack follows LIFO, so 5 should be popped first
25+
Assertions.assertEquals(4, stack.pop()); // Next, 4 should be popped
26+
Assertions.assertEquals(3, stack.pop()); // Followed by 3
27+
Assertions.assertEquals(2, stack.pop()); // Then 2
28+
Assertions.assertEquals(1, stack.pop()); // Finally 1
2929
}
3030

3131
@Test
@@ -34,34 +34,34 @@ void testPeek() {
3434
stack.push(20);
3535
stack.push(30);
3636

37-
Assertions.assertEquals(30, stack.peek()); // Peek should return 30, the top of the stack
38-
Assertions.assertEquals(3, stack.size()); // Size should remain 3 after peek
37+
Assertions.assertEquals(30, stack.peek()); // Peek should return 30, the top of the stack
38+
Assertions.assertEquals(3, stack.size()); // Size should remain 3 after peek
3939

4040
stack.pop();
41-
Assertions.assertEquals(20, stack.peek()); // After popping, peek should return 20
41+
Assertions.assertEquals(20, stack.peek()); // After popping, peek should return 20
4242
}
4343

4444
@Test
4545
void testIsEmpty() {
46-
Assertions.assertTrue(stack.isEmpty()); // Initially, the stack should be empty
46+
Assertions.assertTrue(stack.isEmpty()); // Initially, the stack should be empty
4747
stack.push(42);
48-
Assertions.assertFalse(stack.isEmpty()); // After pushing an element, the stack should not be empty
48+
Assertions.assertFalse(stack.isEmpty()); // After pushing an element, the stack should not be empty
4949
stack.pop();
50-
Assertions.assertTrue(stack.isEmpty()); // After popping the only element, the stack should be empty again
50+
Assertions.assertTrue(stack.isEmpty()); // After popping the only element, the stack should be empty again
5151
}
5252

5353
@Test
5454
void testResizeOnPush() {
55-
StackArray<Integer> smallStack = new StackArray<>(2); // Start with a small stack size
55+
StackArray<Integer> smallStack = new StackArray<>(2); // Start with a small stack size
5656
smallStack.push(1);
5757
smallStack.push(2);
58-
Assertions.assertTrue(smallStack.isFull()); // Initially, the stack should be full
58+
Assertions.assertTrue(smallStack.isFull()); // Initially, the stack should be full
5959

60-
smallStack.push(3); // This push should trigger a resize
61-
Assertions.assertFalse(smallStack.isFull()); // The stack should no longer be full after resize
62-
Assertions.assertEquals(3, smallStack.size()); // Size should be 3 after pushing 3 elements
60+
smallStack.push(3); // This push should trigger a resize
61+
Assertions.assertFalse(smallStack.isFull()); // The stack should no longer be full after resize
62+
Assertions.assertEquals(3, smallStack.size()); // Size should be 3 after pushing 3 elements
6363

64-
Assertions.assertEquals(3, smallStack.pop()); // LIFO behavior check
64+
Assertions.assertEquals(3, smallStack.pop()); // LIFO behavior check
6565
Assertions.assertEquals(2, smallStack.pop());
6666
Assertions.assertEquals(1, smallStack.pop());
6767
}
@@ -74,13 +74,13 @@ void testResizeOnPop() {
7474
stack.push(3);
7575
stack.push(4);
7676

77-
stack.pop(); // Removing elements should trigger a resize when less than 1/4 of the stack is used
77+
stack.pop(); // Removing elements should trigger a resize when less than 1/4 of the stack is used
7878
stack.pop();
7979
stack.pop();
80-
Assertions.assertEquals(1, stack.size()); // After popping, only one element should remain
80+
Assertions.assertEquals(1, stack.size()); // After popping, only one element should remain
8181

8282
stack.pop();
83-
Assertions.assertTrue(stack.isEmpty()); // The stack should be empty now
83+
Assertions.assertTrue(stack.isEmpty()); // The stack should be empty now
8484
}
8585

8686
@Test
@@ -90,32 +90,32 @@ void testMakeEmpty() {
9090
stack.push(3);
9191
stack.makeEmpty();
9292

93-
Assertions.assertTrue(stack.isEmpty()); // The stack should be empty after calling makeEmpty
94-
Assertions.assertThrows(IllegalStateException.class, stack::pop); // Popping from empty stack should throw exception
93+
Assertions.assertTrue(stack.isEmpty()); // The stack should be empty after calling makeEmpty
94+
Assertions.assertThrows(IllegalStateException.class, stack::pop); // Popping from empty stack should throw exception
9595
}
9696

9797
@Test
9898
void testPopEmptyStackThrowsException() {
99-
Assertions.assertThrows(IllegalStateException.class, stack::pop); // Popping from an empty stack should throw an exception
99+
Assertions.assertThrows(IllegalStateException.class, stack::pop); // Popping from an empty stack should throw an exception
100100
}
101101

102102
@Test
103103
void testPeekEmptyStackThrowsException() {
104-
Assertions.assertThrows(IllegalStateException.class, stack::peek); // Peeking into an empty stack should throw an exception
104+
Assertions.assertThrows(IllegalStateException.class, stack::peek); // Peeking into an empty stack should throw an exception
105105
}
106106

107107
@Test
108108
void testConstructorWithInvalidSizeThrowsException() {
109-
Assertions.assertThrows(IllegalArgumentException.class, () -> new StackArray<>(0)); // Size 0 is invalid
110-
Assertions.assertThrows(IllegalArgumentException.class, () -> new StackArray<>(-5)); // Negative size is invalid
109+
Assertions.assertThrows(IllegalArgumentException.class, () -> new StackArray<>(0)); // Size 0 is invalid
110+
Assertions.assertThrows(IllegalArgumentException.class, () -> new StackArray<>(-5)); // Negative size is invalid
111111
}
112112

113113
@Test
114114
void testDefaultConstructor() {
115-
StackArray<Integer> defaultStack = new StackArray<>(); // Using default constructor
116-
Assertions.assertEquals(0, defaultStack.size()); // Initially, size should be 0
115+
StackArray<Integer> defaultStack = new StackArray<>(); // Using default constructor
116+
Assertions.assertEquals(0, defaultStack.size()); // Initially, size should be 0
117117

118118
defaultStack.push(1);
119-
Assertions.assertEquals(1, defaultStack.size()); // After pushing, size should be 1
119+
Assertions.assertEquals(1, defaultStack.size()); // After pushing, size should be 1
120120
}
121121
}

0 commit comments

Comments
 (0)