change package name and update print method
This commit is contained in:
parent
6dde04eed2
commit
19e12cad57
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.binarytree;
|
package com.baeldung.printbinarytree;
|
||||||
|
|
||||||
public class BinaryTreeModel {
|
public class BinaryTreeModel {
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
package com.baeldung.binarytree;
|
package com.baeldung.printbinarytree;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
public class BinaryTreePrinter {
|
public class BinaryTreePrinter {
|
||||||
|
|
||||||
@ -54,8 +56,8 @@ public class BinaryTreePrinter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print() {
|
public void print(PrintStream os) {
|
||||||
System.out.print(traversePreOrder(tree));
|
os.print(traversePreOrder(tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.binarytree;
|
package com.baeldung.printbinarytree;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ -10,6 +10,9 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.printbinarytree.BinaryTreeModel;
|
||||||
|
import com.baeldung.printbinarytree.BinaryTreePrinter;
|
||||||
|
|
||||||
public class PrintingBinaryTreeModelUnitTest {
|
public class PrintingBinaryTreeModelUnitTest {
|
||||||
|
|
||||||
private BinaryTreeModel balanced;
|
private BinaryTreeModel balanced;
|
||||||
@ -129,7 +132,7 @@ public class PrintingBinaryTreeModelUnitTest {
|
|||||||
expected.append(" ├──node5").append("\n");
|
expected.append(" ├──node5").append("\n");
|
||||||
expected.append(" └──node6");
|
expected.append(" └──node6");
|
||||||
|
|
||||||
new BinaryTreePrinter(balanced).print();
|
new BinaryTreePrinter(balanced).print(System.out);
|
||||||
|
|
||||||
assertEquals(expected.toString(), output.toString());
|
assertEquals(expected.toString(), output.toString());
|
||||||
}
|
}
|
||||||
@ -148,7 +151,7 @@ public class PrintingBinaryTreeModelUnitTest {
|
|||||||
expected.append("│ └──node8").append("\n");
|
expected.append("│ └──node8").append("\n");
|
||||||
expected.append("└──node2");
|
expected.append("└──node2");
|
||||||
|
|
||||||
new BinaryTreePrinter(leftSkewed).print();
|
new BinaryTreePrinter(leftSkewed).print(System.out);
|
||||||
|
|
||||||
assertEquals(expected.toString(), output.toString());
|
assertEquals(expected.toString(), output.toString());
|
||||||
}
|
}
|
||||||
@ -167,7 +170,7 @@ public class PrintingBinaryTreeModelUnitTest {
|
|||||||
expected.append(" └──node7").append("\n");
|
expected.append(" └──node7").append("\n");
|
||||||
expected.append(" └──node8");
|
expected.append(" └──node8");
|
||||||
|
|
||||||
new BinaryTreePrinter(rightSkewed).print();
|
new BinaryTreePrinter(rightSkewed).print(System.out);
|
||||||
|
|
||||||
assertEquals(expected.toString(), output.toString());
|
assertEquals(expected.toString(), output.toString());
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user