test-revlog-raw: fix "genbits" implementation
authorJun Wu <quark@fb.com>
Sun, 02 Apr 2017 18:12:47 -0700
changeset 31766 8a0c47982ade
parent 31765 dff03f68ef11
child 31767 15707e58fc3d
test-revlog-raw: fix "genbits" implementation The "genbits" implementation is actually incorrect. This patch fixes it. A good "genbits" implementation should pass the below assertion: n = 3 # or other number l = list(genbits(n)) assert 2**(n*2) == len(set((l[i]<<n)+l[i+1] for i in range(len(l)-1))) An assertion is added to make sure "genbits" won't work unexpectedly.
tests/test-revlog-raw.py
--- a/tests/test-revlog-raw.py	Wed Mar 29 14:49:14 2017 -0700
+++ b/tests/test-revlog-raw.py	Sun Apr 02 18:12:47 2017 -0700
@@ -166,6 +166,7 @@
 
     # Gray Code. See https://en.wikipedia.org/wiki/Gray_code
     gray = lambda x: x ^ (x >> 1)
+    reversegray = dict((gray(i), i) for i in range(m))
 
     # Generate (n * 2) bit gray code, yield lower n bits as X, and look for
     # the next unused gray code where higher n bits equal to X.
@@ -177,7 +178,9 @@
     x = 0
     yield x
     for i in range(m * m):
+        x = reversegray[x]
         y = gray(a[x] + x * m) & (m - 1)
+        assert a[x] < m
         a[x] += 1
         x = y
         yield x