so, jetzt sollte wieder alles grün sein

This commit is contained in:
Johannes Theiner 2018-04-12 18:52:14 +02:00
parent 1996730d1c
commit 85ac78adf5
2 changed files with 9 additions and 2 deletions

View File

@ -1,11 +1,15 @@
package de.joethei.hs.java2.vorlesungen.binaryTree; package de.joethei.hs.java2.vorlesungen.binaryTree;
import java.util.logging.Logger;
public class Node<T> { public class Node<T> {
private T value; private T value;
private Node<T> left; private Node<T> left;
private Node<T> right; private Node<T> right;
private Logger logger = Logger.getLogger(getClass().getName());
public Node() { public Node() {
} }
@ -38,8 +42,9 @@ public class Node<T> {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof Node) { if (obj instanceof Node) {
Node node = (Node) obj; Node node = (Node) obj;
if(node.value.equals(this.value) && node.left == null && node.right == null) return true;
return node.value.equals(this.value) && node.left.equals(this.left) && node.right.equals(this.right); return node.value.equals(this.value) && node.left.equals(this.left) && node.right.equals(this.right);
} }
return false; return false;

View File

@ -25,9 +25,11 @@ public class VorlesungsTest {
Tree<Integer> tree = new Tree<>(new Node<>(45, new Node<>(14), new Node<>(16))); Tree<Integer> tree = new Tree<>(new Node<>(45, new Node<>(14), new Node<>(16)));
Node<Integer> node = new Node<>(45, new Node<>(14), new Node<>(16));
assertEquals(Integer.valueOf(45), tree.getRoot().getValue()); assertEquals(Integer.valueOf(45), tree.getRoot().getValue());
assertEquals(Integer.valueOf(14), tree.getRoot().getLeft().getValue()); assertEquals(Integer.valueOf(14), tree.getRoot().getLeft().getValue());
assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue()); assertEquals(Integer.valueOf(16), tree.getRoot().getRight().getValue());
assertEquals(new Node<Integer>(13, new Node<>(14), new Node<>(16)), new Node<Integer>(13, new Node<>(14), new Node<>(16)));
assertEquals(tree.getRoot(), node);
} }
} }