Exemplo n.º 1
0
def test_extended():
    def f(x, y, z): return x + 2 * y + 3 * z
    g = Extended(f)
    assert_equal(tuple(describe(g)), ('x', 'y', 'z', 'N'))
    assert_equal(g(1, 2, 3, 4), 4 * (f(1, 2, 3)))

    # extended should use analytical when available
    def ana_int(x, y): return y * x ** 2
    ana_int_int = lambda b, n, y: 999.  # wrong on purpose
    ana_int.integrate = ana_int_int
    g = Extended(ana_int)
    assert_almost_equal(g.integrate((0, 1), 100, 5., 2.), 999.*2.)

    # and not fail when it's not available
    def no_ana_int(x, y): return y * x ** 2
    g = Extended(no_ana_int)
    assert_almost_equal(g.integrate((0, 1), 100, 5., 2.), (1.**3) / 3.*5.*2.)
Exemplo n.º 2
0
def test_extended():
    def f(x, y, z):
        return x + 2 * y + 3 * z

    g = Extended(f)
    assert describe(g) == ["x", "y", "z", "N"]
    assert_equal(g(1, 2, 3, 4), 4 * (f(1, 2, 3)))

    # extended should use analytical when available
    def ana_int(x, y):
        return y * x**2

    ana_int_int = lambda b, n, y: 999.0  # wrong on purpose
    ana_int.integrate = ana_int_int
    g = Extended(ana_int)
    assert_almost_equal(g.integrate((0, 1), 100, 5.0, 2.0), 999.0 * 2.0)

    # and not fail when it's not available
    def no_ana_int(x, y):
        return y * x**2

    g = Extended(no_ana_int)
    assert_almost_equal(g.integrate((0, 1), 100, 5.0, 2.0),
                        (1.0**3) / 3.0 * 5.0 * 2.0)