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_fuzzy_name_search():
particles = Particle.findall("p~")
assert len(particles) == 2
assert -2212 in particles
assert -1000010010 in particles
def test_keyword_lambda_style_search():
particles = Particle.findall(pdg_name=lambda x: "p" == x)
assert len(particles) == 4
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
# Fuzzy name
particles = Particle.findall(name=lambda x: "p" in x)
assert len(particles) > 2
assert 2212 in particles
assert -2212 in particles
# Name and particle
assert len(Particle.findall(name=lambda x: x == "p", particle=True)) == 2
# Unit based comparison
assert 2212 in Particle.findall(lifetime=lambda x: x > 1 * second)
def test_complex_search():
# Find all strange mesons with c*tau > 1 meter
particles = Particle.findall(
lambda p: p.pdgid.is_meson
and p.pdgid.has_strange
and p.width > 0
and p.ctau > 1000.0,
particle=True,
)
assert len(particles) == 2 # K+ and KL0
assert 130 in particles
assert 321 in particles
# Find all strange anti-mesons with c*tau > 1 meter
particles = Particle.findall(
lambda p: p.pdgid.is_meson
and p.pdgid.has_strange
and p.width > 0
and p.ctau > 1000.0,
def test_lambda_style_search():
particles = Particle.findall(lambda p: p.pdg_name == "p")
assert len(particles) == 4
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
[p.pdgid for p in Particle.findall(lambda p: p.pdg_name == "p" and p > 0)] == [
2212,
1000010010,
]
[p.pdgid for p in Particle.findall(lambda p: p.pdg_name == "p" and p < 0)] == [
-2212,
-1000010010,
]
particles = Particle.findall(name="p")
assert len(particles) == 2
assert 2212 in particles
assert 1000010010 in particles
[p.pdgid for p in Particle.findall(pdg_name="p", particle=True)] == [
2212,
1000010010,
]
[p.pdgid for p in Particle.findall(pdg_name="p", particle=False)] == [
-2212,
-1000010010,
]
[p.pdgid for p in Particle.findall(name="p", particle=True)] == [2212, 1000010010]
[p.pdgid for p in Particle.findall(name="p~", particle=False)] == [
-2212,
-1000010010,
]
def test_keyword_lambda_style_search():
particles = Particle.findall(pdg_name=lambda x: "p" == x)
assert len(particles) == 4
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
# Fuzzy name
particles = Particle.findall(name=lambda x: "p" in x)
assert len(particles) > 2
assert 2212 in particles
assert -2212 in particles
# Name and particle
assert len(Particle.findall(name=lambda x: x == "p", particle=True)) == 2
# Unit based comparison
def test_keyword_style_search():
particles = Particle.findall(pdg_name="p")
assert len(particles) == 4
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
def test_lambda_style_search():
particles = Particle.findall(lambda p: p.pdg_name == "p")
assert len(particles) == 4
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
[p.pdgid for p in Particle.findall(lambda p: p.pdg_name == "p" and p > 0)] == [
2212,
1000010010,
]
[p.pdgid for p in Particle.findall(lambda p: p.pdg_name == "p" and p < 0)] == [
-2212,
-1000010010,
]
assert 2212 in particles
assert -2212 in particles
assert 1000010010 in particles
assert -1000010010 in particles
# Fuzzy name
particles = Particle.findall(name=lambda x: "p" in x)
assert len(particles) > 2
assert 2212 in particles
assert -2212 in particles
# Name and particle
assert len(Particle.findall(name=lambda x: x == "p", particle=True)) == 2
# Unit based comparison
assert 2212 in Particle.findall(lifetime=lambda x: x > 1 * second)