/
test_geant3id.py
44 lines (29 loc) · 1.07 KB
/
test_geant3id.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2020, Eduardo Rodrigues and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/particle for details.
import pytest
from particle.geant import Geant3ID
from particle.pdgid import PDGID
from particle.exceptions import MatchingIDNotFound
def test_class_string_representations():
pid = Geant3ID(1)
assert pid == 1
assert pid.__str__() == "<Geant3ID: 1>"
def test_class_return_type():
assert isinstance(-Geant3ID(3), Geant3ID)
assert isinstance(~Geant3ID(3), Geant3ID)
def test_class_inversion():
assert -Geant3ID(1) == ~Geant3ID(1)
def test_from_pdgid():
assert Geant3ID.from_pdgid(211) == 8
assert Geant3ID.from_pdgid(PDGID(211)) == 8
assert Geant3ID.from_pdgid(PDGID(211)) == Geant3ID(8)
def test_from_pdgid_non_matching():
with pytest.raises(MatchingIDNotFound):
gid = Geant3ID.from_pdgid(55)
def test_to_pdgid():
gid = Geant3ID(8)
assert gid.to_pdgid() == 211
assert gid.to_pdgid() == PDGID(211)