comparison tests/test-ancestor.py @ 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
children f7f8159caad3
comparison
equal deleted inserted replaced
18078:3d1dc7aeca39 18079:b3ba69692f8a
1 from mercurial import ancestor
2
3 # graph is a dict of child->parent adjacency lists for this graph:
4 # o 13
5 # |
6 # | o 12
7 # | |
8 # | | o 11
9 # | | |\
10 # | | | | o 10
11 # | | | | |
12 # | o---+ | 9
13 # | | | | |
14 # o | | | | 8
15 # / / / /
16 # | | o | 7
17 # | | | |
18 # o---+ | 6
19 # / / /
20 # | | o 5
21 # | |/
22 # | o 4
23 # | |
24 # o | 3
25 # | |
26 # | o 2
27 # |/
28 # o 1
29 # |
30 # o 0
31
32 graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4],
33 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9],
34 13: [8]}
35 pfunc = graph.get
36
37 def runmissingancestors(revs, bases):
38 print "%% ancestors of %s and not of %s" % (revs, bases)
39 print ancestor.missingancestors(revs, bases, pfunc)
40
41 def test_missingancestors():
42 # Empty revs
43 runmissingancestors([], [1])
44 runmissingancestors([], [])
45
46 # If bases is empty, it's the same as if it were [nullrev]
47 runmissingancestors([12], [])
48
49 # Trivial case: revs == bases
50 runmissingancestors([0], [0])
51 runmissingancestors([4, 5, 6], [6, 5, 4])
52
53 # With nullrev
54 runmissingancestors([-1], [12])
55 runmissingancestors([12], [-1])
56
57 # 9 is a parent of 12. 7 is a parent of 9, so an ancestor of 12. 6 is an
58 # ancestor of 12 but not of 7.
59 runmissingancestors([12], [9])
60 runmissingancestors([9], [12])
61 runmissingancestors([12, 9], [7])
62 runmissingancestors([7, 6], [12])
63
64 # More complex cases
65 runmissingancestors([10], [11, 12])
66 runmissingancestors([11], [10])
67 runmissingancestors([11], [10, 12])
68 runmissingancestors([12], [10])
69 runmissingancestors([12], [11])
70 runmissingancestors([10, 11, 12], [13])
71 runmissingancestors([13], [10, 11, 12])
72
73 if __name__ == '__main__':
74 test_missingancestors()