}
@Test
public void testDifference()
{
Range full = new Range(tok(-1), tok(-1));
int maxsize = 16;
mt.maxsize(maxsize);
MerkleTree mt2 = new MerkleTree(partitioner, fullRange(), RECOMMENDED_DEPTH, maxsize);
mt.init();
mt2.init();
// add dummy hashes to both trees
for (TreeRange range : mt.invalids())
range.addAll(new HIterator(range.right));
for (TreeRange range : mt2.invalids())
range.addAll(new HIterator(range.right));
TreeRange leftmost = null;
TreeRange middle = null;
mt.maxsize(maxsize + 2); // give some room for splitting
// split the leftmost
Iterator<TreeRange> ranges = mt.invalids();
leftmost = ranges.next();
mt.split(leftmost.right);
// set the hashes for the leaf of the created split
middle = mt.get(leftmost.right);
middle.hash("arbitrary!".getBytes());
mt.get(partitioner.midpoint(leftmost.left, leftmost.right)).hash("even more arbitrary!".getBytes());
// trees should disagree for (leftmost.left, middle.right]
List<TreeRange> diffs = MerkleTree.difference(mt, mt2);
assertEquals(diffs + " contains wrong number of differences:", 1, diffs.size());
assertTrue(diffs.contains(new Range(leftmost.left, middle.right)));
}