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 273863e..13bba47 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 @@ -36,6 +36,7 @@ public class RingList implements List { } private Wrapper getWrapper(int index) { + if(index == -1) return first; Wrapper wRun; if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); @@ -58,15 +59,15 @@ public class RingList implements List { @Override public E remove(int index) { Wrapper wrapper = getWrapper(index - 1); + E result = wrapper.succ.e; wrapper.succ = wrapper.succ.succ; size--; - return wrapper.succ.e; + return result; } @Override public boolean remove(Object o) { - try { int index = indexOf((E) o); if(index == -1) return false; diff --git a/src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java b/src/test/java/xyz/joethei/studium/algodat/praktikum/RingListTest.java similarity index 86% rename from src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java rename to src/test/java/xyz/joethei/studium/algodat/praktikum/RingListTest.java index 3b0b3a8..ca35165 100644 --- a/src/test/java/xyz/joethei/studium/algodat/vorlesung/Blatt2Test.java +++ b/src/test/java/xyz/joethei/studium/algodat/praktikum/RingListTest.java @@ -1,4 +1,4 @@ -package xyz.joethei.studium.algodat.vorlesung; +package xyz.joethei.studium.algodat.praktikum; import org.junit.jupiter.api.Test; import xyz.joethei.studium.algodat.praktikum.blatt2.List; @@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -class Blatt2Test { +class RingListTest { @Test void add() { @@ -46,9 +46,12 @@ class Blatt2Test { for (int i = 1; i <= 10; i++) { rList.add(i * i); } - assertEquals(Optional.of(49), Optional.ofNullable(rList.remove(5))); + assertEquals(Optional.of(1), Optional.of(rList.remove(0))); assertEquals(9, rList.size()); - assertTrue(rList.get(5) != 36); + assertEquals(Optional.of(36), Optional.of(rList.remove(4))); + assertEquals(8, rList.size()); + assertEquals(Optional.of(true), Optional.of(rList.remove((Integer) 100))); + assertTrue(rList.get(4) != 36); } @Test