# Licensed under a 3-clause BSD style license - see LICENSE.rst


from .. import Constant, si, cgs


def test_c():
    #c is an exactly defined constant, so it shouldn't be changing
    assert si.c == 2.99792458e8
    assert cgs.c == 2.99792458e10

    #check that the float-translation stuff works as expected
    assert si.c.real == si.c * 1
    assert cgs.c.real == cgs.c - 0

    #make sure it has the necessary attributes and they're not blank
    assert si.c.error == 0  # c is a *defined* quantity
    assert si.c.name
    assert si.c.origin
    assert si.c.units
    assert cgs.c.error == 0  # c is a *defined* quantity
    assert cgs.c.name
    assert cgs.c.origin
    assert cgs.c.units


def test_h():
    #check that the value is fairly close to what it should be (not exactly
    #checking because this might get updated in the future)
    assert abs(si.h - 6.626e-34) < 1e-38
    assert abs(cgs.h - 6.626e-27) < 1e-31

    #make sure it has the necessary attributes and they're not blank
    assert si.h.error
    assert si.h.name
    assert si.h.origin
    assert si.h.units
    assert cgs.h.error
    assert cgs.h.name
    assert cgs.h.origin
    assert cgs.h.units


def test_units():
    for key, val in si.__dict__.items() + cgs.__dict__.items():
        if isinstance(val, Constant):
            # Getting the unit forces the unit parser to run and we
            # can catch any syntax errors in the unit this way.
            val.units

# Licensed under a 3-clause BSD style license - see LICENSE.rst


from .. import Constant, si, cgs


def test_c():
    #c is an exactly defined constant, so it shouldn't be changing
    assert si.c == 2.99792458e8
    assert cgs.c == 2.99792458e10

    #check that the float-translation stuff works as expected
    assert si.c.real == si.c * 1
    assert cgs.c.real == cgs.c - 0

    #make sure it has the necessary attributes and they're not blank
    assert si.c.error == 0  # c is a *defined* quantity
    assert si.c.name
    assert si.c.origin
    assert si.c.units
    assert cgs.c.error == 0  # c is a *defined* quantity
    assert cgs.c.name
    assert cgs.c.origin
    assert cgs.c.units


def test_h():
    #check that the value is fairly close to what it should be (not exactly
    #checking because this might get updated in the future)
    assert abs(si.h - 6.626e-34) < 1e-38
    assert abs(cgs.h - 6.626e-27) < 1e-31

    #make sure it has the necessary attributes and they're not blank
    assert si.h.error
    assert si.h.name
    assert si.h.origin
    assert si.h.units
    assert cgs.h.error
    assert cgs.h.name
    assert cgs.h.origin
    assert cgs.h.units


def test_units():
    from ... import units as u

    for key, val in si.__dict__.items() + cgs.__dict__.items():
        if isinstance(val, Constant):
            # Getting the unit forces the unit parser to run.  Confirm
            # that none of the constants defined in astropy have
            # invalid units.
            assert not isinstance(val.units, u.UnrecognizedUnit)

Check that all of the constants defined in astropy have valid units.