Ejemplo n.º 1
0
def test_inertial_length():
    r"""Test the inertial_length function in parameters.py."""

    assert inertial_length(n_i, particle='p').unit.is_equivalent(u.m)

    assert np.isclose(inertial_length(mu * u.cm**-3, particle='p').cgs.value,
                      2.28e7,
                      rtol=0.01)

    inertial_length_electron_plus = inertial_length(5.351 * u.m**-3,
                                                    particle='e+')
    assert inertial_length_electron_plus == inertial_length(5.351 * u.m**-3,
                                                            particle='e')

    assert inertial_length(n_i, particle='p') == inertial_length(n_i,
                                                                 particle='p')

    with pytest.warns(u.UnitsWarning):
        inertial_length(4, particle='p')

    with pytest.raises(u.UnitConversionError):
        inertial_length(4 * u.m**-2, particle='p')

    with pytest.raises(ValueError):
        inertial_length(-5 * u.m**-3, particle='p')

    with pytest.raises(ValueError):
        inertial_length(n_i, particle=-135)

    with pytest.warns(u.UnitsWarning):
        inertial_length_no_units = inertial_length(1e19, particle='p')
        assert inertial_length_no_units == inertial_length(1e19 * u.m**-3,
                                                           particle='p')

    assert inertial_length(n_e).unit.is_equivalent(u.m)

    assert np.isclose(inertial_length(1 * u.cm**-3).cgs.value,
                      5.31e5,
                      rtol=1e-3)

    with pytest.warns(u.UnitsWarning):
        inertial_length(5)

    with pytest.raises(u.UnitConversionError):
        inertial_length(5 * u.m)

    with pytest.raises(ValueError):
        inertial_length(-5 * u.m**-3)

    with pytest.warns(u.UnitsWarning):
        assert inertial_length(1e19) == inertial_length(1e19 * u.m**-3)

    assert_can_handle_nparray(inertial_length)
Ejemplo n.º 2
0
 def time_inertial_length(self):
     inertial_length(5 * u.m ** -3,
                     'He+')