码迷,mamicode.com
首页 > 其他好文 > 详细

Simplifying Failures

时间:2019-07-10 21:37:18      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:else   lin   break   comment   port   put   sim   select   cti   

#
# Finish the delta debug function ddmin
#


import re

def test(s):
    print s, len(s),repr(s)
    if re.search("<SELECT[^>]*>", s) >= 0:
        print (s, len(s),"FAIL")
        return "FAIL"
    else:
        return "PASS"


def ddmin(s):
    assert test(s) == "FAIL"

    n = 2     # Initial granularity
    while len(s) >= 2:
        start = 0
        subset_length = len(s) / n
        some_complement_is_failing = False

        while start < len(s):
            complement = s[:start] + s[start + subset_length:]

            if test(complement) == "FAIL":
                s = complement
                n = max(n - 1, 2)
                some_complement_is_failing = True
                break
                
            start += subset_length

        if not some_complement_is_failing:
            # YOUR CODE HERE
            if len(s) == n:
                break
            n = min(n * 2, len(s))

    return s

# UNCOMMENT TO TEST
html_input = <SELECT>foo</SELECT>
print ddmin(html_input)

 

Simplifying Failures

标签:else   lin   break   comment   port   put   sim   select   cti   

原文地址:https://www.cnblogs.com/catgatp/p/11166568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!