Erster JUnitTest
parent
0dc80b3b47
commit
3cfcc9d9c1
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
public class Knoten {
|
public class Knoten {
|
||||||
|
|
||||||
|
private static final Exception IndexOutOfBoundsException = null;
|
||||||
private int wert;
|
private int wert;
|
||||||
private Knoten nachfolger;
|
private Knoten nachfolger;
|
||||||
|
|
||||||
|
|
@ -19,13 +20,41 @@ public class Knoten {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void auslesenAnPos(int pos) {
|
public int auslesenAnPos(int pos) throws Exception {
|
||||||
if(pos >0 && this.nachfolger != null) {
|
pos--;
|
||||||
nachfolger.auslesenAnPos(pos--);
|
if(nachfolger==null && pos>1) {
|
||||||
|
throw IndexOutOfBoundsException;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(pos >0 ) {
|
||||||
|
nachfolger.auslesenAnPos(pos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.wert;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void loeschenAnPos(int pos) throws Exception{
|
||||||
|
if(this.nachfolger==null) {
|
||||||
|
throw IndexOutOfBoundsException;
|
||||||
|
}
|
||||||
|
if(pos>1) {
|
||||||
|
this.nachfolger = nachfolger.nachfolger;
|
||||||
}else {
|
}else {
|
||||||
System.out.println(this.wert);
|
pos --;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWert() {return this.wert;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// End of Class
|
// End of Class
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ public class LinkedList {
|
||||||
kopf.einfuegenAmEnde(wert);
|
kopf.einfuegenAmEnde(wert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void auslesenAnPos(int pos) throws Exception {
|
public int auslesenAnPos(int pos) throws Exception {
|
||||||
|
|
||||||
kopf.auslesenAnPos(pos);
|
return kopf.auslesenAnPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loeschenAnPos(int pos) throws Exception {
|
public void loeschenAnPos(int pos) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.function.ThrowingRunnable;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class LinkedListTest {
|
||||||
|
|
||||||
|
private static final ThrowingRunnable IndexOutOfBoundsException = null;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test() throws Exception {
|
||||||
|
LinkedList L = new LinkedList(11);
|
||||||
|
L.einfuegenAmEnde(10);
|
||||||
|
L.einfuegenAmEnde(9);
|
||||||
|
L.einfuegenAmEnde(8);
|
||||||
|
L.einfuegenAmEnde(7);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LinkedList R = new LinkedList(10);
|
||||||
|
R.einfuegenAmEnde(3);
|
||||||
|
Assert.assertEquals(3, R.auslesenAnPos(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue