From 0f808a371bd8a71baa3a84ad15b2e99ceefb83b7 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 27 Sep 2022 13:02:56 +0200 Subject: [PATCH] Add tests for the `ListStack` class --- .../java/ch/nuth/zhaw/exbox/ADS1_2_test.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/src/test/java/ch/nuth/zhaw/exbox/ADS1_2_test.java diff --git a/app/src/test/java/ch/nuth/zhaw/exbox/ADS1_2_test.java b/app/src/test/java/ch/nuth/zhaw/exbox/ADS1_2_test.java new file mode 100644 index 0000000..0b23b8a --- /dev/null +++ b/app/src/test/java/ch/nuth/zhaw/exbox/ADS1_2_test.java @@ -0,0 +1,52 @@ +package ch.nuth.zhaw.exbox; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +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.assertTrue; + +public class ADS1_2_test { + ListStack stack; + + @BeforeEach + public void setUp() { + stack = new ListStack(); + } + + @Test + public void testPush1() { + stack.push("A"); + Object o = stack.pop(); + assertEquals("A", o); + } + + @Test + public void testPush2() { + stack.push("A"); + stack.push("B"); + assertEquals("B", stack.pop()); + assertEquals("A", stack.pop()); + } + + @Test + public void testIsEmpty() { + assertTrue(stack.isEmpty()); + stack.push("A"); + assertFalse(stack.isEmpty()); + stack.pop(); + assertTrue(stack.isEmpty()); + } + + @Test + public void testIsFull() { + assertFalse(stack.isFull()); + } + + @Test + public void testEmptyPop() { + assertNull(stack.pop()); + } +}