Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle convention (low priority). #97

Open
github-actions bot opened this issue Jul 26, 2022 · 0 comments
Open

handle convention (low priority). #97

github-actions bot opened this issue Jul 26, 2022 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

# TODO: handle convention (low priority).

        else:
            return False

    # TODO: handle convention (low priority).
    def __mul__(self, other) -> Value:

        def intersection_with_constant(first_value: Constant, second_value: Value) -> Value:
            if isinstance(first_value, Constant):
                if second_value.is_in(first_value.value):
                    return first_value
                else:
                    raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
            else:
                raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)

        def intersection_with_outside(first_value: Outside, second_value: Value) -> Value:
            if isinstance(first_value, Outside):
                if isinstance(second_value, LessThan):
                    if second_value.value <= first_value.lower:
                        return second_value
                    elif first_value.is_in(second_value.value):
                        return LessThan(first_value.lower)
                    else:
                        raise _NOT_IMPLEMENTED_INTERSECTION(first_value, second_value)
                elif isinstance(second_value, GreaterThan):
                    if second_value.value >= first_value.lower:
                        return GreaterThan(first_value.upper)
                    elif first_value.is_in(second_value.value):
                        return second_value
                    else:
                        raise _NOT_IMPLEMENTED_INTERSECTION(first_value, second_value)
                elif isinstance(second_value, Constant):
                    if not first_value.is_in(second_value.value):
                        return second_value
                    else:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                elif isinstance(second_value, Between):
                    if second_value in first_value:
                        return second_value
                    elif second_value.lower <= first_value.lower <= second_value.upper <= first_value.upper:
                        return Between(second_value.lower, first_value.lower)
                    elif first_value.lower <= second_value.lower <= first_value.upper <= second_value.upper:
                        return Between(first_value.upper, second_value.upper)
                    else:
                        raise _NOT_IMPLEMENTED_INTERSECTION(first_value, second_value)
                elif isinstance(second_value, Outside):
                    if second_value.lower <= first_value.lower and second_value.upper >= first_value.upper:
                        return second_value
                    elif first_value.lower <= second_value.lower and first_value.upper >= second_value.upper:
                        return first_value
                    else:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                elif isinstance(second_value, Constant):
                    intersection_with_constant(second_value, first_value)
                else:
                    raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
            else:
                raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)

        def intersection_with_between(first_value: Between, second_value: Value) -> Value:
            if isinstance(first_value, Between):
                if isinstance(second_value, LessThan):
                    if second_value.value <= first_value.lower:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                    elif first_value.lower <= second_value.value <= first_value.upper:
                        return Between(first_value.lower, second_value.value)
                    else:
                        return first_value
                elif isinstance(second_value, GreaterThan):
                    if second_value.value <= first_value.lower:
                        return first_value
                    elif first_value.lower <= second_value.value <= first_value.upper:
                        return Between(second_value.value, first_value.upper)
                    else:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                elif isinstance(second_value, Between):
                    if second_value in first_value:
                        return second_value
                    elif first_value in second_value:
                        return first_value
                    elif first_value.lower <= second_value.lower <= first_value.upper:
                        return Between(second_value.lower, first_value.upper)
                    elif second_value.lower <= first_value.lower <= second_value.upper:
                        return Between(first_value.lower, second_value.upper)
                    elif first_value.lower <= second_value.upper <= first_value.upper:
                        return Between(first_value.lower, second_value.upper)
                    elif second_value.lower <= first_value.upper <= second_value.upper:
                        return Between(second_value.lower, first_value.upper)
                    else:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                elif isinstance(second_value, Constant):
                    intersection_with_constant(second_value, first_value)
                elif isinstance(second_value, Outside):
                    return intersection_with_outside(second_value, first_value)
                else:
                    raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
            else:
                raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)

        def intersection_with_less_than(first_value: LessThan, second_value: Value) -> Value:
            if isinstance(first_value, LessThan):
                if isinstance(second_value, LessThan):
                    return first_value if first_value in second_value else second_value
                elif isinstance(second_value, GreaterThan):
                    if second_value.value <= first_value.value:
                        return Between(second_value.value, first_value.value)
                    else:
                        raise _EMPTY_INTERSECTION_EXCEPTION(first_value, second_value)
                elif isinstance(second_value, Constant):
                    return intersection_with_constant(second_value, first_value)
                elif isinstance(second_value, Outside):
                    return intersection_with_outside(second_value, first_value)
                elif isinstance(second_value, Between):
                    return intersection_with_between(second_value, first_value)
                else:
                    raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
            else:
                raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)

        def intersection_with_greater_than(first_value: GreaterThan, second_value: Value) -> Value:
            if isinstance(first_value, GreaterThan):
                if isinstance(second_value, GreaterThan):
                    return first_value if first_value in second_value else second_value
                elif isinstance(second_value, Constant):
                    return intersection_with_constant(second_value, first_value)
                elif isinstance(second_value, Outside):
                    return intersection_with_outside(second_value, first_value)
                elif isinstance(second_value, Between):
                    return intersection_with_between(second_value, first_value)
                elif isinstance(second_value, LessThan):
                    return intersection_with_less_than(second_value, first_value)
                else:
                    raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)
            else:
                raise _INTERSECTION_WITH_WRONG_TYPE(first_value, second_value)

        if other is None:
            return self
        elif isinstance(self, Constant):
            return intersection_with_constant(self, other)
        elif isinstance(self, Outside):
            return intersection_with_outside(self, other)
        elif isinstance(self, Between):
            return intersection_with_between(self, other)
        elif isinstance(self, LessThan):
            return intersection_with_less_than(self, other)
        elif isinstance(self, GreaterThan):
            return intersection_with_greater_than(self, other)
        else:
            raise _INTERSECTION_WITH_WRONG_TYPE(self, other)


class Interval(Value):

    def __init__(self, lower: float, upper: float, standard: bool = True):
        super().__init__()
        self.standard = standard
        self.lower = lower
        self.upper = upper
@github-actions github-actions bot added the todo label Jul 26, 2022
@MatteoMagnini MatteoMagnini self-assigned this Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant