def test_decay_normalize(radioisotope): """Test decay_normalize()""" now = datetime.datetime.now() interval1 = (now, now + datetime.timedelta(hours=1)) assert np.isclose(decay_normalize(radioisotope, interval1, interval1), 1) # avoid numerical issues with large half-lives (#65) # and underflow with small half-lives # note: 2^(-(1 day) / (85 seconds)) ~ sys.float_info.min if 90 < radioisotope.half_life < 1000 * 3.156e7: interval2 = (now + datetime.timedelta(days=1), now + datetime.timedelta(days=1, hours=1)) assert decay_normalize(radioisotope, interval1, interval2) > 1 assert decay_normalize(radioisotope, interval2, interval1) < 1
def test_decay_normalize_errors(radioisotope): """Test errors in decay_normalize()""" now = datetime.datetime.now() interval1 = (now, now + datetime.timedelta(hours=1)) interval2 = (now + datetime.timedelta(days=1), now + datetime.timedelta(days=1, hours=1)) with pytest.raises(IsotopeQuantityError): decay_normalize(radioisotope, [now], interval2) with pytest.raises(IsotopeQuantityError): decay_normalize(radioisotope, interval1, [now, now, now]) with pytest.raises(ValueError): decay_normalize(radioisotope, (interval1[1], interval1[0]), interval2) with pytest.raises(ValueError): decay_normalize(radioisotope, interval1, (interval2[1], interval2[0]))