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