1
from bzrlib.selftest import TestCase
2
from bzrlib.graph import shortest_path
3
from bzrlib.graph import farthest_node
5
class TestBase(TestCase):
6
def edge_add(self, *args):
7
for start, end in zip(args[:-1], args[1:]):
8
if start not in self.graph:
10
if end not in self.graph:
12
self.graph[start][end] = 1
17
self.edge_add('A', 'B', 'C')
18
self.edge_add('A', 'D', 'E', 'B', 'G')
19
self.edge_add('E', 'F')
21
def test_shortest(self):
22
"""Ensure we find the longest path to A"""
23
assert 'B' in self.graph['A']
24
self.assertEqual(shortest_path(self.graph, 'A', 'F'),
26
self.assertEqual(shortest_path(self.graph, 'A', 'G'),
28
def test_farthest(self):
29
self.assertEqual(farthest_node(self.graph, 'A'), 'G')