Skip to content

Commit

Permalink
test: add results API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjebaker committed Oct 1, 2023
1 parent a025ad7 commit 35d1d7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/fitting/test-results.jl
Original file line number Diff line number Diff line change
@@ -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])
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 35d1d7f

Please sign in to comment.