class TestNoisedValueDivisionWithOtherPositiveNoisedValue( TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) / NoisedValue(val=1.12, var=0.2) expected_val = 1.339285 expected_var = 0.68458 expected_err = 0.82739 expected_relative_err = 0.617787
class TestNoisedValueMultiplicationWithOtherNegativeNoisedValue( TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) * NoisedValue(val=-2.3, var=2.75) expected_val = -3.45 expected_var = 8.8325 expected_err = 2.97195 expected_relative_err = 0.861435
class TestNoisedValueLeftDivisionWithNegativeConstant(TestCase, NoisedValueBaseTestCase): v = -1.12 / NoisedValue(val=1.5, var=0.5) expected_val = -0.746666 expected_var = 0.12389 expected_err = 0.35198 expected_relative_err = 0.4714
class TestNoisedValueInitializationWithoutVarianceOrError( TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5) expected_val = 1.5 expected_var = 0 expected_err = 0 expected_relative_err = 0
def test_representation_of_zero_error(self): v = NoisedValue(val=1.5) self.assertEqual( "1.5 \u00B1 0 (0.000% error)", str(v), msg="NoisedValue representation is different than expected", )
class TestNoisedValueInitializationWithError(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, err=0.5) expected_val = 1.5 expected_var = 0.25 expected_err = 0.5 expected_relative_err = 0.33333
def test_representation_of_non_zero(self): v = NoisedValue(val=1.5, err=0.5) self.assertEqual( "1.5 \u00B1 0.5 (33.333% error)", str(v), msg="NoisedValue representation is different than expected", )
class TestNoisedValueRightMultiplicationWithPositiveConstant( TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) * 1.12 expected_val = 1.68 expected_var = 0.6272 expected_err = 0.79196 expected_relative_err = 0.4714
class TestNoisedValueInitializationWithValueZero(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=0, err=0.5) expected_val = 0 expected_var = 0.25 expected_err = 0.5 expected_relative_err = None
class TestNoisedValueLeftMultiplicationWithNegativeConstant( TestCase, NoisedValueBaseTestCase): v = -1.12 * NoisedValue(val=1.5, var=0.5) expected_val = -1.68 expected_var = 0.6272 expected_err = 0.79196 expected_relative_err = 0.4714
def test_representation_of_zero_value(self): v = NoisedValue(val=0, err=0.5) self.assertEqual( "0 \u00B1 0.5 (\u221E% error)", str(v), msg="NoisedValue representation is different than expected", )
class TestNoisedValueRightDivisionWithPositiveConstant(TestCase, NoisedValueBaseTestCase ): v = NoisedValue(val=1.5, var=0.5) / 1.12 expected_val = 1.339285 expected_var = 0.3986 expected_err = 0.631345 expected_relative_err = 0.4714
class TestNoisedValueLeftConstantSubtraction(TestCase, NoisedValueBaseTestCase): v = 2.2 - NoisedValue(val=1.5, var=0.5) expected_val = 0.7 expected_var = 0.5 expected_err = 0.70711 expected_relative_err = 1.010157
class TestNoisedValueExponential(TestCase, NoisedValueBaseTestCase): v = np.exp(NoisedValue(val=1.5, err=0.5)) expected_val = 4.48169 expected_var = 5.02138 expected_err = 2.24084 expected_relative_err = 0.5
class TestNoisedValueInteger3Power(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, err=0.5) ** 3 expected_val = 3.375 expected_var = 11.390625 expected_err = 3.375 expected_relative_err = 1
class TestNoisedValueSin(TestCase, NoisedValueBaseTestCase): v = np.sin(NoisedValue(val=np.pi / 6, err=0.5)) expected_val = 0.5 expected_var = 0.1875 expected_err = 0.433013 expected_relative_err = 0.866025
class TestNoisedValueCos(TestCase, NoisedValueBaseTestCase): v = np.cos(NoisedValue(val=np.pi / 6, err=0.5)) expected_val = 0.866025 expected_var = 0.0625 expected_err = 0.25 expected_relative_err = 0.288675
class TestNoisedValueSubtractionWithOtherNoisedValue(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) - NoisedValue(val=2.2, var=2.75) expected_val = -0.7 expected_var = 3.25 expected_err = 1.802775 expected_relative_err = 2.57539
class TestNoisedValueRightConstantSubtraction(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) - 2.2 expected_val = -0.7 expected_var = 0.5 expected_err = 0.70711 expected_relative_err = 1.010157
class TestNoisedValueInteger2Power(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, err=0.5) ** 2 expected_val = 2.25 expected_var = 2.25 expected_err = 1.5 expected_relative_err = 0.666666
class TestNoisedValueIntegerNegativePower(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, err=0.5) ** -1 expected_val = 0.666666 expected_var = 0.049382 expected_err = 0.222222 expected_relative_err = 0.333333
class TestNoisedValueInteger1Power(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, err=0.5) ** 1 expected_val = 1.5 expected_var = 0.25 expected_err = 0.5 expected_relative_err = 0.33333
class TestNoisedValueAdditionWithOtherNoisedValue(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) + NoisedValue(val=2.2, var=2.75) expected_val = 3.7 expected_var = 3.25 expected_err = 1.802775 expected_relative_err = 0.487236
class TestNoisedValueRightConstantAddition(TestCase, NoisedValueBaseTestCase): v = NoisedValue(val=1.5, var=0.5) + 2.2 expected_val = 3.7 expected_var = 0.5 expected_err = 0.70711 expected_relative_err = 0.19111
class TestNoisedValueNegativeValue(TestCase, NoisedValueBaseTestCase): v = -NoisedValue(val=1.5, var=0.5) expected_val = -1.5 expected_var = 0.5 expected_err = 0.70711 expected_relative_err = 0.4714
from noised_value import NoisedValue rho_b = NoisedValue(val=7.812, err=0.055) rho_l = NoisedValue(val=1.26, err=5.7e-4) g = NoisedValue(val=981, err=10) L = NoisedValue(val=22.22, err=2.8e-3) a = NoisedValue(val=0.1964, err=0.0091) eta = (2 * g * a * (rho_b - rho_l)) / (9 * L) expected_eta = NoisedValue(val=12.5, err=1.44) print(f"experiment eta is: {eta}") print(f"expected eta is: {expected_eta}") print(f"n sigma is: {expected_eta.n_sigma(eta)}") print(NoisedValue(val=0, err=1))