public void testAncestorsAndChildren() throws Exception {
final HgRepository repo = Configuration.get().find("test-annotate");
Nodeid[] allRevs = RepoUtils.allRevisions(repo);
HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog());
parentHelper.init();
final RevisionSet complete = new RevisionSet(allRevs);
Nodeid[] nodes = {};
// children
errorCollector.assertTrue(new RevisionSet(nodes).children(parentHelper).isEmpty());
Nodeid[] nodes1 = { allRevs[8], allRevs[9] };
Nodeid[] nodes2 = { allRevs[4] };
errorCollector.assertEquals(new RevisionSet(nodes1), new RevisionSet(nodes2).children(parentHelper));
Nodeid[] nodes3 = { allRevs[8], allRevs[9], allRevs[4], allRevs[5], allRevs[7] };
// default branch and no-merge branch both from r2
RevisionSet s1 = new RevisionSet(nodes3);
Nodeid[] nodes4 = { allRevs[2] };
errorCollector.assertEquals(s1, new RevisionSet(nodes4).children(parentHelper));
Nodeid[] nodes5 = { allRevs[0], allRevs[1] };
// ancestors
RevisionSet fromR2 = complete.subtract(new RevisionSet(nodes5));
Nodeid[] nodes6 = { allRevs[9], allRevs[5], allRevs[7], allRevs[8] };
// no-merge branch and r9 are not in ancestors of r8 (as well as r8 itself)
RevisionSet s3 = fromR2.subtract(new RevisionSet(nodes6));
Nodeid[] nodes7 = { allRevs[8] };
errorCollector.assertEquals(s3, fromR2.ancestors(new RevisionSet(nodes7), parentHelper));
Nodeid[] nodes8 = { allRevs[5], allRevs[7] };
// ancestors of no-merge branch
RevisionSet branchNoMerge = new RevisionSet(nodes8);
Nodeid[] nodes9 = { allRevs[0], allRevs[1], allRevs[2] };
errorCollector.assertEquals(new RevisionSet(nodes9), complete.ancestors(branchNoMerge, parentHelper));
Nodeid[] nodes10 = { allRevs[2] };
errorCollector.assertEquals(new RevisionSet(nodes10), fromR2.ancestors(branchNoMerge, parentHelper));
}