def test_point_lower(self): _check_permutations(self, [ Case( point(3), LowerLimit(5), union=PosNeg(LowerLimit(3), UpperLimit(3 - 1)), intersection=PosNeg(empty, unlimited), ), Case( point(4), LowerLimit(5), union=PosNeg(LowerLimit(4), UpperLimit(4 - 1)), intersection=PosNeg(empty, unlimited), ), Case( point(5), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(point(5), unlimited), ), Case( point(6), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(point(6), unlimited), ), Case( point(7), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(point(7), unlimited), ), ])
def test_upper_upper(self): _check_permutations(self, [ Case( UpperLimit(3), UpperLimit(5), union=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), intersection=PosNeg(UpperLimit(3), LowerLimit(3 + 1)), ), Case( UpperLimit(4), UpperLimit(5), union=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), intersection=PosNeg(UpperLimit(4), LowerLimit(4 + 1)), ), Case( UpperLimit(5), UpperLimit(5), union=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), intersection=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), ), Case( UpperLimit(6), UpperLimit(5), union=PosNeg(UpperLimit(6), LowerLimit(6 + 1)), intersection=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), ), Case( UpperLimit(7), UpperLimit(5), union=PosNeg(UpperLimit(7), LowerLimit(7 + 1)), intersection=PosNeg(UpperLimit(5), LowerLimit(5 + 1)), ), ])
def test_lower_upper(self): _check_permutations(self, [ Case( LowerLimit(3), UpperLimit(5), union=PosNeg(unlimited, empty), intersection=PosNeg(Finite(3, 5), unlimited), ), Case( LowerLimit(4), UpperLimit(5), union=PosNeg(unlimited, empty), intersection=PosNeg(Finite(4, 5), unlimited), ), Case( LowerLimit(5), UpperLimit(5), union=PosNeg(unlimited, empty), intersection=PosNeg(point(5), unlimited), ), Case( LowerLimit(6), UpperLimit(5), union=PosNeg(unlimited, empty), intersection=PosNeg(empty, unlimited), ), Case( LowerLimit(7), UpperLimit(5), union=PosNeg(unlimited, empty), intersection=PosNeg(empty, unlimited), ), ])
def test_lower_unlimited(self): _check_permutations(self, [ Case( LowerLimit(7), unlimited, union=PosNeg(unlimited, empty), intersection=PosNeg(LowerLimit(7), UpperLimit(7 - 1)), ), ])
def test_upper_finite(self): _check_permutations(self, [ Case( UpperLimit(3), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(empty, unlimited), ), Case( UpperLimit(4), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(empty, unlimited), ), Case( UpperLimit(5), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(point(5), unlimited), ), Case( UpperLimit(6), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(Finite(5, 6), unlimited), ), Case( UpperLimit(7), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(Finite(5, 7), unlimited), ), Case( UpperLimit(8), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(Finite(5, 8), unlimited), ), Case( UpperLimit(9), Finite(5, 9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), Case( UpperLimit(10), Finite(5, 9), union=PosNeg(UpperLimit(10), LowerLimit(10 + 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), Case( UpperLimit(11), Finite(5, 9), union=PosNeg(UpperLimit(11), LowerLimit(11 + 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), ])
def test__unknown_class_is_limited_interval(self): _check_adaption_variant_cases( self, interval_of_unknown_class=LowerLimit(-200), cases=[ CaseWAdaptionVariants( 'two operands, one wo interval', Disjunction([ _MatcherWInterval(Finite(-70, 60)), _matcher_wo_interval(), ]), [ _without_adaption( asrt_interval.matches_lower_limit(-200)), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-200, 50)), ], ), CaseWAdaptionVariants( 'two operands, all wo interval', Disjunction([ _matcher_wo_interval(), _matcher_wo_interval(), ]), [ _without_adaption( asrt_interval.matches_lower_limit(-200)), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-200, 50)), ], ), CaseWAdaptionVariants( 'three operands, one wo interval', Disjunction([ _MatcherWInterval(LowerLimit(-3)), _matcher_wo_interval(), _MatcherWInterval(LowerLimit(-7)), ]), [ _without_adaption( asrt_interval.matches_lower_limit(-200)), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-200, 50)), ], ), ])
def test_upper_empty(self): _check_permutations(self, [ Case( UpperLimit(7), empty, union=PosNeg(UpperLimit(7), LowerLimit(7 + 1)), intersection=PosNeg(empty, unlimited), ), ])
def test_non_complex(self): _check_adaption_variant_cases( self, interval_of_unknown_class=unlimited_with_unlimited_inversion(), cases=[ CaseWAdaptionVariants( 'constant F', Negation(_constant_wo_interval(False)), [ _without_adaption(_equals_interval(Unlimited())), _w_max_upper_adaption( 20, _equals_interval(UpperLimit(20))), ], ), CaseWAdaptionVariants( 'constant T', Negation(_constant_wo_interval(True)), [ _without_adaption(_equals_interval(Empty())), _w_max_upper_adaption(20, _equals_interval(Empty())), ], ), CaseWAdaptionVariants( 'matcher w interval / point', Negation(_MatcherWInterval(point(5))), [ _without_adaption(_equals_negation_of(point(5))), _w_max_upper_adaption( 20, _equals_interval(UpperLimit(20))), ], ), CaseWAdaptionVariants( 'matcher w interval / upper limit', Negation(_MatcherWInterval(UpperLimit(10))), [ _without_adaption(_equals_interval( LowerLimit(10 + 1))), _w_max_upper_adaption( 20, _equals_interval(Finite(10 + 1, 20))), ], ), CaseWAdaptionVariants( 'matcher wo interval', Negation(_matcher_wo_interval()), [ _without_adaption( _equals_interval( unlimited_with_unlimited_inversion())), _w_max_upper_adaption( 20, _equals_interval(UpperLimit(20))), ], ), ])
def _of(lower: Optional[int], upper: Optional[int]) -> IntIntervalWInversion: """ lower < upper, if both are not None """ if lower is None: if upper is None: return Unlimited() else: return UpperLimit(upper) else: if upper is None: return LowerLimit(lower) else: return Finite(lower, upper)
def test_point_upper(self): _check_permutations(self, [ Case( point(-3), UpperLimit(0), union=PosNeg(UpperLimit(0), LowerLimit(0 + 1)), intersection=PosNeg(point(-3), unlimited), ), Case( point(6), UpperLimit(9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(point(6), unlimited), ), Case( point(7), UpperLimit(9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(point(7), unlimited), ), Case( point(8), UpperLimit(9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(point(8), unlimited), ), Case( point(9), UpperLimit(9), union=PosNeg(UpperLimit(9), LowerLimit(9 + 1)), intersection=PosNeg(point(9), unlimited), ), Case( point(10), UpperLimit(9), union=PosNeg(UpperLimit(10), LowerLimit(10 + 1)), intersection=PosNeg(empty, unlimited), ), Case( point(11), UpperLimit(9), union=PosNeg(UpperLimit(11), LowerLimit(11 + 1)), intersection=PosNeg(empty, unlimited), ), ])
def test_lower_finite(self): _check_permutations(self, [ Case( LowerLimit(3), Finite(5, 9), union=PosNeg(LowerLimit(3), UpperLimit(3 - 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), Case( LowerLimit(4), Finite(5, 9), union=PosNeg(LowerLimit(4), UpperLimit(4 - 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), Case( LowerLimit(5), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(Finite(5, 9), unlimited), ), Case( LowerLimit(6), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(Finite(6, 9), unlimited), ), Case( LowerLimit(7), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(Finite(7, 9), unlimited), ), Case( LowerLimit(8), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(Finite(8, 9), unlimited), ), Case( LowerLimit(9), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(point(9), unlimited), ), Case( LowerLimit(10), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(empty, unlimited), ), Case( LowerLimit(11), Finite(5, 9), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(empty, unlimited), ), ])
def test_lower_lower(self): _check_permutations(self, [ Case( LowerLimit(3), LowerLimit(5), union=PosNeg(LowerLimit(3), UpperLimit(3 - 1)), intersection=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), ), Case( LowerLimit(4), LowerLimit(5), union=PosNeg(LowerLimit(4), UpperLimit(4 - 1)), intersection=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), ), Case( LowerLimit(5), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), ), Case( LowerLimit(6), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(LowerLimit(6), UpperLimit(6 - 1)), ), Case( LowerLimit(7), LowerLimit(5), union=PosNeg(LowerLimit(5), UpperLimit(5 - 1)), intersection=PosNeg(LowerLimit(7), UpperLimit(7 - 1)), ), ])
def test__unknown_class_is_unlimited_w_unlimited_negation(self): _check_adaption_variant_cases( self, interval_of_unknown_class=unlimited_with_unlimited_inversion(), cases=[ CaseWAdaptionVariants( 'two operands', Disjunction([ _MatcherWInterval(Finite(-72, 69 + 5)), _MatcherWInterval(Finite(-72 - 9, 69)), ]), [ _without_adaption( _equals_interval(Finite(-72 - 9, 69 + 5))), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-72 - 9, 50)) ], ), CaseWAdaptionVariants( 'two operands, one wo interval', Disjunction([ _MatcherWInterval(Finite(-72, 69 + 5)), _matcher_wo_interval(), ]), [ _without_adaption(_equals_interval(Unlimited())), _w_max_upper_adaption( 50, asrt_interval.matches_upper_limit(50)) ], ), CaseWAdaptionVariants( 'two operands, all wo interval', Disjunction([ _matcher_wo_interval(), _matcher_wo_interval(), ]), [ _without_adaption(_equals_interval(Unlimited())), _w_max_upper_adaption( 50, asrt_interval.matches_upper_limit(50)) ], ), CaseWAdaptionVariants( 'three operands', Disjunction([ _MatcherWInterval(LowerLimit(-3)), _MatcherWInterval(LowerLimit(-11)), _MatcherWInterval(LowerLimit(-7)), ]), [ _without_adaption(_equals_interval(LowerLimit(-11))), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-11, 50)) ], ), CaseWAdaptionVariants( 'three operands, one wo interval', Disjunction([ _MatcherWInterval(LowerLimit(-3)), _matcher_wo_interval(), _MatcherWInterval(LowerLimit(-7)), ]), [ _without_adaption(_equals_interval(Unlimited())), _w_max_upper_adaption( 50, asrt_interval.matches_upper_limit(50)) ], ), ])
def test__unknown_class_is_limited(self): _check_adaption_variant_cases( self, interval_of_unknown_class=UpperLimit(100), cases=[ CaseWAdaptionVariants( 'two operands', Conjunction([ _MatcherWInterval(Finite(-72, 69 + 5)), _MatcherWInterval(Finite(-72 - 9, 69)), ]), [ _without_adaption(_equals_interval(Finite(-72, 69))), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-72, 50)), ], ), CaseWAdaptionVariants( 'two operands, one wo interval', Conjunction([ _MatcherWInterval(Finite(-70, 200)), _matcher_wo_interval(), ]), [ _without_adaption( asrt_interval.matches_finite(-70, 100)), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-70, 50)), ], ), CaseWAdaptionVariants( 'two operands, all wo interval', Conjunction([ _matcher_wo_interval(), _matcher_wo_interval(), ]), [ _without_adaption( asrt_interval.matches_upper_limit(100)), _w_max_upper_adaption( 200, asrt_interval.matches_upper_limit(100)), ], ), CaseWAdaptionVariants( 'three operands', Conjunction([ _MatcherWInterval(LowerLimit(-3)), _MatcherWInterval(LowerLimit(-11)), _MatcherWInterval(LowerLimit(-7)), ]), [ _without_adaption(_equals_interval(LowerLimit(-3))), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-3, 50)), ], ), CaseWAdaptionVariants( 'three operands, one wo interval', Conjunction([ _MatcherWInterval(LowerLimit(-3)), _matcher_wo_interval(), _MatcherWInterval(LowerLimit(-7)), ]), [ _without_adaption(_equals_interval(Finite(-3, 100))), _w_max_upper_adaption( 50, asrt_interval.matches_finite(-3, 50)), ], ), ])
def test_negation_of_disjunction_should_distribute_negation(self): _check_adaption_variant_cases( self, interval_of_unknown_class=unlimited_with_unlimited_inversion(), cases=[ CaseWAdaptionVariants( 'two operands, all w normal negation', Negation( Disjunction([ _MatcherWInterval(UpperLimit(10)), _MatcherWInterval(UpperLimit(10 + 5)), ])), [ _without_adaption( _equals_interval(LowerLimit(10 + 5 + 1))), _w_max_upper_adaption( 20, _equals_interval(Finite(10 + 5 + 1, 20))), ], ), CaseWAdaptionVariants( 'two operands, one w unlimited-w-unlimited-negation', Negation( Disjunction([ _MatcherWInterval(UpperLimit(0)), _matcher_wo_interval(), ])), [ _without_adaption(_equals_interval(LowerLimit(0 + 1))), _w_max_upper_adaption( 20, _equals_interval(Finite(0 + 1, 20))), ], ), CaseWAdaptionVariants( 'nested negation of disjunction, one w unlimited-w-unlimited-negation', Negation( Disjunction([ Negation( Disjunction([ _MatcherWInterval(UpperLimit(0)), _matcher_wo_interval(), ])), _MatcherWInterval(UpperLimit(10 - 1)), ])), [ _without_adaption(_equals_interval(LowerLimit(10))), _w_max_upper_adaption( 20, _equals_interval(Finite(10, 20))), ], ), CaseWAdaptionVariants( 'nested negation of conjunction, one w unlimited-w-unlimited-negation', Negation( Disjunction([ Negation( Conjunction([ _MatcherWInterval(UpperLimit(20)), _matcher_wo_interval(), ])), _MatcherWInterval(UpperLimit(10)), ])), [ _without_adaption(_equals_interval(Finite(10 + 1, 20))), _w_max_upper_adaption( 15, _equals_interval(Finite(10 + 1, 15))), ], ), ])