##// END OF EJS Templates
contrib: use pycompat.xrange in bdiff-torture.py...
Gregory Szorc -
r43279:e05c1415 default
parent child Browse files
Show More
@@ -1,98 +1,99 b''
1 1 # Randomized torture test generation for bdiff
2 2
3 3 from __future__ import absolute_import, print_function
4 4 import random
5 5 import sys
6 6
7 7 from mercurial import (
8 8 mdiff,
9 pycompat,
9 10 )
10 11
11 12 def reducetest(a, b):
12 13 tries = 0
13 14 reductions = 0
14 15 print("reducing...")
15 16 while tries < 1000:
16 17 a2 = "\n".join(l for l in a.splitlines()
17 18 if random.randint(0, 100) > 0) + "\n"
18 19 b2 = "\n".join(l for l in b.splitlines()
19 20 if random.randint(0, 100) > 0) + "\n"
20 21 if a2 == a and b2 == b:
21 22 continue
22 23 if a2 == b2:
23 24 continue
24 25 tries += 1
25 26
26 27 try:
27 28 test1(a, b)
28 29 except Exception:
29 30 reductions += 1
30 31 tries = 0
31 32 a = a2
32 33 b = b2
33 34
34 35 print("reduced:", reductions, len(a) + len(b),
35 36 repr(a), repr(b))
36 37 try:
37 38 test1(a, b)
38 39 except Exception as inst:
39 40 print("failed:", inst)
40 41
41 42 sys.exit(0)
42 43
43 44 def test1(a, b):
44 45 d = mdiff.textdiff(a, b)
45 46 if not d:
46 47 raise ValueError("empty")
47 48 c = mdiff.patches(a, [d])
48 49 if c != b:
49 50 raise ValueError("bad")
50 51
51 52 def testwrap(a, b):
52 53 try:
53 54 test1(a, b)
54 55 return
55 56 except Exception as inst:
56 57 print("exception:", inst)
57 58 reducetest(a, b)
58 59
59 60 def test(a, b):
60 61 testwrap(a, b)
61 62 testwrap(b, a)
62 63
63 64 def rndtest(size, noise):
64 65 a = []
65 66 src = " aaaaaaaabbbbccd"
66 for x in xrange(size):
67 for x in pycompat.xrange(size):
67 68 a.append(src[random.randint(0, len(src) - 1)])
68 69
69 70 while True:
70 71 b = [c for c in a if random.randint(0, 99) > noise]
71 72 b2 = []
72 73 for c in b:
73 74 b2.append(c)
74 75 while random.randint(0, 99) < noise:
75 76 b2.append(src[random.randint(0, len(src) - 1)])
76 77 if b2 != a:
77 78 break
78 79
79 80 a = "\n".join(a) + "\n"
80 81 b = "\n".join(b2) + "\n"
81 82
82 83 test(a, b)
83 84
84 85 maxvol = 10000
85 86 startsize = 2
86 87 while True:
87 88 size = startsize
88 89 count = 0
89 90 while size < maxvol:
90 91 print(size)
91 92 volume = 0
92 93 while volume < maxvol:
93 94 rndtest(size, 2)
94 95 volume += size
95 96 count += 2
96 97 size *= 2
97 98 maxvol *= 4
98 99 startsize *= 4
General Comments 0
You need to be logged in to leave comments. Login now