1
from bzrlib.selftest import TestCase
2
from bzrlib.graph import farthest_nodes
4
class TestBase(TestCase):
5
def edge_add(self, *args):
6
for start, end in zip(args[:-1], args[1:]):
7
if start not in self.graph:
9
if end not in self.graph:
11
self.graph[start][end] = 1
16
self.edge_add('A', 'B', 'C', 'D')
17
self.edge_add('A', 'E', 'F', 'C')
18
self.edge_add('A', 'G', 'H', 'I', 'B')
19
self.edge_add('A', 'J', 'K', 'L', 'M', 'N')
20
self.edge_add('O', 'N')
22
def test_farthest(self):
23
descendants = {'A':set()}
24
for node in self.graph:
25
for ancestor in self.graph[node]:
26
if ancestor not in descendants:
27
descendants[ancestor] = set()
28
descendants[ancestor].add(node)
29
nodes = farthest_nodes(self.graph, descendants, 'A')
30
self.assertEqual(nodes[0], 'D')
31
assert nodes[1] in ('N', 'C')
32
assert nodes[2] in ('N', 'C')
33
assert nodes[3] in ('B', 'M')
34
assert nodes[4] in ('B', 'M')