~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testgraph.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-09-05 07:11:41 UTC
  • mto: (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050905071141-5f9ef30b0f6b3e21
Started work on djkstra longest-path algorithm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib.selftest import TestCase
 
2
from bzrlib.graph import shortest_path
 
3
from bzrlib.graph import farthest_node
 
4
 
 
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:
 
9
                self.graph[start] = {}
 
10
            if end not in self.graph:
 
11
                self.graph[end] = {}
 
12
            self.graph[start][end] = 1
 
13
 
 
14
    def setUp(self):
 
15
        TestCase.setUp(self)
 
16
        self.graph = {}
 
17
        self.edge_add('A', 'B', 'C')
 
18
        self.edge_add('A', 'D', 'E', 'B', 'G')
 
19
        self.edge_add('E', 'F')
 
20
    
 
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'), 
 
25
                         ['A', 'D', 'E', 'F'])
 
26
        self.assertEqual(shortest_path(self.graph, 'A', 'G'), 
 
27
                         ['A', 'B', 'G'])
 
28
    def test_farthest(self):
 
29
        self.assertEqual(farthest_node(self.graph, 'A'), 'G')