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

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 16, 2014, 9:17 a.m.
Message ID <aef7e4ee148f198ea5a0.1416129430@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6755/
State Accepted
Commit 3f28e8cb3066fdf0aa0e84ad16724c74f2da44b3
Headers show

Comments

Siddharth Agarwal - Nov. 16, 2014, 9:17 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

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)