[PATCH 09 of 16] test-ancestor: add support for multiple tests against one incremental object

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


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1416108380 28800
#      Sat Nov 15 19:26:20 2014 -0800
# Node ID 12491c5d3352731b1602e2f8e8d4b8aa445964a8
# Parent  aef7e4ee148f198ea5a0af213b82ec18104e9dcf
test-ancestor: add support for multiple tests against one incremental object

In upcoming patches we'll add more operations to the object, and this prepares
for testing those operations.

diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py
--- a/tests/test-ancestor.py
+++ b/tests/test-ancestor.py
@@ -58,7 +58,8 @@
 def test_missingancestors(seed, rng):
     # empirically observed to take around 1 second
     graphcount = 100
-    testcount = 100
+    testcount = 10
+    inccount = 10
     nerrs = [0]
     # the default mu and sigma give us a nice distribution of mostly
     # single-digit counts (including 0) with some higher ones
@@ -69,13 +70,13 @@
         count = min(lognormrandom(mu, sigma), len(nodes))
         return rng.sample(nodes, count)
 
-    def err(seed, graph, bases, revs, output, expected):
+    def err(seed, graph, bases, seq, output, expected):
         if nerrs[0] == 0:
             print >> sys.stderr, 'seed:', hex(seed)[:-1]
         if gerrs[0] == 0:
             print >> sys.stderr, 'graph:', graph
         print >> sys.stderr, '* bases:', bases
-        print >> sys.stderr, '* revs: ', revs
+        print >> sys.stderr, '* seq: ', seq
         print >> sys.stderr, '*  output:  ', output
         print >> sys.stderr, '*  expected:', expected
         nerrs[0] += 1
@@ -89,16 +90,19 @@
             # start from nullrev to include it as a possibility
             graphnodes = range(nullrev, len(graph))
             bases = samplerevs(graphnodes)
-            revs = samplerevs(graphnodes)
 
             # fast algorithm
             inc = ancestor.incrementalmissingancestors(graph.__getitem__, bases)
-            h = inc.missingancestors(revs)
             # reference slow algorithm
             naiveinc = naiveincrementalmissingancestors(ancs, bases)
-            r = naiveinc.missingancestors(revs)
-            if h != r:
-                err(seed, graph, bases, revs, h, r)
+            seq = []
+            for _ in xrange(inccount):
+                revs = samplerevs(graphnodes)
+                seq.append(('missingancestors', revs))
+                h = inc.missingancestors(revs)
+                r = naiveinc.missingancestors(revs)
+                if h != r:
+                    err(seed, graph, bases, seq, h, r)
 
 # graph is a dict of child->parent adjacency lists for this graph:
 # o  13


More information about the Mercurial-devel mailing list