From 622494a2f6c7ed93e382362f9acb2c25f48e8a10 Mon Sep 17 00:00:00 2001 From: Vladyslav Date: Wed, 21 Aug 2024 20:07:03 +0300 Subject: [PATCH] feat(dri-1308): add unitless unit --- src/corva_unit_converter/converter.py | 3 +- .../definitions/__init__.py | 4 ++- .../definitions/unitless.py | 30 +++++++++++++++++++ src/version.py | 2 +- tests/test_converter.py | 11 +++---- tests/test_unitless.py | 11 +++++++ 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 src/corva_unit_converter/definitions/unitless.py create mode 100644 tests/test_unitless.py diff --git a/src/corva_unit_converter/converter.py b/src/corva_unit_converter/converter.py index f406a7c..153498b 100644 --- a/src/corva_unit_converter/converter.py +++ b/src/corva_unit_converter/converter.py @@ -35,7 +35,8 @@ "volume_concentration": definitions.volume_concentration.rule, "volume_flow_rate": definitions.volume_flow_rate.rule, "voltage": definitions.voltage.rule, - "viscosity": definitions.viscosity.rule + "viscosity": definitions.viscosity.rule, + "unitless": definitions.unitless.rule, } diff --git a/src/corva_unit_converter/definitions/__init__.py b/src/corva_unit_converter/definitions/__init__.py index 2deebec..7c58ca1 100644 --- a/src/corva_unit_converter/definitions/__init__.py +++ b/src/corva_unit_converter/definitions/__init__.py @@ -35,6 +35,7 @@ voltage, volume_concentration, volume_flow_rate, + unitless ) __all__ = [ @@ -73,5 +74,6 @@ "voltage", "volume_concentration", "volume_flow_rate", - "viscosity" + "viscosity", + "unitless" ] diff --git a/src/corva_unit_converter/definitions/unitless.py b/src/corva_unit_converter/definitions/unitless.py new file mode 100644 index 0000000..68aa25c --- /dev/null +++ b/src/corva_unit_converter/definitions/unitless.py @@ -0,0 +1,30 @@ +metric = imperial = { + "unitless": { + "name": { + "singular": "unitless", + "plural": "unitless", + "display": "unitless" + }, + "to_anchor": 1, + "aliases": [ + "On/Off", + "None", + "EUC" + ] + }, +} + +rule = { + "metric": metric, + "imperial": imperial, + "_anchors": { + "metric": { + "unit": "unitless", + "ratio": 1 + }, + "imperial": { + "unit": "unitless", + "ratio": 1 + } + } +} diff --git a/src/version.py b/src/version.py index c91a341..5a2867d 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -VERSION = "0.5.0" +VERSION = "0.6.0" diff --git a/tests/test_converter.py b/tests/test_converter.py index 96554ea..de7f3db 100644 --- a/tests/test_converter.py +++ b/tests/test_converter.py @@ -11,11 +11,12 @@ def test_get_measures_returns_correct_keys(): expected_keys = [ "acoustic_slowness", "angle", "angle_per_length", "angular_velocity", "area", "density", "energy", "force", "gas_concentration", - "gas_volume", "gamma_radiation", "inverse_pressure", "length", "length_per_angle", - "mass", "mass_flow_rate", "mpl", "porosity", "power", "pressure", - "pressure_gradient", "proportion", "revolution_per_volume", "speed", - "strokes_rate", "temperature", "time", "torque", - "volume_concentration", "volume_flow_rate", "viscosity", "voltage" + "gas_volume", "gamma_radiation", "inverse_pressure", "length", + "length_per_angle", "mass", "mass_flow_rate", "mpl", "porosity", + "power", "pressure", "pressure_gradient", "proportion", + "revolution_per_volume", "speed", "strokes_rate", "temperature", + "time", "torque", "volume_concentration", "volume_flow_rate", + "viscosity", "voltage", "unitless" ] assert sorted(result) == sorted(expected_keys) diff --git a/tests/test_unitless.py b/tests/test_unitless.py new file mode 100644 index 0000000..36664af --- /dev/null +++ b/tests/test_unitless.py @@ -0,0 +1,11 @@ +from .utils import convert_units + +# test cases +cases = [ + {"from": "unitless", "amount": 1, "to": "unitless", "expected": 1, + "measure": 'unitless'} +] + + +def test(): + convert_units(cases)