diff --git a/.gitignore b/.gitignore index 4e7d8d8..7530e6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,19 @@ -venv/ - +# IDEs +.vscode/ .idea/ +# Intermediate Coverage file +.coverage + +# Output files +*.png + +# Python runtime +*.pyc +*.egg-info +.pytest_cache __pycache__/ + +# Virtual environments +venv/ +.venv/ diff --git a/README.md b/README.md index ad7043c..151f6ae 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Oxford RSE Unit Conversion +# Oxford RSE Unit Conversion - Kirsty McCready [![Unittest](https://github.com/OxfordRSE/oxrse_unit_conv/actions/workflows/unittest.yml/badge.svg)](https://github.com/OxfordRSE/oxrse_unit_conv/actions/workflows/unittest.yml) diff --git a/src/oxrse_unit_conv/units.py b/src/oxrse_unit_conv/units.py index ad09e02..3f2657f 100644 --- a/src/oxrse_unit_conv/units.py +++ b/src/oxrse_unit_conv/units.py @@ -8,6 +8,9 @@ hour = Unit(name='hour', abbr='h', si=second, to_si_fun=lambda n: n * 3600) h = hour +day = Unit(name='day', abbr='d', si=second, to_si_fun=lambda n: n * 86_400) +d = day + # meter kilometer = Unit(name='kilometer', abbr="km", si=meter, to_si_fun=lambda n: n * 1000) km = kilometer diff --git a/src/tests/test_conversion_core.py b/src/tests/test_conversion_core.py index 70acff2..178f5e8 100644 --- a/src/tests/test_conversion_core.py +++ b/src/tests/test_conversion_core.py @@ -1,6 +1,6 @@ import unittest from oxrse_unit_conv.meta import classes -from oxrse_unit_conv.units import kilometer, m, m2, m3, s, hour +from oxrse_unit_conv.units import kilometer, m, m2, m3, s, hour, day class TestConversionCore(unittest.TestCase): diff --git a/src/tests/test_unit_d.py b/src/tests/test_unit_d.py new file mode 100644 index 0000000..734fd41 --- /dev/null +++ b/src/tests/test_unit_d.py @@ -0,0 +1,13 @@ +import unittest +from oxrse_unit_conv.units import d, s + +class TestDay(unittest.TestCase): + def test_SI(self): + self.assertTrue(d.si_unit.matches(s)) + + def test_basic_conversion(self): + self.assertEqual(d.to_si(1), 86_400) + self.assertEqual(d.to_unit(10, d), 10) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file