Skip to content

Commit

Permalink
feat(dri-1028): add proportion and strokes_rate unit types
Browse files Browse the repository at this point in the history
  • Loading branch information
vkeyboardv committed May 28, 2024
1 parent 479859c commit 2132158
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/corva_unit_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"power": definitions.power.rule,
"pressure": definitions.pressure.rule,
"pressure_gradient": definitions.pressure_gradient.rule,
"proportion": definitions.proportion.rule,
"revolution_per_volume": definitions.revolution_per_volume.rule,
"speed": definitions.speed.rule,
"strokes_rate": definitions.strokes_rate.rule,
"temperature": definitions.temperature.rule,
"time": definitions.time.rule,
"torque": definitions.torque.rule,
Expand Down
4 changes: 4 additions & 0 deletions src/corva_unit_converter/definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
power,
pressure,
pressure_gradient,
proportion,
revolution_per_volume,
speed,
strokes_rate,
temperature,
time,
torque,
Expand Down Expand Up @@ -58,8 +60,10 @@
"power",
"pressure",
"pressure_gradient",
"proportion",
"revolution_per_volume",
"speed",
"strokes_rate",
"temperature",
"time",
"torque",
Expand Down
39 changes: 39 additions & 0 deletions src/corva_unit_converter/definitions/proportion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
metric = imperial = {
"%": {
"name": {
"singular": "%",
"plural": "%",
"display": "%"
},
"to_anchor": 1,
"aliases": [
"%"
]
},
"Fraction": {
"name": {
"singular": "Fraction",
"plural": "Fraction",
"display": "Fraction (0-1)"
},
"to_anchor": 100,
"aliases": [
"0-1"
]
}
}

rule = {
"metric": metric,
"imperial": imperial,
"_anchors": {
"metric": {
"unit": "%",
"ratio": 1
},
"imperial": {
"unit": "%",
"ratio": 1
}
}
}
56 changes: 56 additions & 0 deletions src/corva_unit_converter/definitions/strokes_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
metric = imperial = {
"strokes/min": {
"name": {
"singular": "stroke per minute",
"plural": "stroke per minute",
"display": "strokes/min"
},
"to_anchor": 1,
"aliases": [
"strokes/min",
"spm",
"1/m"
]
},
"strokes/sec": {
"name": {
"singular": "stroke per second",
"plural": "stroke per second",
"display": "strokes/sec"
},
"to_anchor": 60,
"aliases": [
"strokes/sec",
"sps",
"1/s"
]
},
"strokes/h": {
"name": {
"singular": "stroke per hour",
"plural": "stroke per hour",
"display": "strokes/h"
},
"to_anchor": 1/60,
"aliases": [
"strokes/h",
"sph",
"1/h"
]
}
}

rule = {
"metric": metric,
"imperial": imperial,
"_anchors": {
"metric": {
"unit": "strokes/min",
"ratio": 1
},
"imperial": {
"unit": "strokes/min",
"ratio": 1
}
}
}
11 changes: 11 additions & 0 deletions tests/test_proportion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .utils import convert_units

# test cases
cases = [
{"from": "%", "amount": 1, "to": "Fraction", "expected": 0.01},
{"from": "Fraction", "amount": 1, "to": '%', "expected": 100},
]


def test():
convert_units(cases)
20 changes: 20 additions & 0 deletions tests/test_strokes_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .utils import convert_units

# Test cases
cases = [
{"from": "strokes/min", "amount": 1, "to": "strokes/sec",
"expected": 0.016666666666666666},
{"from": "strokes/min", "amount": 1, "to": "strokes/h", "expected": 60},

{"from": "strokes/sec", "amount": 1, "to": "strokes/min", "expected": 60},
{"from": "strokes/sec", "amount": 1, "to": "strokes/h", "expected": 3600},

{"from": "strokes/h", "amount": 1, "to": "strokes/sec",
"expected": 0.0002777777777777778},
{"from": "strokes/h", "amount": 1, "to": "strokes/min",
"expected": 0.016666666666666666},
]


def test():
convert_units(cases)

0 comments on commit 2132158

Please sign in to comment.