changeset 31763:8a0c47982ade

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.
author Jun Wu <quark@fb.com>
date Sun, 02 Apr 2017 18:12:47 -0700
parents dff03f68ef11
children 15707e58fc3d
files tests/test-revlog-raw.py
diffstat 1 files changed, 3 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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