### Question:
MerkleTree { public void appendLeaf(Node node) { int size = nodes.size(); if (size <= 2) { nodes.add(node); if (size == 0) { nodes.add(new Node(node.getValue())); } else { updateHash(0); } } else { int parentIndex = getParentIndex(size); Node nodeToReplace = nodes.get(parentIndex); Node emptyNode = new Node(null); nodes.set(parentIndex, emptyNode); nodes.add(nodeToReplace); nodes.add(node); updateHash(parentIndex); } } MerkleTree(MessageDigest digest);  MerkleTree(MessageDigest digest, List<byte[]> dataList); List<Node> getNodes(); List<Node> getLeaves(); Node getRoot(); void appendLeaf(Node node); void appendLeaves(Node[] nodes); void appendLeaf(byte[] value); void appendLeaves(byte[][] values); void appendHashedLeaves(byte[][] hashes); @Override boolean equals(Object o);  }### Answer:
@Test public void testAppendAndBuildTreesEquals() { int counter = 1_000; List<byte[]> bytesToAdd = new ArrayList<>(); MerkleTree appendTree = new MerkleTree(sha256()); Random random = new Random(); while (counter-- > 0) { byte[] bytes = new byte[256]; random.nextBytes(bytes); bytesToAdd.add(bytes); appendTree.appendLeaf(bytes); } MerkleTree builtTree = new MerkleTree(sha256(), bytesToAdd); Assertions.assertEquals(appendTree, builtTree); }