예제 #1
0
def test_changing_expression():
    """Change expression and get value."""

    formula = Formula("2*asin(x)", 16)
    assert formula.get({"x": "1"}) == "3.1415926535897932384626433832795"
    assert formula.expression == "2*asin(x)"
    formula.set_expression("asin(x)")
    assert formula.get({"x": "1"}) == "1.57079632679489661923132169163975"
    formula.expression = "sin(x)"
    assert formula.get({"x":
                        "1"}) == "0.8414709848078965066609974948209608755664"
예제 #2
0
def test_formula_object_copy():
    """Compare Formula objects."""

    formula = Formula("2*log(1)", 99)
    formula2 = formula.copy()
    assert formula2 != formula
    assert formula2 is not formula
    assert formula2.expression == formula.expression
    assert formula2.precision == formula.precision
    assert formula2.get() == formula.get()
    formula.expression = "1"
    assert formula.get() == "1"
    assert formula2.get() != formula.get()
예제 #3
0
def test_changing_precision():
    """Change precision on the fly."""

    formula = Formula("2*asin(x)", 16)
    assert formula.get({"x": "1"})[0:16] == "3.14159265358979"
    assert formula.get({"x": "1"}, 10) == "3.141592654"
    formula.precision = 24
    digits = 18
    format_flags = FmtFlags.fixed
    assert formula.get({"x": "1"}, digits,
                       format_flags) == "3.141592653589793238"
    formula.set_precision(240)
    assert formula.precision == 256
    assert (formula.get({"x": "1"})[0:256] ==
            "3.141592653589793238462643383279502884197169399375105820974944"
            "59230781640628620899862803482534211706798214808651328230664709"
            "38446095505822317253594081284811174502841027019385211055596446"
            "22948954930381964428810975665933446128475648233786783165271201"
            "90914564")