Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1 unit day added #33

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/oxrse_unit_conv/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_conversion_core.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
13 changes: 13 additions & 0 deletions src/tests/test_unit_d.py
Original file line number Diff line number Diff line change
@@ -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()