Пример #1
0
def test_cgs_equivalent():
    """
    Check cgs equivalent of a unit.

    """
    Msun_cgs = mass_sun_grams
    Mpc_cgs = cm_per_mpc

    u1 = Unit("Msun * Mpc**-3")
    u2 = Unit("g * cm**-3")
    u3 = u1.get_cgs_equivalent()

    yield assert_true, u2.expr == u3.expr
    yield assert_true, u2 == u3

    yield assert_allclose, u1.cgs_value, Msun_cgs / Mpc_cgs**3, 1e-12
    yield assert_true, u2.cgs_value == 1
    yield assert_true, u3.cgs_value == 1

    mass_density = mass / length**3

    yield assert_true, u1.dimensions == mass_density
    yield assert_true, u2.dimensions == mass_density
    yield assert_true, u3.dimensions == mass_density

    yield assert_allclose, get_conversion_factor(u1, u3)[0], \
        Msun_cgs / Mpc_cgs**3, 1e-12
Пример #2
0
def test_base_equivalent():
    """
    Check base equivalent of a unit.

    """
    Msun_cgs = mass_sun_grams
    Mpc_cgs = cm_per_mpc

    u1 = Unit("Msun * Mpc**-3")
    u2 = Unit("g * cm**-3")
    u3 = u1.get_base_equivalent()

    assert_true(u2.expr == u3.expr)
    assert_true(u2 == u3)

    assert_allclose_units(u1.base_value, Msun_cgs / Mpc_cgs**3, 1e-12)
    assert_true(u2.base_value == 1)
    assert_true(u3.base_value == 1)

    mass_density = mass / length**3

    assert_true(u1.dimensions == mass_density)
    assert_true(u2.dimensions == mass_density)
    assert_true(u3.dimensions == mass_density)

    assert_allclose_units(
        get_conversion_factor(u1, u3)[0], Msun_cgs / Mpc_cgs**3, 1e-12)
def test_base_equivalent():
    """
    Check base equivalent of a unit.

    """
    Msun_cgs = mass_sun_grams
    Mpc_cgs = cm_per_mpc

    u1 = Unit("Msun * Mpc**-3")
    u2 = Unit("g * cm**-3")
    u3 = u1.get_base_equivalent()

    yield assert_true, u2.expr == u3.expr
    yield assert_true, u2 == u3

    yield assert_allclose_units, u1.base_value, Msun_cgs / Mpc_cgs**3, 1e-12
    yield assert_true, u2.base_value == 1
    yield assert_true, u3.base_value == 1

    mass_density = mass / length**3

    yield assert_true, u1.dimensions == mass_density
    yield assert_true, u2.dimensions == mass_density
    yield assert_true, u3.dimensions == mass_density

    yield assert_allclose_units, get_conversion_factor(u1, u3)[0], \
        Msun_cgs / Mpc_cgs**3, 1e-12