From 47bb83a98cf54f7c11c07bf7fa2f8a2b9486207c Mon Sep 17 00:00:00 2001 From: hertero Date: Thu, 1 Sep 2022 16:35:23 +0200 Subject: [PATCH] =?UTF-8?q?Schreiben=20weiterer=20Testf=C3=A4lle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SimpleLinkedList/.classpath | 7 +- .../src/solution/SimpleListTest90.java | 159 +++++++++++------- 2 files changed, 107 insertions(+), 59 deletions(-) diff --git a/SimpleLinkedList/.classpath b/SimpleLinkedList/.classpath index e770324..dbe3bbf 100644 --- a/SimpleLinkedList/.classpath +++ b/SimpleLinkedList/.classpath @@ -1,8 +1,11 @@ - + + + + + - diff --git a/SimpleLinkedList/src/solution/SimpleListTest90.java b/SimpleLinkedList/src/solution/SimpleListTest90.java index a53a297..186db56 100644 --- a/SimpleLinkedList/src/solution/SimpleListTest90.java +++ b/SimpleLinkedList/src/solution/SimpleListTest90.java @@ -1,92 +1,137 @@ package solution; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public abstract class SimpleListTest90 { - ISimpleList list; - ISimpleList> nodeList; - - protected Node nodeNull = new Node(null); - protected Node node0 = new Node(0); - protected Node node1 = new Node(1); - protected Node node2 = new Node(2); - protected Node node3 = new Node(3); - protected Node node4 = new Node(4); - - protected abstract ISimpleList getInstance1(); + ISimpleList list; - protected abstract ISimpleList> getInstance2(); + protected String nodeNull = null; + protected String node0 = "0"; + protected String node1 = "1"; + protected String node2 = "2"; + protected String node3 = "3"; + protected String node4 = "4"; + + protected abstract ISimpleList getInstance1(); + + protected void add2() { + list.add(node1); + list.add(node2); + } + + @BeforeAll + static void setUpBeforeClass() throws Exception { + } @BeforeEach - void setUp() throws Exception{ + void setUp() throws Exception { list = getInstance1(); - nodeList = getInstance2(); } - + @Test - void testAdd() { - - boolean actual = nodeList.add(node1); + public void testAdd1() { + boolean actual = list.add(node1); assertEquals(true, actual); } - + @Test - void testRemoveObject() { - nodeList.add(node1); - nodeList.add(node2); - nodeList.add(node3); - - boolean actual = nodeList.remove(node2); + public void testAdd2() { + add2(); + list.remove(node2); + list.add(node3); + list.add(node4); + String actual = list.get(2); + assertEquals(node3, actual); + } + + @Test + public void testRemoveObject() { + list.add(node1); + list.add(node2); + list.add(node3); + + boolean actual = list.remove(node2); assertEquals(true, actual); } - + + @Test + public void testRemoveSize() { + add2(); + list.remove(1); + int actual = list.size(); + assertEquals(1, actual); + } + @Test - void testContainsTrue() { - nodeList.add(node1); - nodeList.add(node2); - - boolean actual = nodeList.contains(node1); + public void testContainsTrue() { + add2(); + boolean actual = list.contains(node1); assertEquals(true, actual); } - + @Test - void testContainsFalse() { - nodeList.add(node1); - nodeList.add(node2); - - boolean actual = nodeList.contains(node3); + public void testContainsFalse() { + add2(); + boolean actual = list.contains(node3); assertEquals(false, actual); } - + @Test - void getNodeIndex() { - nodeList.add(node1); - nodeList.add(node2); - - Node actual = nodeList.get(1); + public void testForAll1() { + list.forAll(null); + assertEquals(true, true); + } + + @Test + public void getNodeIndex() { + add2(); + String actual = list.get(1); assertEquals(node2, actual); } - + @Test - void setNodeIndex() { - //TODO + public void setNodeIndex() { + add2(); + list.set(1, node3); + String actual = list.get(1); + assertEquals(node3, actual); } - + @Test - void testRemoveIndex() { - nodeList.add(node1); - nodeList.add(node2); - nodeList.add(node3); - - boolean actual = nodeList.remove(1); + public void testRemoveIndex() { + add2(); + list.add(node3); + boolean actual = list.remove(1); assertEquals(true, actual); } - + + @Test + public void testAddIndexException() { + try { + list.add(-1, node1); + list.get(0); + } catch (Exception e) { + assertEquals(true, e instanceof IndexOutOfBoundsException); + } + } + + @Test + public void testAddIndexSameSize() { + add2(); + list.add(2, node4); + String actual = list.get(2); + assertEquals(node4, actual); + } + @Test - void testAddIndex() { - //TODO + public void testAddIndexNewNode() { + add2(); + list.add(1, node3); + String actual = list.get(1); + assertEquals(node3, actual); } }