Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Jul 31, 2024
1 parent 94e1367 commit dadd6be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions tests/test_minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dadd6be

Please sign in to comment.