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