526
526
graph = self.make_graph(history_shortcut)
527
527
self.assertEqual(set(['rev2b']), graph.find_lca('rev3a', 'rev3b'))
529
def test_lefthand_distance_smoke(self):
530
"""A simple does it work test for graph.lefthand_distance(keys)."""
531
graph = self.make_graph(history_shortcut)
532
distance_graph = graph.find_lefthand_distances(['rev3b', 'rev2a'])
533
self.assertEqual({'rev2a': 2, 'rev3b': 3}, distance_graph)
535
def test_lefthand_distance_ghosts(self):
536
"""A simple does it work test for graph.lefthand_distance(keys)."""
537
nodes = {'nonghost':[NULL_REVISION], 'toghost':['ghost']}
538
graph = self.make_graph(nodes)
539
distance_graph = graph.find_lefthand_distances(['nonghost', 'toghost'])
540
self.assertEqual({'nonghost': 1, 'toghost': -1}, distance_graph)
542
529
def test_recursive_unique_lca(self):
543
530
"""Test finding a unique least common ancestor.
1424
1411
self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
1427
class TestFindDescendants(TestGraphBase):
1429
def test_find_descendants_rev1_rev3(self):
1430
graph = self.make_graph(ancestry_1)
1431
descendants = graph.find_descendants('rev1', 'rev3')
1432
self.assertEqual(set(['rev1', 'rev2a', 'rev3']), descendants)
1434
def test_find_descendants_rev1_rev4(self):
1435
graph = self.make_graph(ancestry_1)
1436
descendants = graph.find_descendants('rev1', 'rev4')
1437
self.assertEqual(set(['rev1', 'rev2a', 'rev2b', 'rev3', 'rev4']),
1440
def test_find_descendants_rev2a_rev4(self):
1441
graph = self.make_graph(ancestry_1)
1442
descendants = graph.find_descendants('rev2a', 'rev4')
1443
self.assertEqual(set(['rev2a', 'rev3', 'rev4']), descendants)
1445
class TestFindLefthandMerger(TestGraphBase):
1447
def check_merger(self, result, ancestry, merged, tip):
1448
graph = self.make_graph(ancestry)
1449
self.assertEqual(result, graph.find_lefthand_merger(merged, tip))
1451
def test_find_lefthand_merger_rev2b(self):
1452
self.check_merger('rev4', ancestry_1, 'rev2b', 'rev4')
1454
def test_find_lefthand_merger_rev2a(self):
1455
self.check_merger('rev2a', ancestry_1, 'rev2a', 'rev4')
1457
def test_find_lefthand_merger_rev4(self):
1458
self.check_merger(None, ancestry_1, 'rev4', 'rev2a')
1460
def test_find_lefthand_merger_f(self):
1461
self.check_merger('i', complex_shortcut, 'f', 'm')
1463
def test_find_lefthand_merger_g(self):
1464
self.check_merger('i', complex_shortcut, 'g', 'm')
1466
def test_find_lefthand_merger_h(self):
1467
self.check_merger('n', complex_shortcut, 'h', 'n')
1470
class TestGetChildMap(TestGraphBase):
1472
def test_get_child_map(self):
1473
graph = self.make_graph(ancestry_1)
1474
child_map = graph.get_child_map(['rev4', 'rev3', 'rev2a', 'rev2b'])
1475
self.assertEqual({'rev1': ['rev2a', 'rev2b'],
1482
1414
class TestCachingParentsProvider(tests.TestCase):
1483
1415
"""These tests run with:
1637
1569
self.assertCollapsed(d, d)
1640
class TestGraphThunkIdsToKeys(tests.TestCase):
1642
def test_heads(self):
1648
d = {('D',): [('B',), ('C',)], ('C',):[('A',)],
1649
('B',): [('A',)], ('A',): []}
1650
g = _mod_graph.Graph(_mod_graph.DictParentsProvider(d))
1651
graph_thunk = _mod_graph.GraphThunkIdsToKeys(g)
1652
self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'A'])))
1653
self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'B'])))
1654
self.assertEqual(['D'], sorted(graph_thunk.heads(['D', 'C'])))
1655
self.assertEqual(['B', 'C'], sorted(graph_thunk.heads(['B', 'C'])))
1658
1572
class TestPendingAncestryResultGetKeys(TestCaseWithMemoryTransport):
1659
1573
"""Tests for bzrlib.graph.PendingAncestryResult."""