From b3fb0997586f86bb1b1d07d50bc558c15d33694e Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 15 Nov 2018 16:17:52 +0100 Subject: [PATCH] =?UTF-8?q?Tests=20f=C3=BCr=20Blatt2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algodat/praktikum/blatt2/Main.java | 1 + .../algodat/praktikum/blatt2/RingList.java | 2 +- .../studium/algodat/vorlesung/Blatt2Test.java | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java index 5a63623..0f4df3b 100644 --- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java +++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/Main.java @@ -91,6 +91,7 @@ public class Main { while(iter.hasNext()) { System.out.print(iter.next() + " "); } + System.out.println(); diff --git a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java index 886685c..860c3af 100644 --- a/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java +++ b/src/main/java/xyz/joethei/studium/algodat/praktikum/blatt2/RingList.java @@ -19,7 +19,7 @@ public class RingList implements List { private Wrapper last; private int size; - RingList() { + public RingList() { first = new Wrapper(null); last = first; last.succ = first; diff --git a/src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java b/src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java new file mode 100644 index 0000000..7c1d860 --- /dev/null +++ b/src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java @@ -0,0 +1,41 @@ +package xyz.joethei.studium.algodat.vorlesung; + +import org.junit.jupiter.api.Test; +import xyz.joethei.studium.algodat.praktikum.blatt2.List; +import xyz.joethei.studium.algodat.praktikum.blatt2.RingList; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class Blatt2Test { + + @Test + void add() { + List rList = new RingList<>(); + for (int i = 1; i <= 10; i++) { + rList.add(i * i); + } + assertEquals(Optional.of(1), Optional.of(rList.get(0))); + assertEquals(Optional.of(4), Optional.of(rList.get(1))); + assertEquals(Optional.of(9), Optional.of(rList.get(2))); + assertEquals(Optional.of(16), Optional.of(rList.get(3))); + assertEquals(Optional.of(25), Optional.of(rList.get(4))); + assertEquals(Optional.of(36), Optional.of(rList.get(5))); + assertEquals(Optional.of(49), Optional.of(rList.get(6))); + assertEquals(Optional.of(64), Optional.of(rList.get(7))); + assertEquals(Optional.of(81), Optional.of(rList.get(8))); + assertEquals(Optional.of(100), Optional.of(rList.get(9))); + } + + @Test + void size() { + List rList = new RingList<>(); + for (int i = 1; i <= 10; i++) { + rList.add(i * i); + } + assertEquals(10, rList.size()); + } + + +} \ No newline at end of file