Mercurial > hg
comparison tests/test-linelog.py @ 38924:6fed8b323651
linelog: add replacelines_vec for fastannotate
# no-check-commit because we're conforming to an existing interface
Differential Revision: https://phab.mercurial-scm.org/D3993
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 30 Jul 2018 23:52:15 -0400 |
parents | 57af5ee15b35 |
children | 27a54096c92e |
comparison
equal
deleted
inserted
replaced
38923:8460c3cbca7e | 38924:6fed8b323651 |
---|---|
4 import random | 4 import random |
5 import unittest | 5 import unittest |
6 | 6 |
7 from mercurial import linelog | 7 from mercurial import linelog |
8 | 8 |
9 vecratio = 3 # number of replacelines / number of replacelines_vec | |
9 maxlinenum = 0xffffff | 10 maxlinenum = 0xffffff |
10 maxb1 = 0xffffff | 11 maxb1 = 0xffffff |
11 maxdeltaa = 10 | 12 maxdeltaa = 10 |
12 maxdeltab = 10 | 13 maxdeltab = 10 |
13 | 14 |
19 n = len(lines) | 20 n = len(lines) |
20 a1 = random.randint(0, n) | 21 a1 = random.randint(0, n) |
21 a2 = random.randint(a1, min(n, a1 + maxdeltaa)) | 22 a2 = random.randint(a1, min(n, a1 + maxdeltaa)) |
22 b1 = random.randint(0, maxb1) | 23 b1 = random.randint(0, maxb1) |
23 b2 = random.randint(b1, b1 + maxdeltab) | 24 b2 = random.randint(b1, b1 + maxdeltab) |
24 blines = [(rev, idx) for idx in range(b1, b2)] | 25 usevec = not bool(random.randint(0, vecratio)) |
26 if usevec: | |
27 blines = [(random.randint(0, rev), random.randint(0, maxlinenum)) | |
28 for _ in range(b1, b2)] | |
29 else: | |
30 blines = [(rev, bidx) for bidx in range(b1, b2)] | |
25 lines[a1:a2] = blines | 31 lines[a1:a2] = blines |
26 yield lines, rev, a1, a2, b1, b2 | 32 yield lines, rev, a1, a2, b1, b2, blines, usevec |
27 | 33 |
28 class linelogtests(unittest.TestCase): | 34 class linelogtests(unittest.TestCase): |
29 def testlinelogencodedecode(self): | 35 def testlinelogencodedecode(self): |
30 program = [linelog._eof(0, 0), | 36 program = [linelog._eof(0, 0), |
31 linelog._jge(41, 42), | 37 linelog._jge(41, 42), |
157 # Inspired by original linelog tests. | 163 # Inspired by original linelog tests. |
158 seed = random.random() | 164 seed = random.random() |
159 numrevs = 2000 | 165 numrevs = 2000 |
160 ll = linelog.linelog() | 166 ll = linelog.linelog() |
161 # Populate linelog | 167 # Populate linelog |
162 for lines, rev, a1, a2, b1, b2 in _genedits(seed, numrevs): | 168 for lines, rev, a1, a2, b1, b2, blines, usevec in _genedits( |
163 ll.replacelines(rev, a1, a2, b1, b2) | 169 seed, numrevs): |
170 if usevec: | |
171 ll.replacelines_vec(rev, a1, a2, blines) | |
172 else: | |
173 ll.replacelines(rev, a1, a2, b1, b2) | |
164 ar = ll.annotate(rev) | 174 ar = ll.annotate(rev) |
165 self.assertEqual(ll.annotateresult, lines) | 175 self.assertEqual(ll.annotateresult, lines) |
166 # Verify we can get back these states by annotating each rev | 176 # Verify we can get back these states by annotating each rev |
167 for lines, rev, a1, a2, b1, b2 in _genedits(seed, numrevs): | 177 for lines, rev, a1, a2, b1, b2, blines, usevec in _genedits( |
178 seed, numrevs): | |
168 ar = ll.annotate(rev) | 179 ar = ll.annotate(rev) |
169 self.assertEqual([(l.rev, l.linenum) for l in ar], lines) | 180 self.assertEqual([(l.rev, l.linenum) for l in ar], lines) |
170 | 181 |
171 if __name__ == '__main__': | 182 if __name__ == '__main__': |
172 import silenttestrunner | 183 import silenttestrunner |