From 35d1d7f19d4584bd5764baaf652f723719445fd3 Mon Sep 17 00:00:00 2001 From: fjebaker Date: Sun, 1 Oct 2023 18:36:43 +0100 Subject: [PATCH] test: add results API tests --- test/fitting/test-results.jl | 26 ++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 27 insertions(+) create mode 100644 test/fitting/test-results.jl diff --git a/test/fitting/test-results.jl b/test/fitting/test-results.jl new file mode 100644 index 00000000..ff0dcc1d --- /dev/null +++ b/test/fitting/test-results.jl @@ -0,0 +1,26 @@ +using Test, SpectralFitting + +include("../dummies.jl") + +dummy_data = make_dummy_dataset((E) -> (E^(-3.0)); units = u"counts / (s * keV)") +model = PowerLaw() +prob = FittingProblem(model, dummy_data) + +# test inference +@inferred SpectralFitting._unpack_fitting_configuration(prob); + +result = fit(prob, LevenbergMarquadt()) + +@test result[1].u ≈ [12.066, 3.0810] atol = 1e-3 + +@test measure(ChiSquared(), result) ≈ result.χ2 rtol = 1e-3 +@test measure(ChiSquared(), result, [11.0, 2.0]) ≈ 281423.5 rtol = 1e-3 +# can measure different parameters +@test measure(ChiSquared(), result[1], [11.0, 2.0]) ≈ 281423.5 rtol = 1e-3 + +# check these don't error +@test invoke_result(result) ≈ invoke_result(result[1]) +invoke_result(result, [11.0, 2.0]) + +# mismatch +@test_throws "" invoke_result(result, [11.0]) diff --git a/test/runtests.jl b/test/runtests.jl index 3c1f7495..ef1924db 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -95,6 +95,7 @@ end include("fitting/test-fit-simple-dataset.jl") include("fitting/test-cache.jl") include("fitting/test-binding.jl") + include("fitting/test-results.jl") @testset "powerlaws" begin include("fitting/test-fit-powerlaw.jl")