コード例 #1
0
def test_sqrt():
    prntr = PythonCodePrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == 'math.sqrt(x)'
    assert prntr._print_Pow(1 / sqrt(x), rational=False) == '1/math.sqrt(x)'

    prntr = PythonCodePrinter({'standard': 'python2'})
    assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1./2.)'
    assert prntr._print_Pow(1 / sqrt(x), rational=True) == 'x**(-1./2.)'

    prntr = PythonCodePrinter({'standard': 'python3'})
    assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1/2)'
    assert prntr._print_Pow(1 / sqrt(x), rational=True) == 'x**(-1/2)'

    prntr = MpmathPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == 'mpmath.sqrt(x)'
    assert prntr._print_Pow(sqrt(x), rational=True) == \
        "x**(mpmath.mpf(1)/mpmath.mpf(2))"

    prntr = NumPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == 'numpy.sqrt(x)'
    assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1/2)'

    prntr = SciPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == 'numpy.sqrt(x)'
    assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1/2)'

    prntr = SymPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == 'sympy.sqrt(x)'
    assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1/2)'
コード例 #2
0
ファイル: test_pycode.py プロジェクト: msgoff/sympy
def test_sqrt():
    prntr = PythonCodePrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == "math.sqrt(x)"
    assert prntr._print_Pow(1 / sqrt(x), rational=False) == "1/math.sqrt(x)"

    prntr = PythonCodePrinter({"standard": "python2"})
    assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1./2.)"
    assert prntr._print_Pow(1 / sqrt(x), rational=True) == "x**(-1./2.)"

    prntr = PythonCodePrinter({"standard": "python3"})
    assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1/2)"
    assert prntr._print_Pow(1 / sqrt(x), rational=True) == "x**(-1/2)"

    prntr = MpmathPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == "mpmath.sqrt(x)"
    assert (prntr._print_Pow(
        sqrt(x), rational=True) == "x**(mpmath.mpf(1)/mpmath.mpf(2))")

    prntr = NumPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == "numpy.sqrt(x)"
    assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1/2)"

    prntr = SciPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == "numpy.sqrt(x)"
    assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1/2)"

    prntr = SymPyPrinter()
    assert prntr._print_Pow(sqrt(x), rational=False) == "sympy.sqrt(x)"
    assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1/2)"
コード例 #3
0
ファイル: test_pycode.py プロジェクト: sidhu1012/sympy
def test_frac():
    from sympy.functions.elementary.integers import frac

    expr = frac(x)
    prntr = NumPyPrinter()
    assert prntr.doprint(expr) == 'numpy.mod(x, 1)'

    prntr = SciPyPrinter()
    assert prntr.doprint(expr) == 'numpy.mod(x, 1)'

    prntr = PythonCodePrinter()
    assert prntr.doprint(expr) == 'x % 1'

    prntr = MpmathPrinter()
    assert prntr.doprint(expr) == 'mpmath.frac(x)'

    prntr = SymPyPrinter()
    assert prntr.doprint(expr) == 'sympy.functions.elementary.integers.frac(x)'