예제 #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
예제 #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
예제 #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)
예제 #4
0
 def simplify(self, node):
     expr, expected_map = node
     expr = simplify(expr)
     note(dump(expr))
     return expr, expected_map
예제 #5
0
파일: conftest.py 프로젝트: encukou/gillcup
 def check_dump(expression, expected):
     dumped = dump(expression)
     print(dumped)
     expected = textwrap.dedent(expected.strip('\n').rstrip())
     assert dumped == expected
예제 #6
0
def check_depth(exp, depth):
    print(dump(exp))
    assert get_depth(exp) == depth