diff --git a/bia/test_units.py b/bia/test_units.py index e54743e..be83207 100644 --- a/bia/test_units.py +++ b/bia/test_units.py @@ -24,6 +24,19 @@ def test_basic_conversions(): assert g.as_unit('lb').scalar == a.as_unit('lb').scalar +def test_complex_conversions(): + a = V(2, ['m', 'm']) + cm2 = a.as_unit(['cm', 'cm']) + assert cm2.scalar == 20000 + assert cm2.unit == Unit(['cm', 'cm']) + + g = V(9.8, Unit(['m'], ['s', 's'])) + g_ft = g.as_unit(Unit(['ft'], ['s', 's'])) + assert g_ft.scalar - 32 < 1 + assert g_ft.unit == Unit(['ft'], ['s', 's']) + + + def test_basic_cmp(): assert V(1, 'kg') < V(2, 'kg') assert V(1, 'kg') <= V(2, 'kg') diff --git a/bia/units.py b/bia/units.py index 1815a5b..d98d777 100644 --- a/bia/units.py +++ b/bia/units.py @@ -7,7 +7,11 @@ _UNITS = { 'lb': {'base': 'kg', 'scale': 2.20462}, 'g': {'base': 'kg', 'scale': 1000.0}, - 'm': {'base': 'm', 'scale': 1.0}, + 'm': {'base': 'm', 'scale': 1.0}, + 'cm': {'base': 'm', 'scale': 100.0}, + 'ft': {'base': 'm', 'scale': 3.28084}, + + 's': {'base': 's', 'scale': 1.0}, }