From 02361341f0e50b9951ce4d5d3a9972634e985c61 Mon Sep 17 00:00:00 2001 From: Maximilian Linhoff Date: Fri, 6 Sep 2024 13:57:41 +0200 Subject: [PATCH] Add more tests for Particle.__hash__ --- tests/particle/test_particle.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/particle/test_particle.py b/tests/particle/test_particle.py index 316a7c59..97ea7c0a 100644 --- a/tests/particle/test_particle.py +++ b/tests/particle/test_particle.py @@ -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