~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testgraph.py

  • Committer: Aaron Bentley
  • Date: 2005-09-18 19:21:48 UTC
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050918192148-3f9373ac85a83b02
Refactored and documented graph stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from bzrlib.selftest import TestCase
2
 
from bzrlib.graph import farthest_nodes
 
2
from bzrlib.graph import node_distances, nodes_by_distance
3
3
 
4
4
class TestBase(TestCase):
5
5
    def edge_add(self, *args):
18
18
        self.edge_add('A', 'G', 'H', 'I', 'B')
19
19
        self.edge_add('A', 'J', 'K', 'L', 'M', 'N')
20
20
        self.edge_add('O', 'N')
21
 
    
22
 
    def test_farthest(self):
 
21
 
 
22
    def node_descendants(self):
23
23
        descendants = {'A':set()}
24
24
        for node in self.graph:
25
25
            for ancestor in self.graph[node]:
26
26
                if ancestor not in descendants:
27
27
                    descendants[ancestor] = set()
28
28
                descendants[ancestor].add(node)
29
 
        nodes = farthest_nodes(self.graph, descendants, 'A')
 
29
        return descendants
 
30
    
 
31
    def test_distances(self):
 
32
        descendants = self.node_descendants()
 
33
        distances = node_distances(self.graph, descendants, 'A')
 
34
        nodes = nodes_by_distance(distances)
30
35
        self.assertEqual(nodes[0], 'D')
31
36
        assert nodes[1] in ('N', 'C')
32
37
        assert nodes[2] in ('N', 'C')