package com.dataStructures; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.EmptyStackException; class StackTest { @Test void testEmpty() { Stack myStack = new Stack<>(); boolean isEmpty = myStack.empty(); Assertions.assertTrue(isEmpty); myStack.push(10); isEmpty = myStack.empty(); Assertions.assertFalse(isEmpty); } @Test void testPeekWithoutElements() { Assertions.assertThrows(EmptyStackException.class, () -> { Stack myStack = new Stack<>(); myStack.peek(); }); } @Test void testPeekWithElements() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); myStack.push(40); Assertions.assertEquals(40, myStack.peek()); } @Test void testPopWithoutElements() { Assertions.assertThrows(EmptyStackException.class, () -> { Stack myStack = new Stack<>(); myStack.pop(); }); } @Test void testPopWithElements() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); myStack.push(40); myStack.push(50); Assertions.assertEquals(50, myStack.pop()); } @Test void testPushWithinInitialCapacity() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); myStack.push(40); myStack.push(50); myStack.push(60); myStack.push(70); myStack.push(80); myStack.push(90); myStack.push(100); Assertions.assertEquals(10, myStack.size()); } @Test void testPushOutsideInitialCapacity() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); myStack.push(40); myStack.push(50); myStack.push(60); myStack.push(70); myStack.push(80); myStack.push(90); myStack.push(100); myStack.push(110); Assertions.assertEquals(11, myStack.size()); } @Test void testSearchWithObjectUnavailable() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); Assertions.assertEquals(-1, myStack.search(50)); } @Test void testSearchWithObjectAvailable() { Stack myStack = new Stack<>(); myStack.push(10); myStack.push(20); myStack.push(30); Assertions.assertEquals(3, myStack.search(10)); } }