Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikrommyd committed Mar 22, 2024
1 parent e30818c commit 0bf4ec7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/test_pdf_erfexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@ def _erfexp_numpy(x, alpha, beta, gamma, n):

def create_erfexp(alpha, beta, gamma, n, limits):
obs = zfit.Space("obs1", limits=limits)
erfexp = zphys.pdf.ErfExp(alpha=alpha, beta=beta, gamma=gamma, n=n, obs=obs, norm=False)
erfexp = zphys.pdf.ErfExp(alpha=alpha, beta=beta, gamma=gamma, n=n, obs=obs)
return erfexp, obs


def test_erfexp_pdf():
# Test PDF here
erfexp, _ = create_erfexp(alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true, limits=(50, 130))
assert erfexp.pdf(90.0).numpy().item() == pytest.approx(
assert erfexp.pdf(90.0, norm=False).numpy().item() == pytest.approx(
erfexp_numpy(90.0, alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true), rel=1e-8
)
np.testing.assert_allclose(
erfexp.pdf(tf.range(50.0, 130, 10_000)),
erfexp.pdf(tf.range(50.0, 130, 10_000), norm=False),
erfexp_numpy(tf.range(50.0, 130, 10_000), alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true),
rtol=1e-8,
)
np.testing.assert_allclose(
erfexp.pdf(tf.range(50.0, 130, 10_000)),
erfexp_numpy(tf.range(50.0, 130, 10_000), alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true)
/ 71.18838,
rtol=1e-8,
atol=1e-8,
)


def test_erfexp_pdf_random_params():
Expand All @@ -56,7 +63,7 @@ def test_erfexp_pdf_random_params():

erfexp, __ = create_erfexp(alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true, limits=(50, 130))
np.testing.assert_allclose(
erfexp.pdf(tf.range(50.0, 130, 10_000)),
erfexp.pdf(tf.range(50.0, 130, 10_000), norm=False),
erfexp_numpy(tf.range(50.0, 130, 10_000), alpha=alpha_true, beta=beta_true, gamma=gamma_true, n=n_true),
rtol=1e-5,
)
Expand Down

0 comments on commit 0bf4ec7

Please sign in to comment.