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