def future(self, i): #到底需不需要考虑拓扑顺序呢??? if type(self.node_list[i]) != Varnode or self.node_list[i].I == None: return #第一次future是提前做的,因此现在I还可能是空呢 for item in self.node_list[i].next_dashed_list: if self.node_list[item].lval != None: #lval != -inf #e.g. 原来是[j_3, a),现在有[, 99] #把lval换成-inf,变成[-inf, a),然后把这个字符串代入Interval进行初始化 tmp = copy.deepcopy(self.node_list[item]) tmp.lval = str(self.node_list[i].I.lower) s = str(tmp).replace('-inf', '').replace('inf', '') if tmp._type == 'int': e = IntInterval.from_string(s) else: e = FloatInterval.from_string(s) else: #rval != inf #e.g. 原来是(a,j_3),现在有[, 99] #把rval=j_3换成99,变成(a, 99),然后把这个字符串代入Interval进行初始化 tmp = copy.deepcopy(self.node_list[item]) tmp.rval = str(self.node_list[i].I.upper) s = str(tmp).replace('-inf', '').replace('inf', '') #用字符串来初始化不能有inf,而要留空 if tmp._type == 'int': e = IntInterval.from_string(s) else: e = FloatInterval.from_string(s) self.node_list[item].I = e
def test_and_operator_for_half_open_intervals_with_empty_results( self, interval1, interval2, empty ): assert ( IntInterval.from_string(interval1) & IntInterval.from_string(interval2) ).empty == empty
def test_or_operator( self, interval1, interval2, result ): assert ( IntInterval.from_string(interval1) | IntInterval.from_string(interval2) == result )
def test_and_operator_with_half_open_intervals( self, interval1, interval2, result ): assert ( IntInterval.from_string(interval1) & IntInterval.from_string(interval2) == IntInterval(result) )
def buildDictionary() -> dict: popUpDict = {} with open('PopUpRead.csv', 'r', newline='') as file: read = csv.reader(file) next(read) #skip header for row in read: #skips duplicates if row[0] not in popUpDict: popUpDict[row[0]] = [ [x.strip() for x in row[1].split(',') if x], IntInterval.from_string(row[2]), [x.strip() for x in row[3].split(',') if x], row[4] ] if '' == row[2]: popUpDict[row[0]][1] = '0' if '' == row[4]: popUpDict[row[0]][3] = 'hot' return popUpDict
def test_or_operator_with_illegal_arguments(self, interval1, interval2): with raises(IllegalArgument): (IntInterval.from_string(interval1) | IntInterval.from_string(interval2))
def test_and_operator_for_half_open_intervals_with_empty_results( self, interval1, interval2, empty): assert (IntInterval.from_string(interval1) & IntInterval.from_string(interval2)).empty == empty
def test_empty_string_as_lower_bound(self): interval = IntInterval.from_string('[,1)') assert interval.lower == -inf assert interval.upper == 1 assert interval.lower_inc assert not interval.upper_inc
def test_eq_operator(self, interval, interval2): assert (IntInterval.from_string(interval) == IntInterval.from_string( interval2))
def test_hyphen_format(self, number_range, lower, upper): interval = IntInterval.from_string(number_range) assert interval.lower == lower assert interval.upper == upper
def test_supports_strings_with_bounds(self): interval = IntInterval.from_string('[1, 3]') assert interval.lower == 1 assert interval.upper == 3 assert interval.lower_inc assert interval.upper_inc
@mark.parametrize(('interval', 'string'), ( ((1, 3), '(1, 3)'), ([1, 1], '[1, 1]'), ([1, inf], '[1,]') )) def test_str_representation(interval, string): assert str(IntInterval(interval)) == string @mark.parametrize( ('number_range', 'empty'), ( (IntInterval((2, 3)), True), (IntInterval([2, 3]), False), (IntInterval([2, 2]), False), (IntInterval.from_string('[2, 2)'), True), (IntInterval.from_string('(2, 2]'), True), (IntInterval.from_string('[2, 3)'), False), (IntInterval((2, 10)), False), ) ) def test_bool(number_range, empty): assert bool(IntInterval(number_range)) != empty @mark.parametrize( ('number_range', 'coerced_value'), ( ([5, 5], 5), ([2, 2], 2), )
def test_step_argument_for_from_string(self): interval = IntInterval.from_string('[2,)', step=2) assert interval.lower == 2 assert interval.upper == inf assert interval.step == 2
def test_eq_operator(self, interval, interval2): assert ( IntInterval.from_string(interval) == IntInterval.from_string(interval2) )
def test_or_operator_with_illegal_arguments(self, interval1, interval2): with raises(IllegalArgument): ( IntInterval.from_string(interval1) | IntInterval.from_string(interval2) )
# code = get_SSA('benchmark/t7_2.ssa') #函数层数太多,比较耗时 # init_val = {'i':IntInterval.from_string('[-10,10]')} #[16, 30] # code = get_SSA('benchmark/t8.ssa') # init_val = {'a':IntInterval.from_string('[1,100]'), # 'b':IntInterval.from_string('[-2,2]')} #[-3.22, 5.94] # code = get_SSA('benchmark/t9.ssa') # init_val = {} #[9791,9791] # code = get_SSA('benchmark/t10.ssa') # init_val = {'a':IntInterval.from_string('[30, 50]'), # 'b':IntInterval.from_string('[90, 100]')} #[-10,40] # code = get_SSA('benchmark/t10_2.ssa') #如果改成i<b-j试试,还是错误。 # init_val = {'a':IntInterval.from_string('[30, 50]'), # 'b':IntInterval.from_string('[90, 100]')} #[-10,40] code = get_SSA('benchmark/t10_3.ssa') #如果改成j<b-i试试,一端错误。 init_val = { 'a': IntInterval.from_string('[30, 50]'), 'b': IntInterval.from_string('[90, 100]') } #[-10,40] create_func_list(code) callee = Context.func_list['foo'] # 分析过程利用上一轮的不可能分支来做 last_Unreached = [] for t in range(5): #还是要防止一下死循环;我想最多五次也就收敛了 graph = Flowgraph(callee, init_val, last_Unreached) graph.get_SSC() graph.analyze() if cmp(last_Unreached, graph.Unreached) == 0: break #如果不可能分支没有变化,则结束 else: last_Unreached = graph.Unreached #记录下这一轮得到的新的不可能分支
def test_int_with_empty_interval(number_range): with raises(TypeError): int(IntInterval.from_string(number_range))
from pytest import mark from intervals import IntInterval @mark.parametrize(('interval', 'string'), ( (IntInterval((1, 3)), '2'), (IntInterval([1, 1]), '1'), (IntInterval([1, 3]), '1 - 3'), (IntInterval.from_string('(1, 5]'), '2 - 5'), (IntInterval.from_string('[1,]'), '1 -') )) def test_hyphenized(interval, string): assert interval.hyphenized == string
def test_supports_strings_with_spaces(self): interval = IntInterval.from_string('1 - 3') assert interval.lower == 1 assert interval.upper == 3 assert interval.lower_inc assert interval.upper_inc
class TestIntervalProperties(object): @mark.parametrize( ('number_range', 'length'), ( ([1, 4], 3), ([-1, 1], 2), ((-inf, inf), inf), ((1, inf), inf), ) ) def test_length(self, number_range, length): assert IntInterval(number_range).length == length @mark.parametrize( ('number_range', 'radius'), ( ([1, 4], 1.5), ([-1, 1], 1.0), ([-4, -1], 1.5), ((-inf, inf), inf), ((1, inf), inf), ) ) def test_radius(self, number_range, radius): assert IntInterval(number_range).radius == radius @mark.parametrize( ('number_range', 'centre'), ( ([1, 4], 2.5), ([-1, 1], 0), ([-4, -1], -2.5), ((1, inf), inf), ) ) def test_centre(self, number_range, centre): assert IntInterval(number_range).centre == centre @mark.parametrize( ('interval', 'is_open'), ( (IntInterval((2, 3)), True), (IntInterval.from_string('(2, 5)'), True), (IntInterval.from_string('[3, 4)'), False), (IntInterval.from_string('(4, 5]'), False), (IntInterval.from_string('3 - 4'), False), (IntInterval([4, 5]), False), (IntInterval.from_string('[4, 5]'), False) ) ) def test_is_open(self, interval, is_open): assert interval.is_open == is_open @mark.parametrize( ('interval', 'is_closed'), ( (IntInterval((2, 3)), False), (IntInterval.from_string('(2, 5)'), False), (IntInterval.from_string('[3, 4)'), False), (IntInterval.from_string('(4, 5]'), False), (IntInterval.from_string('3 - 4'), True), (IntInterval([4, 5]), True), (IntInterval.from_string('[4, 5]'), True) ) ) def test_closed(self, interval, is_closed): assert interval.is_closed == is_closed @mark.parametrize( ('interval', 'empty'), ( (IntInterval((2, 3)), True), (IntInterval([2, 3]), False), (IntInterval([2, 2]), False), (IntInterval.from_string('[2, 2)'), True), (IntInterval.from_string('(2, 2]'), True), (IntInterval.from_string('[2, 3)'), False), (IntInterval((2, 10)), False), ) ) def test_empty(self, interval, empty): assert interval.empty == empty @mark.parametrize( ('interval', 'degenerate'), ( (IntInterval((2, 4)), False), (IntInterval.from_string('[2, 2]'), True), (IntInterval.from_string('[0, 0)'), True), ) ) def test_degenerate(self, interval, degenerate): assert interval.degenerate == degenerate @mark.parametrize( ('interval', 'discrete'), ( (IntInterval((2, 3)), True), (IntInterval(5), True), (FloatInterval(3.5), False), (DecimalInterval(Decimal('2.4')), False), (DateTimeInterval(datetime(2002, 1, 1)), False), (DateInterval(date(2002, 1, 1)), True) ) ) def test_discrete(self, interval, discrete): assert interval.discrete == discrete
from pytest import mark, raises from intervals import IntInterval @mark.parametrize(('interval', 'string'), (((1, 3), '(1, 3)'), ([1, 1], '[1, 1]'), ([1, inf], '[1,]'))) def test_str_representation(interval, string): assert str(IntInterval(interval)) == string @mark.parametrize(('number_range', 'empty'), ( (IntInterval((2, 3)), True), (IntInterval([2, 3]), False), (IntInterval([2, 2]), False), (IntInterval.from_string('[2, 2)'), True), (IntInterval.from_string('(2, 2]'), True), (IntInterval.from_string('[2, 3)'), False), (IntInterval((2, 10)), False), )) def test_bool(number_range, empty): assert bool(IntInterval(number_range)) != empty @mark.parametrize(('number_range', 'coerced_value'), ( ([5, 5], 5), ([2, 2], 2), )) def test_int_with_single_point_interval(number_range, coerced_value): assert int(IntInterval(number_range)) == coerced_value
def test_intersection(self, first, second, intersection): assert ( IntInterval.from_string(first) & IntInterval.from_string(second) ) == IntInterval.from_string(intersection)
from pytest import mark from intervals import IntInterval @mark.parametrize(('interval', 'string'), ((IntInterval((1, 3)), '2'), (IntInterval([1, 1]), '1'), (IntInterval([1, 3]), '1 - 3'), (IntInterval.from_string('(1, 5]'), '2 - 5'), (IntInterval.from_string('[1,]'), '1 -'))) def test_hyphenized(interval, string): assert interval.hyphenized == string
def test_supports_exact_ranges_as_strings(self): interval = IntInterval.from_string('3') assert interval.lower == 3 assert interval.upper == 3 assert interval.lower_inc assert interval.upper_inc
class TestBinaryOperators(object): @mark.parametrize(('interval1', 'interval2', 'result'), ( ('(2, 3]', '[3, 4)', IntInterval([3, 3])), ('(2, 10]', '[3, 40]', IntInterval([3, 10])), ('[0, 0]', '[0, 0]', IntInterval.from_string('[0, 0]')), ('[0, 0]', '(0, 0]', IntInterval.from_string('(0, 0]')), ('[0, 0)', '[0, 0]', IntInterval.from_string('[0, 0)')), ('(2, 2]', '(2, 2]', IntInterval.from_string('(2, 2]')), ('[2, 2)', '[2, 2)', IntInterval.from_string('[2, 2)')), ('(2, 3)', '[3, 4]', IntInterval.from_string('[3, 3)')), ('[2, 3]', '(3, 4)', IntInterval.from_string('(3, 3]')), )) def test_and_operator(self, interval1, interval2, result): assert (IntInterval.from_string(interval1) & IntInterval.from_string(interval2) == result) @mark.parametrize(('interval1', 'interval2'), ( ('[2, 2]', '[5, 7)'), ('(2, 3]', '[4, 40]'), ('(2, 3)', '(3, 4)'), )) def test_and_operator_with_illegal_arguments(self, interval1, interval2): with raises(IllegalArgument): (IntInterval.from_string(interval1) & IntInterval.from_string(interval2)) @mark.parametrize(('interval1', 'interval2'), ( ('[2, 2]', '[5, 7)'), ('(2, 3]', '[4, 40]'), ('(2, 3)', '(3, 4)'), )) def test_or_operator_with_illegal_arguments(self, interval1, interval2): with raises(IllegalArgument): (IntInterval.from_string(interval1) | IntInterval.from_string(interval2)) @mark.parametrize(('interval1', 'interval2', 'result'), ( ('(2, 3]', '[3, 4)', IntInterval.from_string('(2, 4)')), ('(2, 10]', '[3, 40]', IntInterval.from_string('(2, 40]')), ('[0, 0]', '[0, 0]', IntInterval.from_string('[0, 0]')), ('[0, 0]', '(0, 0]', IntInterval.from_string('[0, 0]')), ('[0, 0)', '[0, 0]', IntInterval.from_string('[0, 0]')), ('(2, 2]', '(2, 2]', IntInterval.from_string('(2, 2]')), ('[2, 2)', '[2, 2)', IntInterval.from_string('[2, 2)')), ('(2, 3)', '[3, 4]', IntInterval.from_string('(2, 4]')), ('[2, 3]', '(3, 4)', IntInterval.from_string('[2, 4)')), )) def test_or_operator(self, interval1, interval2, result): assert (IntInterval.from_string(interval1) | IntInterval.from_string(interval2) == result)
class TestComparisonOperators(object): @mark.parametrize( ('comparison', 'result'), ( (IntInterval([1, 3]) == IntInterval([1, 3]), True), (IntInterval([1, 3]) == IntInterval([1, 4]), False), (IntInterval([inf, inf]) == inf, True), (IntInterval([3, 3]) == 3, True), (IntInterval([3, 3]) == 5, False), (IntInterval([3, 3]) == 'something', False), (IntInterval([3, 3]) == DateInterval( [date(2011, 1, 1), date(2011, 1, 1)]), False), (IntInterval.from_string('(,)') == None, False), # noqa (DateInterval(date(2000, 1, 1), date(2001, 1, 1)) == -12312321312312312312123123, False))) def test_eq_operator(self, comparison, result): assert comparison is result @mark.parametrize( ('comparison', 'result'), ( (IntInterval([1, 3]) != IntInterval([1, 3]), False), (IntInterval([1, 3]) != IntInterval([1, 4]), True), (IntInterval([inf, inf]) != inf, False), (IntInterval([3, 3]) != 3, False), (IntInterval([3, 3]) != 5, True), (IntInterval([3, 3]) != 'something', True), (IntInterval.from_string('(,)') != None, True) # noqa )) def test_ne_operator(self, comparison, result): assert comparison is result @mark.parametrize( ('comparison', 'result'), ((IntInterval([1, 3]) > IntInterval([0, 2]), True), (IntInterval( (1, 4)) > 1, False), (IntInterval( (1, 6)) > [1, 6], False), (IntInterval((1, 6)) > 0, True))) def test_gt_operator(self, comparison, result): assert comparison is result @mark.parametrize( ('comparison', 'result'), ((IntInterval([1, 3]) >= IntInterval([0, 2]), True), (IntInterval( (1, 4)) >= 1, False), (IntInterval( (1, 6)) >= [1, 6], False), (IntInterval((1, 6)) >= 0, True))) def test_ge_operator(self, comparison, result): assert comparison is result @mark.parametrize( ('comparison', 'result'), ((IntInterval([0, 2]) < IntInterval([1, 3]), True), (IntInterval([2, 3]) < IntInterval([2, 3]), False), (IntInterval([2, 5]) < 6, True), (IntInterval([2, 5]) < 5, False), (IntInterval([2, 5]) < inf, True))) def test_lt_operator(self, comparison, result): assert comparison is result @mark.parametrize( ('comparison', 'result'), ((IntInterval([0, 2]) <= IntInterval([1, 3]), True), (IntInterval([1, 3]) <= IntInterval([1, 3]), True), (IntInterval([1, 7]) <= 8, True), (IntInterval([1, 6]) <= 5, False), (IntInterval([1, 5]) <= inf, True))) def test_le_operator(self, comparison, result): assert comparison is result def test_integer_comparison(self): assert IntInterval([2, 2]) <= 3 assert IntInterval([1, 3]) >= 0 assert IntInterval([2, 2]) == 2 assert IntInterval([2, 2]) != 3 @mark.parametrize('value', ( IntInterval([0, 2]), 1, 1.0, (-1, 1), )) def test_contains_operator_for_inclusive_interval(self, value): assert value in IntInterval([-1, 2]) @mark.parametrize('value', ( IntInterval([0, 2]), 2, [-1, 1], )) def test_contains_operator_for_non_inclusive_interval(self, value): assert value not in IntInterval((-1, 2)) @mark.parametrize(('interval1', 'interval2', 'expected'), ( (IntInterval((0, 2)), IntInterval((0, 2)), True), (IntInterval([0, 2]), IntInterval([0, 2]), True), (IntInterval.from_string('[0, 2)'), IntInterval.from_string('[0, 2)'), True), (IntInterval.from_string('(0, 2]'), IntInterval.from_string('(0, 2]'), True), (IntInterval((0, 2)), IntInterval((1, 2)), False), (IntInterval((0, 2)), IntInterval((0, 1)), False), (IntInterval((0, 2)), IntInterval([0, 1]), False), (IntInterval((0, 2)), FloatInterval((0, 1)), False), )) def test_hash_operator_with_interval_attributes(self, interval1, interval2, expected): actual = (interval1.__hash__() == interval2.__hash__()) assert actual == expected @mark.parametrize(('contains_check', 'expected'), ( (IntInterval([0, 2]) in { IntInterval([0, 2]): '' }, True), (IntInterval([0, 2]) in { IntInterval((0, 2)): '' }, False), (IntInterval([0, 2]) in set([IntInterval([0, 2])]), True), )) def test_hash_operator_with_collections(self, contains_check, expected): assert contains_check is expected
def test_and_operator_with_half_open_intervals(self, interval1, interval2, result): assert (IntInterval.from_string(interval1) & IntInterval.from_string(interval2) == IntInterval(result))