Hallo,
ich habe eine Klasse "Binärbaum" erstellt und möchte diese nun mittels JUnit 5 testen. Leider schlägt mein Test schon fehl, wenn ich lediglich die Methode get.Right (oder get.Left) teste. Ich bin mir sicher, dass die Methode get.Right richtig ist, da wir diese in den Vorlesung vorgegeben bekommen haben. Daher vermute ich, dass ich den Test falsch implementiere. Ich möchte verifizieren, dass c das rechte Kind von b ist.
So sieht meine Testklasse aus:
Dies ist meine Klasse des Binärsbaums:
Vielen Dank für jede Hilfe.
ich habe eine Klasse "Binärbaum" erstellt und möchte diese nun mittels JUnit 5 testen. Leider schlägt mein Test schon fehl, wenn ich lediglich die Methode get.Right (oder get.Left) teste. Ich bin mir sicher, dass die Methode get.Right richtig ist, da wir diese in den Vorlesung vorgegeben bekommen haben. Daher vermute ich, dass ich den Test falsch implementiere. Ich möchte verifizieren, dass c das rechte Kind von b ist.
So sieht meine Testklasse aus:
Java:
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test ;
public class IntBinTreeTest {
@Test
void test1() {
IntBinTree e = new IntBinTree(5);
IntBinTree d = new IntBinTree(4);
IntBinTree c = new IntBinTree(e,3,d);
IntBinTree a = new IntBinTree(1);
IntBinTree b = new IntBinTree(a,2,c);
assertEquals(c, b.getRight());
}
}
Dies ist meine Klasse des Binärsbaums:
Java:
public class IntBinTree {
private IntNode root;
public IntBinTree() {
this.root = null;
}
public IntBinTree(Integer content) {
this.root = new IntNode(content);
}
public IntBinTree(IntBinTree left, Integer content, IntBinTree right) {
this.root = new IntNode(content);
if (left != null) {
this.root.setLeft(left.root);
}
if (right != null) {
this.root.setRight(right.root);
}
}
private IntBinTree(IntNode root) {
this.root = root;
}
public boolean isEmpty() {
return this.root == null;
}
public Integer getValue() {
if(this.isEmpty()) {
return null;
}
return this.root.getContent();
}
public IntBinTree getLeft() {
if(this.isEmpty()) {
return null;
}
return new IntBinTree(this.root.getLeft());
}
public void setLeft(IntBinTree tree) {
if(this.isEmpty()) {
return;
}
this.root.setLeft(tree.root);
}
public IntBinTree getRight() {
if(this.isEmpty()) {
return null;
}
return new IntBinTree(this.root.getRight());
}
public void setRight(IntBinTree tree) {
if(this.isEmpty()) {
return;
}
this.root.setRight(tree.root);
}
Vielen Dank für jede Hilfe.