Exemplo n.º 1
0
 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))),
                 ],
             ),
         ])
Exemplo n.º 2
0
from typing import Iterator, Tuple, Callable

from exactly_lib.type_val_prims.matcher.line_matcher import LineMatcherLine, FIRST_LINE_NUMBER
from exactly_lib.util.functional import map_optional
from exactly_lib.util.interval.int_interval import IntInterval
from exactly_lib.util.interval.w_inversion import intervals
from exactly_lib.util.interval.w_inversion.interval import IntIntervalWInversion

LINES_INTERVAL_FOR_UNKNOWN_INTERVAL = intervals.unlimited_with_unlimited_inversion(
)

FullContentsAndLineMatcherLine = Tuple[str, LineMatcherLine]


def adapt_to_line_num_range(
        interval: IntIntervalWInversion) -> IntIntervalWInversion:
    """
    :return: All non-None values >= FIRST_LINE_NUMBER.
    lower > FIRST_LINE_NUMBER (if not None)
    """
    if interval.is_empty:
        return interval
    if interval.upper is not None and interval.upper < FIRST_LINE_NUMBER:
        return intervals.Empty()

    lower = map_optional(_adapt_limit, interval.lower)
    if lower == FIRST_LINE_NUMBER:
        lower = None
    upper = map_optional(_adapt_limit, interval.upper)

    if lower is None:
Exemplo n.º 3
0
        _get_int_interval_of_int_matcher,
    )


_MATCHER_PARSER = parse_integer_matcher.parsers().simple


def _operand_from_model_sdv() -> PropertyGetterSdv[LineMatcherLine, int]:
    return property_getters.PropertyGetterSdvConstant(
        property_getters.PropertyGetterDdvConstant(_PropertyGetter(), ))


class _PropertyGetter(property_getters.PropertyGetter[LineMatcherLine, int],
                      WithCachedNodeDescriptionBase):
    def _structure(self) -> StructureRenderer:
        return renderers.header_only(_NAME)

    def get_from(self, model: LineMatcherLine) -> int:
        return model[0]


def _get_int_interval_of_int_matcher(
        matcher: IntegerMatcher) -> IntIntervalWInversion:
    return matcher_interval.interval_of__w_inversion(
        matcher, _INTERVAL_OF_UNKNOWN_INT_MATCHER,
        matcher_interval.no_adaption)


_INTERVAL_OF_UNKNOWN_INT_MATCHER = intervals.unlimited_with_unlimited_inversion(
)
Exemplo n.º 4
0
 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))
                 ],
             ),
         ])
Exemplo n.º 5
0
 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))),
                 ],
             ),
         ])
Exemplo n.º 6
0
 def test_double_negation(self):
     _check_adaption_variant_cases(
         self,
         interval_of_unknown_class=unlimited_with_unlimited_inversion(),
         cases=[
             CaseWAdaptionVariants(
                 'constant F',
                 Negation(Negation(_constant_wo_interval(False))),
                 [
                     _without_adaption(_equals_interval(Empty())),
                     _w_max_upper_adaption(20, _equals_interval(Empty())),
                 ],
             ),
             CaseWAdaptionVariants(
                 'constant T',
                 Negation(Negation(_constant_wo_interval(True))),
                 [
                     _without_adaption(_equals_interval(Unlimited())),
                     _w_max_upper_adaption(
                         20, _equals_interval(UpperLimit(20))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'matcher w interval / point',
                 Negation(Negation(_MatcherWInterval(point(5)))),
                 [
                     _without_adaption(_equals_interval(point(5))),
                     _w_max_upper_adaption(0, _equals_interval(Empty())),
                 ],
             ),
             CaseWAdaptionVariants(
                 'matcher w interval / upper limit',
                 Negation(Negation(_MatcherWInterval(UpperLimit(10)))),
                 [
                     _without_adaption(_equals_interval(UpperLimit(10))),
                     _w_max_upper_adaption(5, _equals_interval(
                         UpperLimit(5))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'matcher wo interval',
                 Negation(Negation(_matcher_wo_interval())),
                 [
                     _without_adaption(
                         _equals_interval(
                             unlimited_with_unlimited_inversion())),
                     _w_max_upper_adaption(
                         20, _equals_interval(UpperLimit(20))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'conjunction, all w interval',
                 Negation(
                     Negation(
                         Conjunction([
                             _MatcherWInterval(UpperLimit(10)),
                             _MatcherWInterval(UpperLimit(10 + 5)),
                         ]))),
                 [
                     _without_adaption(_equals_interval(UpperLimit(10))),
                     _w_max_upper_adaption(5, _equals_interval(
                         UpperLimit(5))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'conjunction, one w unlimited-negation',
                 Negation(
                     Negation(
                         Conjunction([
                             _MatcherWInterval(UpperLimit(10)),
                             _matcher_wo_interval(),
                         ]))),
                 [
                     _without_adaption(_equals_interval(UpperLimit(10))),
                     _w_max_upper_adaption(5, _equals_interval(
                         UpperLimit(5))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'disjunction, all w interval',
                 Negation(
                     Negation(
                         Disjunction([
                             _MatcherWInterval(UpperLimit(10)),
                             _MatcherWInterval(UpperLimit(10 + 5)),
                         ]))),
                 [
                     _without_adaption(_equals_interval(
                         UpperLimit(10 + 5))),
                     _w_max_upper_adaption(5, _equals_interval(
                         UpperLimit(5))),
                 ],
             ),
             CaseWAdaptionVariants(
                 'disjunction, one w unlimited-negation',
                 Negation(
                     Negation(
                         Disjunction([
                             _MatcherWInterval(UpperLimit(10)),
                             _matcher_wo_interval(),
                         ]))),
                 [
                     _without_adaption(_equals_interval(Unlimited())),
                     _w_max_upper_adaption(5, _equals_interval(
                         UpperLimit(5))),
                 ],
             ),
         ])