Skip to content

testing: improve StackArrayTest #6424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,62 @@ void testToString() {
stack.push(3);
Assertions.assertEquals("StackArray [1, 2, 3]", stack.toString());
}

@Test
void testSingleElementOperations() {
// Test operations with a single element
stack.push(2);
Assertions.assertEquals(1, stack.size());
Assertions.assertFalse(stack.isEmpty());
Assertions.assertEquals(2, stack.peek());
Assertions.assertEquals(2, stack.pop());
Assertions.assertTrue(stack.isEmpty());
}

@Test
void testAlternatingPushPop() {
// Test alternating push and pop operations
stack.push(1);
Assertions.assertEquals(1, stack.pop());

stack.push(2);
stack.push(3);
Assertions.assertEquals(3, stack.pop());

stack.push(4);
Assertions.assertEquals(4, stack.pop());
Assertions.assertEquals(2, stack.pop());
Assertions.assertTrue(stack.isEmpty());
}

@Test
void testPushNullElements() {
// Test pushing null values
stack.push(null);
Assertions.assertEquals(1, stack.size());
Assertions.assertNull(stack.peek());
Assertions.assertNull(stack.pop());

// Mix null and non-null values
stack.push(1);
stack.push(null);
stack.push(2);

Assertions.assertEquals(2, stack.pop());
Assertions.assertNull(stack.pop());
Assertions.assertEquals(1, stack.pop());
}

@Test
void testWithDifferentDataTypes() {
// Test with String type
StackArray<String> stringStack = new StackArray<>(3);
stringStack.push("first");
stringStack.push("second");
stringStack.push("third");

Assertions.assertEquals("third", stringStack.pop());
Assertions.assertEquals("second", stringStack.peek());
Assertions.assertEquals(2, stringStack.size());
}
}
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