Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_C_consistency():
"""
The charge conjugation parity is stored in the (curated) data CSV files.
For unflavoured mesons it can be calculated as C = (-1)^(L+S),
and this relation can be checked against the CSV data.
Note: mesons with PDGIDs of the kind 9XXXXXX (N=9) are not experimentally
well-known particles and C is undefined.
"""
for p in Particle.all():
if not p.is_unflavoured_meson:
continue
elif _digit(p.pdgid, Location.N) == 9:
continue
elif p.pdgid == 22: # Special case of the photon
assert p.C == -1
elif p.pdgid in [130, 310]: # Special case of the KS and KL
assert p.C == Parity.u
else:
assert p.C == (-1) ** (p.L + p.S)
def test_P_consistency():
"""
The parity quantum number is stored in the (curated) data CSV files.
For unflavoured mesons it can be calculated as P = (-1)^(L+1),
and this relation can be checked against the CSV data.
Note: mesons with PDGIDs of the kind 9XXXXXX (N=9) are not experimentally
well-known particles and P is undefined.
"""
for p in Particle.all():
if not p.is_unflavoured_meson:
continue
elif _digit(p.pdgid, Location.N) == 9:
continue
elif p.pdgid == 22: # Special case of the photon
assert p.P == -1
else:
assert p.P == (-1) ** (p.L + 1)
def test_programmatic_name():
"""
Test makes sure that all literals defined in particle.shared_literals
match what is returned by Particle.programmatic_name.
"""
for literal_name, pid in common_particles.items():
if literal_name in ("photon", "proton", "antiproton", "neutron", "antineutron"):
continue
try: # some particles in the literals may not be in the table (e.g the neutrinos as of 2018)
p = Particle.from_pdgid(pid)
assert Particle.from_pdgid(pid).programmatic_name == literal_name
except ParticleNotFound:
pass
def test_programmatic_name():
"""
Test makes sure that all literals defined in particle.shared_literals
match what is returned by Particle.programmatic_name.
"""
for literal_name, pid in common_particles.items():
if literal_name in ("photon", "proton", "antiproton", "neutron", "antineutron"):
continue
try: # some particles in the literals may not be in the table (e.g the neutrinos as of 2018)
p = Particle.from_pdgid(pid)
assert Particle.from_pdgid(pid).programmatic_name == literal_name
except ParticleNotFound:
pass
def test_charge(PDGIDs):
assert charge(PDGIDs.Photon) == 0
assert charge(PDGIDs.Gluon) == 0
assert charge(PDGIDs.Electron) == -1
assert charge(PDGIDs.AntiMuon) == +1
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None
def test_charge(PDGIDs):
assert charge(PDGIDs.Photon) == 0
assert charge(PDGIDs.Gluon) == 0
assert charge(PDGIDs.Electron) == -1
assert charge(PDGIDs.AntiMuon) == +1
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None
def test_charge(PDGIDs):
assert charge(PDGIDs.Photon) == 0
assert charge(PDGIDs.Gluon) == 0
assert charge(PDGIDs.Electron) == -1
assert charge(PDGIDs.AntiMuon) == +1
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None
def test_charge(PDGIDs):
assert charge(PDGIDs.Photon) == 0
assert charge(PDGIDs.Gluon) == 0
assert charge(PDGIDs.Electron) == -1
assert charge(PDGIDs.AntiMuon) == +1
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None
def test_charge(PDGIDs):
assert charge(PDGIDs.Photon) == 0
assert charge(PDGIDs.Gluon) == 0
assert charge(PDGIDs.Electron) == -1
assert charge(PDGIDs.AntiMuon) == +1
assert charge(PDGIDs.jpsi) == 0
assert charge(PDGIDs.Upsilon_1S) == 0
assert charge(PDGIDs.PiPlus) == +1
assert charge(PDGIDs.KMinus) == -1
assert charge(PDGIDs.D0) == 0
assert charge(PDGIDs.DPlus) == +1
assert charge(PDGIDs.DsPlus) == +1
assert charge(PDGIDs.B0) == 0
assert charge(PDGIDs.Bs) == 0
assert charge(PDGIDs.BcPlus) == +1
assert charge(PDGIDs.Proton) == +1
assert charge(PDGIDs.LcPlus) == +1
assert charge(PDGIDs.Lb) == 0
assert charge(PDGIDs.DD1) == -2 / 3
assert charge(PDGIDs.SD0) == -2 / 3
assert charge(PDGIDs.Invalid1) == None
assert charge(PDGIDs.Invalid2) == None