contrib/bdiff-torture.py
changeset 43076 2372284d9457
parent 43009 e05c141511dd
child 48875 6000f5b25c9b
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
     7 from mercurial import (
     7 from mercurial import (
     8     mdiff,
     8     mdiff,
     9     pycompat,
     9     pycompat,
    10 )
    10 )
    11 
    11 
       
    12 
    12 def reducetest(a, b):
    13 def reducetest(a, b):
    13     tries = 0
    14     tries = 0
    14     reductions = 0
    15     reductions = 0
    15     print("reducing...")
    16     print("reducing...")
    16     while tries < 1000:
    17     while tries < 1000:
    17         a2 = "\n".join(l for l in a.splitlines()
    18         a2 = (
    18                        if random.randint(0, 100) > 0) + "\n"
    19             "\n".join(l for l in a.splitlines() if random.randint(0, 100) > 0)
    19         b2 = "\n".join(l for l in b.splitlines()
    20             + "\n"
    20                        if random.randint(0, 100) > 0) + "\n"
    21         )
       
    22         b2 = (
       
    23             "\n".join(l for l in b.splitlines() if random.randint(0, 100) > 0)
       
    24             + "\n"
       
    25         )
    21         if a2 == a and b2 == b:
    26         if a2 == a and b2 == b:
    22             continue
    27             continue
    23         if a2 == b2:
    28         if a2 == b2:
    24             continue
    29             continue
    25         tries += 1
    30         tries += 1
    30             reductions += 1
    35             reductions += 1
    31             tries = 0
    36             tries = 0
    32             a = a2
    37             a = a2
    33             b = b2
    38             b = b2
    34 
    39 
    35     print("reduced:", reductions, len(a) + len(b),
    40     print("reduced:", reductions, len(a) + len(b), repr(a), repr(b))
    36           repr(a), repr(b))
       
    37     try:
    41     try:
    38         test1(a, b)
    42         test1(a, b)
    39     except Exception as inst:
    43     except Exception as inst:
    40         print("failed:", inst)
    44         print("failed:", inst)
    41 
    45 
    42     sys.exit(0)
    46     sys.exit(0)
       
    47 
    43 
    48 
    44 def test1(a, b):
    49 def test1(a, b):
    45     d = mdiff.textdiff(a, b)
    50     d = mdiff.textdiff(a, b)
    46     if not d:
    51     if not d:
    47         raise ValueError("empty")
    52         raise ValueError("empty")
    48     c = mdiff.patches(a, [d])
    53     c = mdiff.patches(a, [d])
    49     if c != b:
    54     if c != b:
    50         raise ValueError("bad")
    55         raise ValueError("bad")
    51 
    56 
       
    57 
    52 def testwrap(a, b):
    58 def testwrap(a, b):
    53     try:
    59     try:
    54         test1(a, b)
    60         test1(a, b)
    55         return
    61         return
    56     except Exception as inst:
    62     except Exception as inst:
    57         print("exception:", inst)
    63         print("exception:", inst)
    58     reducetest(a, b)
    64     reducetest(a, b)
    59 
    65 
       
    66 
    60 def test(a, b):
    67 def test(a, b):
    61     testwrap(a, b)
    68     testwrap(a, b)
    62     testwrap(b, a)
    69     testwrap(b, a)
       
    70 
    63 
    71 
    64 def rndtest(size, noise):
    72 def rndtest(size, noise):
    65     a = []
    73     a = []
    66     src = "                aaaaaaaabbbbccd"
    74     src = "                aaaaaaaabbbbccd"
    67     for x in pycompat.xrange(size):
    75     for x in pycompat.xrange(size):
    80     a = "\n".join(a) + "\n"
    88     a = "\n".join(a) + "\n"
    81     b = "\n".join(b2) + "\n"
    89     b = "\n".join(b2) + "\n"
    82 
    90 
    83     test(a, b)
    91     test(a, b)
    84 
    92 
       
    93 
    85 maxvol = 10000
    94 maxvol = 10000
    86 startsize = 2
    95 startsize = 2
    87 while True:
    96 while True:
    88     size = startsize
    97     size = startsize
    89     count = 0
    98     count = 0