Ü2: Testat bestanden

This commit is contained in:
Johannes Theiner 2018-11-20 13:08:18 +01:00
parent 6a57d69524
commit 528a4a8dab
2 changed files with 10 additions and 6 deletions

View File

@ -36,6 +36,7 @@ public class RingList<E> implements List<E> {
} }
private Wrapper getWrapper(int index) { private Wrapper getWrapper(int index) {
if(index == -1) return first;
Wrapper wRun; Wrapper wRun;
if (index < 0 || index >= size) { if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
@ -58,15 +59,15 @@ public class RingList<E> implements List<E> {
@Override @Override
public E remove(int index) { public E remove(int index) {
Wrapper wrapper = getWrapper(index - 1); Wrapper wrapper = getWrapper(index - 1);
E result = wrapper.succ.e;
wrapper.succ = wrapper.succ.succ; wrapper.succ = wrapper.succ.succ;
size--; size--;
return wrapper.succ.e; return result;
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
try { try {
int index = indexOf((E) o); int index = indexOf((E) o);
if(index == -1) return false; if(index == -1) return false;

View File

@ -1,4 +1,4 @@
package xyz.joethei.studium.algodat.vorlesung; package xyz.joethei.studium.algodat.praktikum;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import xyz.joethei.studium.algodat.praktikum.blatt2.List; 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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class Blatt2Test { class RingListTest {
@Test @Test
void add() { void add() {
@ -46,9 +46,12 @@ class Blatt2Test {
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
rList.add(i * 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()); 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 @Test