~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Aaron Bentley
  • Date: 2006-07-10 19:23:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1848.
  • Revision ID: abentley@panoramicfeedback.com-20060710192353-469477798c5c4139
Switch to John Meinel's _unescape_xml implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from bzrlib.selftest import TestCase
2
 
from bzrlib.graph import node_distances, nodes_by_distance
 
1
from bzrlib.tests import TestCase
 
2
from bzrlib.graph import node_distances, nodes_by_distance, Graph
3
3
 
4
4
class TestBase(TestCase):
 
5
 
5
6
    def edge_add(self, *args):
6
7
        for start, end in zip(args[:-1], args[1:]):
7
8
            if start not in self.graph:
33
34
        distances = node_distances(self.graph, descendants, 'A')
34
35
        nodes = nodes_by_distance(distances)
35
36
        self.assertEqual(nodes[0], 'D')
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')
 
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'))
40
41
 
41
42
        #Ensure we don't shortcut through B when there's only a difference of
42
43
        # 1 in distance
47
48
        distances = node_distances(self.graph, descendants, 'A')
48
49
        self.assertEqual(distances['C'], 3)
49
50
 
 
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())