Exemple #1
0
def _cmp(x, y):
    if eq.eq(x, y) or eq.eq(y, x):
        return 0

    if _lt(x, y):
        return -1

    return 1
Exemple #2
0
def _is_monotonic(elements, inc=True, strict=False):
    """Is the sequence in elements monotonically increasing?

    Args: inc: Direction of monotonicity (increasing or decreasing).
          strict: If true elements may not repeat.
    """
    last = None
    for i, element in enumerate(elements):
        if i == 0:
            last = element
            continue

        # Strict monotonic means this element can not be equal to
        # the last one.
        if eq.eq(element, last):
            if strict:
                return False
            continue

        if inc and _lt(element, last):
            return False

        if not inc and _lt(last, element):
            return False

    return True
Exemple #3
0
def solve_quotient(expr, vars):
    iterators = convert_to_iterators(expr, vars, pad=0)

    # Add each element individually.
    result = []
    for elements in zip(*iterators):
        total = None
        for element in elements:
            if number.isnumber(element):
                if total is None:
                    total = element
                else:
                    # Division by 0.
                    if eq.eq(element, 0):
                        total = None
                        break

                    total = number.quotient(total, element)

            # If we encounter a non-number we swallow the error and
            # return None. This could happen for example if one of the
            # columns in the select returns NoneObject() or something
            # which is not a number.
            else:
                total = None
                break

        result.append(total)

    return Result(result, ())
Exemple #4
0
    def testCompare(self):
        def _generator():
            yield 1
            yield 2
            yield 3

        self.assertTrue(
            eq.eq(lazy_repetition.LazyRepetition(_generator),
                  repeated.meld(1, 2, 3)))
Exemple #5
0
def solve_equivalence(expr, vars):
    iterators = convert_to_iterators(expr, vars, pad=0)

    # Add each element individually.
    for elements in zip(*iterators):
        elements = iter(elements)
        try:
            first = next(elements)
        except StopIteration:
            return Result(True, ())

        if not all(eq.eq(first, rest) for rest in elements):
            return Result(False, ())

    return Result(True, ())
Exemple #6
0
def _scalar_value_eq(x, y):
    if isrepeating(y):
        return False

    return eq.eq(x, getvalue(y))
Exemple #7
0
def _scalar_state_eq(x, y):
    if insuperposition(y):
        return False

    return eq.eq(x, getstate(y))
Exemple #8
0
def _scalar_state_eq(x, y):
    if insuperposition(y):
        return False

    return eq.eq(x, getstate(y))
 def assertValueEq(self, x, y):
     return self.assertTrue(eq.eq(x, y))
Exemple #10
0
def _scalar_value_eq(x, y):
    if isrepeating(y):
        return False

    return eq.eq(x, getvalue(y))