Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofia Calgaro committed Jan 10, 2025
1 parent 1f93adb commit 2501ced
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
10 changes: 10 additions & 0 deletions test/inputs/events_fake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"events": [
{
"experiment": "GERDA",
"energy": 35.6729,
"timestamp": 1453119048,
"detector": "ANG8"
}
]
}
16 changes: 8 additions & 8 deletions test/io/test_all.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Test

Test.@testset "io" begin
include("test_get_settings.jl")
include("test_get_partitions.jl")
#include("test_get_settings.jl")
#include("test_get_partitions.jl")
include("test_get_events.jl")
include("test_get_partition_event_index.jl")
include("test_get_partitions_events.jl")
include("test_get_corr_info.jl")
include("test_get_signal_prior_info.jl")
include("test_get_energy_scale_pars.jl")
include("test_get_efficiency.jl")
#include("test_get_partition_event_index.jl")
#include("test_get_partitions_events.jl")
#include("test_get_corr_info.jl")
#include("test_get_signal_prior_info.jl")
#include("test_get_energy_scale_pars.jl")
#include("test_get_efficiency.jl")
end
11 changes: 11 additions & 0 deletions test/io/test_get_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ using .ZeroNuFit
include("../../main.jl")
include("../../src/utils.jl")

Base.exit(code::Int) = throw(ArgumentError("exit code $code"))

@testset "test_get_events" begin

@info "Testing function to retrieve events given partitions (function 'get_events' in src/utils.jl)"
Expand Down Expand Up @@ -54,4 +56,13 @@ include("../../src/utils.jl")
@testset "Check events accuracy" begin
@test events == expected_events
end

# event with no partition
@test_throws ArgumentError ZeroNuFit.get_events(
joinpath(present_dir, "../inputs/events_fake.json"),
partitions,
)

# not-existing file
@test_throws ArgumentError ZeroNuFit.get_events("not_existing_file.json", partitions)
end
13 changes: 12 additions & 1 deletion test/io/test_get_partition_event_index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ include("../../src/utils.jl")
),
)

# 1 event case
partitions = nothing
part_event_index = nothing
fit_ranges = nothing
Expand All @@ -53,8 +54,18 @@ include("../../src/utils.jl")
end

expected_part_event_index = [1]
@testset "Check part_event_index accuracy" begin
@testset "Check part_event_index accuracy (1 event)" begin
@test part_event_index == expected_part_event_index
end

# no events case
events = Array{Vector{Float64}}(undef, length(partitions))
for (idx, part) in enumerate(partitions)
events[idx] = Vector{Float64}[]
end
part_event_index = ZeroNuFit.get_partition_event_index(events, partitions)
@testset "Check part_event_index accuracy (0 events)" begin
@test part_event_index == [0]
end

end

0 comments on commit 2501ced

Please sign in to comment.