This commit is contained in:
Fabian Joswig 2025-04-28 19:44:55 +00:00 committed by GitHub
commit 32b3afc7bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 96 additions and 2 deletions

View file

@ -427,3 +427,14 @@ def assert_equal_Obs(to, ro):
print(kw, "does not match.")
return False
return True
def test_meas_uuid(tmp_path):
meas = pe.Meas(0.3, 0.2)
for obs in [meas, meas + 1, meas * pe.pseudo_Obs(0.1, 0.001, "obs|r1")]:
with pytest.raises(ValueError):
jsonio.dump_to_json([obs], "test_file", indent=1, description='[This file should not be writable]')
name_meas = pe.Meas(0.3, 0.2, name="my name")
jsonio.dump_to_json([name_meas], "test_file", indent=1, description='[This file should be writable]')

View file

@ -1486,3 +1486,37 @@ def test_missing_replica():
for op in [[O1O2, O1O2b], [O1O2O3, O1O2O3b]]:
assert np.isclose(op[1].value, op[0].value)
assert np.isclose(op[1].dvalue, op[0].dvalue, atol=0, rtol=5e-2)
def test_meas():
meas1 = pe.Meas(1.0, 0.1)
meas2 = pe.Meas(2, 1)
assert meas1 + meas2 == meas2 + meas1
assert meas1 - meas2 == -(meas2 - meas1)
assert meas1 * meas2 == meas2 * meas1
identical_sum = meas1 + meas1
assert identical_sum == 2 * meas1
assert np.isclose(identical_sum.dvalue, 2 * meas1.dvalue)
meas1_new = pe.Meas(1.0, 0.1)
not_identical_sum = meas1 + meas1_new
assert not_identical_sum.value == (2 * meas1).value
assert not_identical_sum != 2 * meas1
assert np.isclose(not_identical_sum.dvalue, np.sqrt(meas1.dvalue ** 2 + meas1_new.dvalue ** 2))
assert meas2 * meas2 == meas2 ** 2
def test_square_cov_obs():
cov = pe.cov_Obs(1, 0.1 ** 2, "testing")
cov2 = cov ** 2
def test_covobs_equal_meas():
value = 1.1
standard_error = 0.23
meas = pe.Meas(value, standard_error)
covo = pe.cov_Obs(value, standard_error ** 2, meas.names[0])
assert covo == meas