Skip to content

Commit

Permalink
seed test randomness and fix tests for julia versions <= 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonReinhard committed May 3, 2024
1 parent 534f443 commit 87006a8
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions test/phase_spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ include("test_implementation/TestImplementation.jl")
TESTMODEL = TestImplementation.TestModel()
TESTPSDEF = TestImplementation.TestPhasespaceDef()

RNG = Random.MersenneTwister(727)

@testset "Stateful Particle" begin
DIRECTIONS = [Incoming(), Outgoing()]
PARTICLES = [Electron(), Positron()] #=, Muon(), AntiMuon(), Tauon(), AntiTauon()=#
SPINANDPOLS = [AllSpin(), SpinUp(), SpinDown(), AllPol(), PolX(), PolY()]

for (particle, dir, spinorpol) in Iterators.product(PARTICLES, DIRECTIONS, SPINANDPOLS)
momentum = rand(SFourMomentum)
momentum = rand(RNG, SFourMomentum)

if (is_fermion(particle) && (spinorpol isa AbstractSpin)) ||
(is_boson(particle) && (spinorpol isa AbstractPolarization))
Expand All @@ -38,10 +40,10 @@ TESTPSDEF = TestImplementation.TestPhasespaceDef()
end

@testset "Phasespace Point" begin
in_el = ParticleStateful(rand(SFourMomentum), Electron(), AllSpin(), Incoming())
in_ph = ParticleStateful(rand(SFourMomentum), Photon(), AllPol(), Incoming())
out_el = ParticleStateful(rand(SFourMomentum), Electron(), AllSpin(), Outgoing())
out_ph = ParticleStateful(rand(SFourMomentum), Photon(), AllPol(), Outgoing())
in_el = ParticleStateful(rand(RNG, SFourMomentum), Electron(), AllSpin(), Incoming())
in_ph = ParticleStateful(rand(RNG, SFourMomentum), Photon(), AllPol(), Incoming())
out_el = ParticleStateful(rand(RNG, SFourMomentum), Electron(), AllSpin(), Outgoing())
out_ph = ParticleStateful(rand(RNG, SFourMomentum), Photon(), AllPol(), Outgoing())

in_particles_valid = SVector(in_el, in_ph)
in_particles_invalid = SVector(in_el, out_ph)
Expand All @@ -58,19 +60,38 @@ end

PhaseSpacePoint(process, model, phasespace_def, in_particles_valid, out_particles_valid)

@test_throws r"Stateful particle (.*) is given as an incoming particle but is outgoing" PhaseSpacePoint(
if (VERSION >= v"1.8")
# julia versions before 1.8 did not have support for regex matching in @test_throws
@test_throws r"Stateful particle (.*) is given as an incoming particle but is outgoing" PhaseSpacePoint(
process, model, phasespace_def, in_particles_invalid, out_particles_valid
)

@test_throws r"Stateful particle (.*) is given as an outgoing particle but is incoming" PhaseSpacePoint(
process, model, phasespace_def, in_particles_valid, out_particles_invalid
)

@test_throws r"Process given particle type \((.*)Electron\(\)\) does not match stateful particle type \((.*)Photon\(\)\)" PhaseSpacePoint(
process, model, phasespace_def, SVector(in_ph, in_el), out_particles_valid
)

@test_throws r"Process given particle type \((.*)Electron\(\)\) does not match stateful particle type \((.*)Photon\(\)\)" PhaseSpacePoint(
process, model, phasespace_def, in_particles_valid, SVector(out_ph, out_el)
)
end

@test_throws InvalidInputError PhaseSpacePoint(
process, model, phasespace_def, in_particles_invalid, out_particles_valid
)

@test_throws r"Stateful particle (.*) is given as an outgoing particle but is incoming" PhaseSpacePoint(
@test_throws InvalidInputError PhaseSpacePoint(
process, model, phasespace_def, in_particles_valid, out_particles_invalid
)

@test_throws r"Process given particle type \((.*)Electron\(\)\) does not match stateful particle type \((.*)Photon\(\)\)" PhaseSpacePoint(
@test_throws InvalidInputError PhaseSpacePoint(
process, model, phasespace_def, SVector(in_ph, in_el), out_particles_valid
)

@test_throws r"Process given particle type \((.*)Electron\(\)\) does not match stateful particle type \((.*)Photon\(\)\)" PhaseSpacePoint(
@test_throws InvalidInputError PhaseSpacePoint(
process, model, phasespace_def, in_particles_valid, SVector(out_ph, out_el)
)
end

0 comments on commit 87006a8

Please sign in to comment.