/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib.tests import TestCase
 
2
from bzrlib.graph import node_distances, nodes_by_distance
 
3
 
 
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:
 
8
                self.graph[start] = {}
 
9
            if end not in self.graph:
 
10
                self.graph[end] = {}
 
11
            self.graph[start][end] = 1
 
12
 
 
13
    def setUp(self):
 
14
        TestCase.setUp(self)
 
15
        self.graph = {}
 
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')
 
21
 
 
22
    def node_descendants(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
        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)
 
35
        self.assertEqual(nodes[0], 'D')
 
36
        self.assert_(nodes[1] in ('N', 'C'))
 
37
        self.assert_(nodes[2] in ('N', 'C'))
 
38
        self.assert_(nodes[3] in ('B', 'M'))
 
39
        self.assert_(nodes[4] in ('B', 'M'))
 
40
 
 
41
        #Ensure we don't shortcut through B when there's only a difference of
 
42
        # 1 in distance
 
43
        self.graph = {}
 
44
        self.edge_add('A', 'B', 'C')
 
45
        self.edge_add('A', 'D', 'E', 'C')
 
46
        descendants = self.node_descendants()
 
47
        distances = node_distances(self.graph, descendants, 'A')
 
48
        self.assertEqual(distances['C'], 3)
 
49