import org.junit.jupiter.api.Test; import java.util.List; import static org.junit.jupiter.api.Assertions.*; class RegeneratorTest { private final LinkedBinaryTree bt = new LinkedBinaryTree<>(3, new LinkedBinaryTree<>(4, new LinkedBinaryTree<>(34), null), new LinkedBinaryTree<>(5, new LinkedBinaryTree<>(25), new LinkedBinaryTree<>(53, new LinkedBinaryTree<>(2), new LinkedBinaryTree<>()) ) ); private final IterativeTraversals it = new IterativeTraversals(); @Test void test_regenerator_integer_tree() { List postOrder = it.postOrder(bt); List inOrder = it.inOrder(bt); LinkedBinaryTree regeneratedTree = Regenerator.postAndIn(postOrder, inOrder); assertEquals(postOrder, it.postOrder(regeneratedTree)); assertEquals(inOrder, it.inOrder(regeneratedTree)); } private final LinkedBinaryTree bt2 = new LinkedBinaryTree<>("Hi!", new LinkedBinaryTree<>("Bye!", new LinkedBinaryTree<>("Stre!"), new LinkedBinaryTree<>("Oui!", null, new LinkedBinaryTree<>("Uala!"))), new LinkedBinaryTree<>("Ecs!", new LinkedBinaryTree<>("Lolo"), new LinkedBinaryTree<>("lala", new LinkedBinaryTree<>("Ei!", new LinkedBinaryTree<>("Prra!"), null), new LinkedBinaryTree<>()) ) ); @Test void test_regenerator_string_tree(){ List postOrder = it.postOrder(bt2); List inOrder = it.inOrder(bt2); LinkedBinaryTree regeneratedTree = Regenerator.postAndIn(postOrder, inOrder); assertEquals(postOrder, it.postOrder(regeneratedTree)); assertEquals(inOrder, it.inOrder(regeneratedTree)); } private final LinkedBinaryTree bt3 = new LinkedBinaryTree<>(3.5465423, new LinkedBinaryTree<>(4.5465), new LinkedBinaryTree<>(2.5431) ); @Test void test_regenerator_double_tree(){ List postOrder = it.postOrder(bt3); List inOrder = it.inOrder(bt3); LinkedBinaryTree regeneratedTree = Regenerator.postAndIn(postOrder, inOrder); assertEquals(postOrder, it.postOrder(regeneratedTree)); assertEquals(inOrder, it.inOrder(regeneratedTree)); } }