~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testgraph.py

  • Committer: Robert Collins
  • Date: 2005-10-06 05:13:21 UTC
  • mfrom: (1393.3.3)
  • Revision ID: robertc@robertcollins.net-20051006051321-88f1053c3bf1ca4a
merge in an adjusted version of Jelmer's empty-log detection patch.

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, Graph
 
1
from bzrlib.selftest import TestCase
 
2
from bzrlib.graph import node_distances, nodes_by_distance
3
3
 
4
4
class TestBase(TestCase):
5
 
 
6
5
    def edge_add(self, *args):
7
6
        for start, end in zip(args[:-1], args[1:]):
8
7
            if start not in self.graph:
34
33
        distances = node_distances(self.graph, descendants, 'A')
35
34
        nodes = nodes_by_distance(distances)
36
35
        self.assertEqual(nodes[0], 'D')
37
 
        self.assert_(nodes[1] in ('N', 'C'))
38
 
        self.assert_(nodes[2] in ('N', 'C'))
39
 
        self.assert_(nodes[3] in ('B', 'M'))
40
 
        self.assert_(nodes[4] in ('B', 'M'))
 
36
        assert nodes[1] in ('N', 'C')
 
37
        assert nodes[2] in ('N', 'C')
 
38
        assert nodes[3] in ('B', 'M')
 
39
        assert nodes[4] in ('B', 'M')
41
40
 
42
41
        #Ensure we don't shortcut through B when there's only a difference of
43
42
        # 1 in distance
48
47
        distances = node_distances(self.graph, descendants, 'A')
49
48
        self.assertEqual(distances['C'], 3)
50
49
 
51
 
 
52
 
class TestGraph(TestCase):
53
 
 
54
 
    def test_get_descendants(self):
55
 
        # Graph objects let you get a descendants graph in 
56
 
        # node: {direct-children:distance} which contains
57
 
        # known children, including ghost children
58
 
        graph = Graph()
59
 
        graph.add_ghost('ghost')
60
 
        graph.add_node('rev1', ['ghost'])
61
 
        # check the result contains ghosts:
62
 
        self.assertEqual({'ghost': {'rev1': 1}, 'rev1': {}},
63
 
                         graph.get_descendants())