Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
giacomomagni committed Nov 7, 2024
1 parent ad596f4 commit 15f4a78
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/yadism/coefficient_functions/coupling_constants.py
Original file line number Diff line number Diff line change
@@ -416,7 +416,7 @@ def from_dict(cls, theory, observables):
if isinstance(ckm_matrix, str):
ckm_matrix = CKM2Matrix.from_str(ckm_matrix)
elif isinstance(ckm_matrix, list):
ckm_matrix = CKM2Matrix(np.array([ckm_matrix]) ** 2)
ckm_matrix = CKM2Matrix(np.array(ckm_matrix) ** 2)
theory_config = {
"MZ2": theory.get("MZ", 91.1876)
** 2, # TODO remove defaults to the PDG2020 value
@@ -479,6 +479,12 @@ def __repr__(self):
"""Return string representation."""
return "CKM(" + str(self.m).replace("\n", "") + ")"

def __eq__(self, other) -> bool:
eq = True
for a, b in zip(self.__dict__, other.__dict__):
eq = a == b
return eq

def __getitem__(self, key):
"""Allow pid and strings as key.
18 changes: 18 additions & 0 deletions tests/yadism/cf/test_coupling_constants.py
Original file line number Diff line number Diff line change
@@ -132,6 +132,24 @@ def test_from_dict(self):
coupl_const = coupl.CouplingConstants.from_dict(th_d, obs_d)
assert coupl_const.theory_config["MW2"] == MW**2

new_th_ckm = dict(
SIN2TW=sin2tw,
MZ=MZ,
CKM=[
0.97428,
0.22530,
0.003470,
0.22520,
0.97345,
0.041000,
0.00862,
0.04030,
0.999152,
],
)
new_coupl_const = coupl.CouplingConstants.from_dict(new_th_ckm, obs_d)
assert coupl_const.theory_config["CKM"] == new_coupl_const.theory_config["CKM"]

# Unknown projectile
obs_d["ProjectileDIS"] = 0
with pytest.raises(ValueError, match="Unknown projectile"):

0 comments on commit 15f4a78

Please sign in to comment.