[PATCH 08 of 16] test-ancestor: move naive missing ancestor algorithm into a class

Siddharth Agarwal sid0 at fb.com
Sun Nov 16 03:17:10 CST 2014


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1416037801 28800
#      Fri Nov 14 23:50:01 2014 -0800
# Node ID aef7e4ee148f198ea5a0af213b82ec18104e9dcf
# Parent  19925690cbad7e74263bca6c6d84a53842e3fa59
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 --git a/tests/test-ancestor.py b/tests/test-ancestor.py
--- a/tests/test-ancestor.py
+++ b/tests/test-ancestor.py
@@ -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)
 


More information about the Mercurial-devel mailing list