Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Reduced static imports
  • Loading branch information
Andruid929 committed Apr 14, 2026
commit 259fbfa4c82fd261e549d2f05abffe9a347e1fc8
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.thealgorithms.stacks;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -22,48 +17,48 @@ public void instantiateLinkedStack() {

@Test
void peek() {
assertNull(linkedStack.peek());
Assertions.assertNull(linkedStack.peek());

linkedStack.push(10);
linkedStack.push(20);
linkedStack.push(30);

assertEquals(30, linkedStack.peek());
Assertions.assertEquals(30, linkedStack.peek());
}

@Test
void pop() {
linkedStack.push(3);
linkedStack.push(6);

assertEquals(6, linkedStack.pop());
assertEquals(3, linkedStack.peek());
Assertions.assertEquals(6, linkedStack.pop());
Assertions.assertEquals(3, linkedStack.peek());

linkedStack.pop();

assertThrows(NoSuchElementException.class, () -> linkedStack.pop()); //Cannot pop from an empty stack
Assertions.assertThrows(NoSuchElementException.class, () -> linkedStack.pop()); //Cannot pop from an empty stack
}

@Test
void push() {
linkedStack.push(12);

assertEquals(12, linkedStack.peek());
Assertions.assertEquals(12, linkedStack.peek());

linkedStack.push(15);
linkedStack.push(17);

assertEquals(17, linkedStack.peek());
Assertions.assertEquals(17, linkedStack.peek());

}

@Test
void isEmpty() {
assertTrue(linkedStack.isEmpty());
Assertions.assertTrue(linkedStack.isEmpty());

linkedStack.push(1);

assertFalse(linkedStack.isEmpty());
Assertions.assertFalse(linkedStack.isEmpty());
}

@Test
Expand All @@ -73,11 +68,11 @@ void size() {
linkedStack.push(3);
linkedStack.push(4);

assertEquals(4, linkedStack.size());
Assertions.assertEquals(4, linkedStack.size());

linkedStack.pop();
linkedStack.pop();

assertEquals(2, linkedStack.size());
Assertions.assertEquals(2, linkedStack.size());
}
}
Loading