Tests für Blatt2

This commit is contained in:
Johannes Theiner 2018-11-15 16:17:52 +01:00
parent 2fbe9d5f68
commit b3fb099758
3 changed files with 43 additions and 1 deletions

View File

@ -91,6 +91,7 @@ public class Main {
while(iter.hasNext()) { while(iter.hasNext()) {
System.out.print(iter.next() + " "); System.out.print(iter.next() + " ");
} }
System.out.println(); System.out.println();

View File

@ -19,7 +19,7 @@ public class RingList<E> implements List<E> {
private Wrapper last; private Wrapper last;
private int size; private int size;
RingList() { public RingList() {
first = new Wrapper(null); first = new Wrapper(null);
last = first; last = first;
last.succ = first; last.succ = first;

View File

@ -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<Integer> 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<Integer> rList = new RingList<>();
for (int i = 1; i <= 10; i++) {
rList.add(i * i);
}
assertEquals(10, rList.size());
}
}