Mercurial > hg
changeset 18079:b3ba69692f8a
ancestor: move missingancestors doctest out into a separate file
This is in preparation for upcoming patches which will reuse the same graph
for tests.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 11 Dec 2012 14:47:33 -0800 |
parents | 3d1dc7aeca39 |
children | 486bfb200b3f |
files | mercurial/ancestor.py tests/test-ancestor.py tests/test-ancestor.py.out |
diffstat | 3 files changed, 110 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ancestor.py Sun Dec 16 23:02:54 2012 -0600 +++ b/mercurial/ancestor.py Tue Dec 11 14:47:33 2012 -0800 @@ -101,88 +101,6 @@ revs and bases should both be iterables. pfunc must return a list of parent revs for a given revs. - - graph is a dict of child->parent adjacency lists for this graph: - o 13 - | - | o 12 - | | - | | o 11 - | | |\ - | | | | o 10 - | | | | | - | o---+ | 9 - | | | | | - o | | | | 8 - / / / / - | | o | 7 - | | | | - o---+ | 6 - / / / - | | o 5 - | |/ - | o 4 - | | - o | 3 - | | - | o 2 - |/ - o 1 - | - o 0 - >>> graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], - ... 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], - ... 13: [8]} - >>> pfunc = graph.get - - Empty revs - >>> missingancestors([], [1], pfunc) - [] - >>> missingancestors([], [], pfunc) - [] - - If bases is empty, it's the same as if it were [nullrev] - >>> missingancestors([12], [], pfunc) - [0, 1, 2, 4, 6, 7, 9, 12] - - Trivial case: revs == bases - >>> missingancestors([0], [0], pfunc) - [] - >>> missingancestors([4, 5, 6], [6, 5, 4], pfunc) - [] - - With nullrev - >>> missingancestors([-1], [12], pfunc) - [] - >>> missingancestors([12], [-1], pfunc) - [0, 1, 2, 4, 6, 7, 9, 12] - - 9 is a parent of 12. 7 is a parent of 9, so an ancestor of 12. 6 is an - ancestor of 12 but not of 7. - >>> missingancestors([12], [9], pfunc) - [12] - >>> missingancestors([9], [12], pfunc) - [] - >>> missingancestors([12, 9], [7], pfunc) - [6, 9, 12] - >>> missingancestors([7, 6], [12], pfunc) - [] - - More complex cases - >>> missingancestors([10], [11, 12], pfunc) - [5, 10] - >>> missingancestors([11], [10], pfunc) - [3, 7, 11] - >>> missingancestors([11], [10, 12], pfunc) - [3, 11] - >>> missingancestors([12], [10], pfunc) - [6, 7, 9, 12] - >>> missingancestors([12], [11], pfunc) - [6, 9, 12] - >>> missingancestors([10, 11, 12], [13], pfunc) - [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12] - >>> missingancestors([13], [10, 11, 12], pfunc) - [8, 13] """ revsvisit = set(revs)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-ancestor.py Tue Dec 11 14:47:33 2012 -0800 @@ -0,0 +1,74 @@ +from mercurial import ancestor + +# graph is a dict of child->parent adjacency lists for this graph: +# o 13 +# | +# | o 12 +# | | +# | | o 11 +# | | |\ +# | | | | o 10 +# | | | | | +# | o---+ | 9 +# | | | | | +# o | | | | 8 +# / / / / +# | | o | 7 +# | | | | +# o---+ | 6 +# / / / +# | | o 5 +# | |/ +# | o 4 +# | | +# o | 3 +# | | +# | o 2 +# |/ +# o 1 +# | +# o 0 + +graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], + 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], + 13: [8]} +pfunc = graph.get + +def runmissingancestors(revs, bases): + print "%% ancestors of %s and not of %s" % (revs, bases) + print ancestor.missingancestors(revs, bases, pfunc) + +def test_missingancestors(): + # Empty revs + runmissingancestors([], [1]) + runmissingancestors([], []) + + # If bases is empty, it's the same as if it were [nullrev] + runmissingancestors([12], []) + + # Trivial case: revs == bases + runmissingancestors([0], [0]) + runmissingancestors([4, 5, 6], [6, 5, 4]) + + # With nullrev + runmissingancestors([-1], [12]) + runmissingancestors([12], [-1]) + + # 9 is a parent of 12. 7 is a parent of 9, so an ancestor of 12. 6 is an + # ancestor of 12 but not of 7. + runmissingancestors([12], [9]) + runmissingancestors([9], [12]) + runmissingancestors([12, 9], [7]) + runmissingancestors([7, 6], [12]) + + # More complex cases + runmissingancestors([10], [11, 12]) + runmissingancestors([11], [10]) + runmissingancestors([11], [10, 12]) + runmissingancestors([12], [10]) + runmissingancestors([12], [11]) + runmissingancestors([10, 11, 12], [13]) + runmissingancestors([13], [10, 11, 12]) + +if __name__ == '__main__': + test_missingancestors()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-ancestor.py.out Tue Dec 11 14:47:33 2012 -0800 @@ -0,0 +1,36 @@ +% ancestors of [] and not of [1] +[] +% ancestors of [] and not of [] +[] +% ancestors of [12] and not of [] +[0, 1, 2, 4, 6, 7, 9, 12] +% ancestors of [0] and not of [0] +[] +% ancestors of [4, 5, 6] and not of [6, 5, 4] +[] +% ancestors of [-1] and not of [12] +[] +% ancestors of [12] and not of [-1] +[0, 1, 2, 4, 6, 7, 9, 12] +% ancestors of [12] and not of [9] +[12] +% ancestors of [9] and not of [12] +[] +% ancestors of [12, 9] and not of [7] +[6, 9, 12] +% ancestors of [7, 6] and not of [12] +[] +% ancestors of [10] and not of [11, 12] +[5, 10] +% ancestors of [11] and not of [10] +[3, 7, 11] +% ancestors of [11] and not of [10, 12] +[3, 11] +% ancestors of [12] and not of [10] +[6, 7, 9, 12] +% ancestors of [12] and not of [11] +[6, 9, 12] +% ancestors of [10, 11, 12] and not of [13] +[0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12] +% ancestors of [13] and not of [10, 11, 12] +[8, 13]