Exemplo n.º 1
0
def check_formula(numpy, formula, expected_args, got_args):
    if numpy:
        expected = formula(*(numpy.array(a, dtype=float)
                             for a in expected_args))
    else:
        try:
            expected = formula(*expected_args)
        except ZeroDivisionError:
            print('cannot check zero division without numpy')
            return
    got = formula(*got_args)
    print(dump(got))
    if math.isnan(got):
        assert isinstance(expected, complex) or math.isnan(expected)
    elif (numpy and formula is FLOORDIV_OPERATOR and expected == 0 and
          got == -1):
        # http://bugs.python.org/issue22198
        # TODO: remove this case, and inline FLOORDIV_OPERATOR, when fixed
        raise pytest.xfail('ran into python bug 22198')
    elif (numpy and formula is FLOORDIV_OPERATOR and
          expected_args[0] < 0 and
          expected_args[-1] == 0):
        raise pytest.xfail('Floor-dividing negative num by zero with numpy')
    else:
        assert expected == got
    return got
Exemplo n.º 2
0
def reduce_to_const(exp):
    repl_available = Flag(simplify(exp) is not exp)
    exp.replacement_available.connect(repl_available.set)
    yield exp
    print(dump(simplify(exp)))
    assert all(exp == simplify(exp))
    assert isinstance(simplify(exp), Constant), type(exp.replacement)
    assert repl_available
Exemplo n.º 3
0
 def check_equiv(self, tree):
     got, expected_map = tree
     for settings, expected_value in expected_map.items():
         note('settings: {}'.format(settings))
         note('expected: {}'.format(expected_value))
         for setting in settings:
             setting.value.set(setting.number)
         note(dump(got, show_ids=True))
         if isnan(expected_value) or isinf(expected_value):
             assert isnan(got) or isinf(got)
         else:
             assert isclose(float(got), expected_value, abs_tol=1e-09)
Exemplo n.º 4
0
 def simplify(self, node):
     expr, expected_map = node
     expr = simplify(expr)
     note(dump(expr))
     return expr, expected_map
Exemplo n.º 5
0
 def check_dump(expression, expected):
     dumped = dump(expression)
     print(dumped)
     expected = textwrap.dedent(expected.strip('\n').rstrip())
     assert dumped == expected
Exemplo n.º 6
0
def check_depth(exp, depth):
    print(dump(exp))
    assert get_depth(exp) == depth