Skip to content

Commit

Permalink
Add more tests for Particle.__hash__
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Sep 6, 2024
1 parent f7fd799 commit 0236134
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,25 @@ def test_from_name_non_unique_pdgids(name, pdgid):
p = Particle.from_name(name)
assert p.name == name
assert p.pdgid == pdgid


@pytest.mark.parametrize("sign", [1, -1])
def test_particle_hash(sign):
proton1 = Particle.from_pdgid(sign * 2212)
proton2 = Particle.from_pdgid(sign * 1000010010)
neutron1 = Particle.from_pdgid(sign * 2112)
neutron2 = Particle.from_pdgid(sign * 1000000010)

s1 = {proton1, neutron1}

assert proton1 in s1
assert proton2 in s1
assert neutron1 in s1
assert neutron2 in s1

assert len({proton1, proton2}) == 1
assert len({neutron1, neutron2}) == 1

d = {proton1: 5, neutron2: 3}
assert d[proton2] == 5
assert d[neutron1] == 3

0 comments on commit 0236134

Please sign in to comment.