~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_graph.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-28 06:53:44 UTC
  • mfrom: (3581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3583.
  • Revision ID: andrew.bennetts@canonical.com-20080728065344-ocndjoycs903q6fz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1312
1312
        self.assertFindDistance(6, graph, 'g', [('i', 8)])
1313
1313
 
1314
1314
 
 
1315
class TestFindMergeOrder(TestGraphBase):
 
1316
 
 
1317
    def assertMergeOrder(self, expected, graph, tip, base_revisions):
 
1318
        self.assertEqual(expected, graph.find_merge_order(tip, base_revisions))
 
1319
 
 
1320
    def test_parents(self):
 
1321
        graph = self.make_graph(ancestry_1)
 
1322
        self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4',
 
1323
                                                        ['rev3', 'rev2b'])
 
1324
        self.assertMergeOrder(['rev3', 'rev2b'], graph, 'rev4',
 
1325
                                                        ['rev2b', 'rev3'])
 
1326
 
 
1327
    def test_ancestors(self):
 
1328
        graph = self.make_graph(ancestry_1)
 
1329
        self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4',
 
1330
                                                        ['rev1', 'rev2b'])
 
1331
        self.assertMergeOrder(['rev1', 'rev2b'], graph, 'rev4',
 
1332
                                                        ['rev2b', 'rev1'])
 
1333
 
 
1334
    def test_shortcut_one_ancestor(self):
 
1335
        # When we have enough info, we can stop searching
 
1336
        graph = self.make_breaking_graph(ancestry_1, ['rev3', 'rev2b', 'rev4'])
 
1337
        # Single ancestors shortcut right away
 
1338
        self.assertMergeOrder(['rev3'], graph, 'rev4', ['rev3'])
 
1339
 
 
1340
    def test_shortcut_after_one_ancestor(self):
 
1341
        graph = self.make_breaking_graph(ancestry_1, ['rev2a', 'rev2b'])
 
1342
        self.assertMergeOrder(['rev3', 'rev1'], graph, 'rev4', ['rev1', 'rev3'])
 
1343
 
 
1344
 
1315
1345
class TestCachingParentsProvider(tests.TestCase):
1316
1346
 
1317
1347
    def setUp(self):
1354
1384
        # Use sorted because we don't care about the order, just that each is
1355
1385
        # only present 1 time.
1356
1386
        self.assertEqual(['a', 'b'], sorted(self.inst_pp.calls))
 
1387
 
 
1388
 
 
1389
class TestCollapseLinearRegions(tests.TestCase):
 
1390
 
 
1391
    def assertCollapsed(self, collapsed, original):
 
1392
        self.assertEqual(collapsed,
 
1393
                         _mod_graph.collapse_linear_regions(original))
 
1394
 
 
1395
    def test_collapse_nothing(self):
 
1396
        d = {1:[2, 3], 2:[], 3:[]}
 
1397
        self.assertCollapsed(d, d)
 
1398
        d = {1:[2], 2:[3, 4], 3:[5], 4:[5], 5:[]}
 
1399
        self.assertCollapsed(d, d)
 
1400
 
 
1401
    def test_collapse_chain(self):
 
1402
        # Any time we have a linear chain, we should be able to collapse
 
1403
        d = {1:[2], 2:[3], 3:[4], 4:[5], 5:[]}
 
1404
        self.assertCollapsed({1:[5], 5:[]}, d)
 
1405
        d = {5:[4], 4:[3], 3:[2], 2:[1], 1:[]}
 
1406
        self.assertCollapsed({5:[1], 1:[]}, d)
 
1407
        d = {5:[3], 3:[4], 4:[1], 1:[2], 2:[]}
 
1408
        self.assertCollapsed({5:[2], 2:[]}, d)
 
1409
 
 
1410
    def test_collapse_with_multiple_children(self):
 
1411
        #    7
 
1412
        #    |
 
1413
        #    6
 
1414
        #   / \
 
1415
        #  4   5
 
1416
        #  |   |
 
1417
        #  2   3
 
1418
        #   \ /
 
1419
        #    1
 
1420
        #
 
1421
        # 4 and 5 cannot be removed because 6 has 2 children
 
1422
        # 2 and 3 cannot be removed because 1 has 2 parents
 
1423
        d = {1:[2, 3], 2:[4], 4:[6], 3:[5], 5:[6], 6:[7], 7:[]}
 
1424
        self.assertCollapsed(d, d)