From dadd6beb9841083178a0859235870a8cf659b815 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Wed, 31 Jul 2024 17:26:05 +0200 Subject: [PATCH] more coverage --- tests/test_cost.py | 12 ++++++++++++ tests/test_minuit.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tests/test_cost.py b/tests/test_cost.py index c3ba6355..78233e3a 100644 --- a/tests/test_cost.py +++ b/tests/test_cost.py @@ -621,6 +621,18 @@ def test_BinnedNLL_bad_input_6(): BinnedNLL([[1]], [[1, 2], [3, 4]], lambda x, a: 0, use_pdf="numerical") +def test_BinnedNLL_bad_input_7(): + with pytest.raises(ValueError, match="xe must be iterable"): + BinnedNLL([0, 1], 0, lambda x, a: 0) + + +def test_BinnedNLL_bad_input_8(): + with pytest.raises(ValueError, match="use_pdf and grad cannot be used together"): + BinnedNLL( + [0, 1], [1, 2, 3], lambda x, a: 0, grad=lambda x, a: [1], use_pdf="numeric" + ) + + def test_BinnedNLL_ndof_zero(): c = BinnedNLL([1], [0, 1], lambda x, scale: expon_cdf(x, scale)) m = Minuit(c, scale=1) diff --git a/tests/test_minuit.py b/tests/test_minuit.py index 799eba51..34453cda 100644 --- a/tests/test_minuit.py +++ b/tests/test_minuit.py @@ -1727,3 +1727,32 @@ def cost(a, b): # check that cost.errordef value is still overridden m.hesse() assert_allclose(m.errors, [2, 2]) + + +def test_mnprofile_bad_cost(): + def fn(a, b): + if b > 0: + return a**2 + return (a - 0.1) ** 2 + + m = Minuit(fn, 1, 2) + # test iterative fitting with custom precision + # m.precision = 1e-18 + m.migrad() + with pytest.warns(IMinuitWarning, match="MIGRAD fails to converge"): + m.mnprofile("a") + + +def test_migrad_iterative_with_precision(): + def fn(a, b): + return 0 + + m1 = Minuit(fn, 1, 2) + m1.precision = 1e-7 + m1.migrad(iterate=5) + + m2 = Minuit(fn, 1, 2) + m2.precision = 1e-7 + m2.migrad(iterate=1) + + assert m2.fmin.nfcn < m1.fmin.nfcn