374
374
graph = self.make_graph({'c': ['b', 'd'], 'd': ['e'], 'b': ['a'],
375
375
'a': [NULL_REVISION], 'e': [NULL_REVISION]})
376
self.assertEqual(['c'], graph._filter_candidate_lca(['a', 'c', 'e']))
376
self.assertEqual(set(['c']), graph.heads(['a', 'c', 'e']))
378
def test_heads_null(self):
379
graph = self.make_graph(ancestry_1)
380
self.assertEqual(set(['null:']), graph.heads(['null:']))
381
self.assertEqual(set(['rev1']), graph.heads(['null:', 'rev1']))
382
self.assertEqual(set(['rev1']), graph.heads(['rev1', 'null:']))
383
self.assertEqual(set(['rev1']), graph.heads(set(['rev1', 'null:'])))
384
self.assertEqual(set(['rev1']), graph.heads(('rev1', 'null:')))
386
def test_heads_one(self):
387
# A single node will alwaya be a head
388
graph = self.make_graph(ancestry_1)
389
self.assertEqual(set(['null:']), graph.heads(['null:']))
390
self.assertEqual(set(['rev1']), graph.heads(['rev1']))
391
self.assertEqual(set(['rev2a']), graph.heads(['rev2a']))
392
self.assertEqual(set(['rev2b']), graph.heads(['rev2b']))
393
self.assertEqual(set(['rev3']), graph.heads(['rev3']))
394
self.assertEqual(set(['rev4']), graph.heads(['rev4']))
396
def test_heads_single(self):
397
graph = self.make_graph(ancestry_1)
398
self.assertEqual(set(['rev4']), graph.heads(['null:', 'rev4']))
399
self.assertEqual(set(['rev2a']), graph.heads(['rev1', 'rev2a']))
400
self.assertEqual(set(['rev2b']), graph.heads(['rev1', 'rev2b']))
401
self.assertEqual(set(['rev3']), graph.heads(['rev1', 'rev3']))
402
self.assertEqual(set(['rev4']), graph.heads(['rev1', 'rev4']))
403
self.assertEqual(set(['rev4']), graph.heads(['rev2a', 'rev4']))
404
self.assertEqual(set(['rev4']), graph.heads(['rev2b', 'rev4']))
405
self.assertEqual(set(['rev4']), graph.heads(['rev3', 'rev4']))
407
def test_heads_two_heads(self):
408
graph = self.make_graph(ancestry_1)
409
self.assertEqual(set(['rev2a', 'rev2b']),
410
graph.heads(['rev2a', 'rev2b']))
411
self.assertEqual(set(['rev3', 'rev2b']),
412
graph.heads(['rev3', 'rev2b']))
414
def test_heads_criss_cross(self):
415
graph = self.make_graph(criss_cross)
416
self.assertEqual(set(['rev2a']),
417
graph.heads(['rev2a', 'rev1']))
418
self.assertEqual(set(['rev2b']),
419
graph.heads(['rev2b', 'rev1']))
420
self.assertEqual(set(['rev3a']),
421
graph.heads(['rev3a', 'rev1']))
422
self.assertEqual(set(['rev3b']),
423
graph.heads(['rev3b', 'rev1']))
424
self.assertEqual(set(['rev2a', 'rev2b']),
425
graph.heads(['rev2a', 'rev2b']))
426
self.assertEqual(set(['rev3a']),
427
graph.heads(['rev3a', 'rev2a']))
428
self.assertEqual(set(['rev3a']),
429
graph.heads(['rev3a', 'rev2b']))
430
self.assertEqual(set(['rev3a']),
431
graph.heads(['rev3a', 'rev2a', 'rev2b']))
432
self.assertEqual(set(['rev3b']),
433
graph.heads(['rev3b', 'rev2a']))
434
self.assertEqual(set(['rev3b']),
435
graph.heads(['rev3b', 'rev2b']))
436
self.assertEqual(set(['rev3b']),
437
graph.heads(['rev3b', 'rev2a', 'rev2b']))
438
self.assertEqual(set(['rev3a', 'rev3b']),
439
graph.heads(['rev3a', 'rev3b']))
440
self.assertEqual(set(['rev3a', 'rev3b']),
441
graph.heads(['rev3a', 'rev3b', 'rev2a', 'rev2b']))
443
def test_heads_shortcut(self):
444
graph = self.make_graph(history_shortcut)
446
self.assertEqual(set(['rev2a', 'rev2b', 'rev2c']),
447
graph.heads(['rev2a', 'rev2b', 'rev2c']))
448
self.assertEqual(set(['rev3a', 'rev3b']),
449
graph.heads(['rev3a', 'rev3b']))
450
self.assertEqual(set(['rev3a', 'rev3b']),
451
graph.heads(['rev2a', 'rev3a', 'rev3b']))
452
self.assertEqual(set(['rev2a', 'rev3b']),
453
graph.heads(['rev2a', 'rev3b']))
454
self.assertEqual(set(['rev2c', 'rev3a']),
455
graph.heads(['rev2c', 'rev3a']))