Commit 82edcd47 authored by Tim Keil's avatar Tim Keil

[pymortest] more tests for nested sums and products

parent 9492d2e5
......@@ -42,10 +42,12 @@ def test_lincomb_function():
for one in (ConstantFunction(1.0, dim_domain=steps),
GenericFunction(lambda X: np.ones(X.shape[:-1]), dim_domain=steps), 1.0):
add = (zero + one) + 1 - 1
add_ = 1 - 1 + (zero + one)
sub = (zero - one) + np.zeros(())
neg = - zero
assert np.allclose(sub(x), [-1])
assert np.allclose(add(x), [1.0])
assert np.allclose(add_(x), [1.0])
assert np.allclose(neg(x), [0.0])
(repr(add), str(add), repr(one), str(one)) # just to cover the respective special funcs too
mul = neg * 1. * 1.
......
......@@ -23,14 +23,18 @@ def test_LincombParameterFunctional():
zero = pf - pf
two_pf = pf + pf
two_pf_named = two_pf.with_(name='some_interesting_quantity')
three_pf = pf + 2*pf
three_pf_ = pf + two_pf
three_pf_named = pf + two_pf_named
pf_plus_one = pf + 1
pf_plus_one_ = 1 + pf
sum_ = epf + pf + 1 - 3
pf_squared_ = pf * pf
pf_squared_named = pf_squared_.with_(name='some_interesting_quantity')
pf_times_pf_squared = pf * pf_squared_
pf_squared = (pf + 2*epf) * (pf - 2*epf) + 4 * epf * epf * 1
pf_times_pf_squared_named = pf * pf_squared_named
pf_squared = 4 * epf * epf * 1 + (pf + 2*epf) * (pf - 2*epf)
assert zero(mu) == 0
assert two_pf(mu) == 2 * pf(mu)
......@@ -40,8 +44,17 @@ def test_LincombParameterFunctional():
assert pf_plus_one_(mu) == pf(mu) + 1
assert sum_(mu) == epf(mu) + pf(mu) + 1 - 3
assert pf_squared_(mu) == pf(mu) * pf(mu)
assert pf_times_pf_squared(mu) == pf(mu) * pf(mu) * pf(mu)
assert pf_squared(mu) == pf(mu) * pf(mu)
assert pf_times_pf_squared(mu) == pf(mu) * pf(mu) * pf(mu)
# derivatives are linear
assert sum_.d_mu('mu', 0)(mu) == epf.d_mu('mu', 0)(mu) + pf.d_mu('mu', 0)(mu)
assert sum_.d_mu('mu', 1)(mu) == epf.d_mu('mu', 1)(mu) + pf.d_mu('mu', 1)(mu)
assert sum_.d_mu('nu', 0)(mu) == epf.d_mu('nu', 0)(mu) + pf.d_mu('nu', 0)(mu)
# sums and products are not nested
assert len(sum_.coefficients) == 4
assert len(pf_squared.functionals[0].factors) == 4
# named functions will not be merged and still be nested
assert three_pf_named(mu) == three_pf_(mu)
assert len(three_pf_named.coefficients) != len(three_pf_.coefficients)
assert pf_times_pf_squared_named(mu) == pf_times_pf_squared(mu)
assert len(pf_times_pf_squared_named.factors) != len(pf_times_pf_squared.factors)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment