def test_unnamed_constants(): assert from_root('pi').unnamed_constants == set() assert from_numexpr('2').unnamed_constants == {'2'} assert from_numexpr('2e-3').unnamed_constants == {'2e-3'} assert from_numexpr('A').unnamed_constants == set() assert from_numexpr('A + A').unnamed_constants == set() assert from_numexpr('A + B').unnamed_constants == set() assert from_numexpr('A + A*A - 3e7').unnamed_constants == {'3e7'} assert from_numexpr('arctan2(A, A)').unnamed_constants == set() assert from_numexpr('arctan2(A, B)').unnamed_constants == set() assert from_root('arctan2(A, pi)').unnamed_constants == set() assert from_numexpr('arctan2(arctan2(A, B), C)').unnamed_constants == set() for base, expect in [(UC('2'), {'2'}), (Variable('A'), set()), (NC(ConstantIDs.PI), set())]: expr = base for i in list(range(100)): expr = Expression(IDs.SQRT, expr) assert expr.unnamed_constants == expect
def test_get_variables(): assert from_root('pi').variables == set() assert from_numexpr('2').variables == set() assert from_numexpr('2e-3').variables == set() assert from_numexpr('A').variables == set(['A']) assert from_numexpr('A + A').variables == set(['A']) assert from_numexpr('A + B').variables == set(['A', 'B']) assert from_numexpr('A + A*A - 3e7').variables == set(['A']) assert from_numexpr('arctan2(A, A)').variables == set(['A']) assert from_numexpr('arctan2(A, B)').variables == set(['A', 'B']) assert from_root('arctan2(A, pi)').variables == set(['A']) assert from_numexpr('arctan2(arctan2(A, B), C)').variables == set( ['A', 'B', 'C']) for base, expect in [(UC('2'), set()), (Variable('A'), set(['A'])), (NC(ConstantIDs.PI), set())]: expr = base for i in list(range(100)): expr = Expression(IDs.SQRT, expr) assert expr.variables == expect
NewTestClass.__name__ = name return NewTestClass TestPosInts = _create_test_type('TestPosInts', UC('1'), UC('2'), UC('3'), UC('4')) TestNegInts = _create_test_type('TestNegInts', UC('-1'), UC('-2'), UC('-3'), UC('-4')) TestMixInts = _create_test_type('TestMixInts', UC('1'), UC('-2'), UC('3'), UC('-4')) TestPosFloats = _create_test_type('TestPosFloats', UC('1.2'), UC('3.4'), UC('4.5'), UC('6.7')) TestNegFloats = _create_test_type('TestNegFloats', UC('-1.2'), UC('-3.4'), UC('-4.5'), UC('-6.7')) TestMixFloats = _create_test_type('TestMixFloats', UC('1.2'), UC('-3.4'), UC('4.5'), UC('-6.7')) TestPosScientific = _create_test_type('TestPosScientific', UC('1e-2'), UC('3.4e5'), UC('6.7e8'), UC('9e10')) TestNegScientific = _create_test_type('TestNegScientific', UC('-1e-2'), UC('-3.4e5'), UC('-6.7e8'), UC('-9e10')) TestMixScientific = _create_test_type('TestMixScientific', UC('1e-2'), UC('-3.4e5'), UC('6.7e8'), UC('-9e10')) TestVariables = _create_test_type('TestVariables', Variable('A'), Variable('Bee'), Variable('C_is_4'), Variable('_Dxyz'))