def test_get_in_cgs():
    """
    Get cosmological density quantity in cgs.

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

    q1 = Quantity(1.47721e11, u1)
    q2 = q1.get_in_cgs()

    assert equal_sigfigs(q2.data, 1e-29, required_precision)
    assert q2.units == u2
def test_convert_bad_dimensions():
    """
    Get Exception from converting to wrong dimensionality.

    """
    u1 = Unit("Msun * Mpc**-2")
    q1 = Quantity(1e-29, "g * cm**-3")

    try:
        q1.convert_to(u1)
    except Exception:
        pass
    else:
        assert False
def test_convert_to_cgs():
    """
    Convert a cosmological density quantity to cgs.

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

    q1 = Quantity(1.47721e11, "Msun * Mpc**-3")

    assert q1.units == u1

    q1.convert_to_cgs()

    assert equal_sigfigs(q1.data, 1e-29, required_precision)
    assert q1.units == u2
def test_convert_to():
    """
    Convert a density quantity from cgs to cosmological units.

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

    q1 = Quantity(1e-29, u1)

    assert q1.units == u1

    q1.convert_to(u2)

    assert equal_sigfigs(q1.data, 1.47721e11, required_precision)
    assert q1.units == u2