# HG changeset patch # User Siddharth Agarwal # Date 1416037801 28800 # Node ID 3f28e8cb3066fdf0aa0e84ad16724c74f2da44b3 # Parent 59e6e5dd36050712c223989443bc1a3af623c804 test-ancestor: move naive missing ancestor algorithm into a class This mirrors the change to the real missing ancestor algorithm in a previous patch. diff -r 59e6e5dd3605 -r 3f28e8cb3066 tests/test-ancestor.py --- a/tests/test-ancestor.py Fri Nov 14 23:44:38 2014 -0800 +++ b/tests/test-ancestor.py Fri Nov 14 23:50:01 2014 -0800 @@ -41,15 +41,19 @@ ancs[i].update(ancs[p]) return ancs -def naivemissingancestors(ancs, revs, bases): - res = set() - for rev in revs: - if rev != nullrev: - res.update(ancs[rev]) - for base in bases: - if base != nullrev: - res.difference_update(ancs[base]) - return sorted(res) +class naiveincrementalmissingancestors(object): + def __init__(self, ancs, bases): + self.ancs = ancs + self.bases = set(bases) + def missingancestors(self, revs): + res = set() + for rev in revs: + if rev != nullrev: + res.update(self.ancs[rev]) + for base in self.bases: + if base != nullrev: + res.difference_update(self.ancs[base]) + return sorted(res) def test_missingancestors(seed, rng): # empirically observed to take around 1 second @@ -91,7 +95,8 @@ inc = ancestor.incrementalmissingancestors(graph.__getitem__, bases) h = inc.missingancestors(revs) # reference slow algorithm - r = naivemissingancestors(ancs, revs, bases) + naiveinc = naiveincrementalmissingancestors(ancs, bases) + r = naiveinc.missingancestors(revs) if h != r: err(seed, graph, bases, revs, h, r)