Skip to content

Commit

Permalink
fix(area): update area units
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Oct 15, 2024
1 parent 66b2882 commit a6428c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ph_units/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def convert(_value, _input_unit, _target_unit):
if _value is None:
return None

if str(_value).strip() == "":
return 0

input_unit, target_unit = _clean_user_inputs(
_input_unit, _target_unit, unit_type_alias_dict
)
Expand Down
24 changes: 21 additions & 3 deletions ph_units/unit_types/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MeterSquare(Base_UnitType):
"""Meter Square"""

__symbol__ = "M2"
__aliases__ = ["SM", "SQM", "SQ.M", "SQ-M", "SQ-METER", "SQ-METERS", "M²"]
__aliases__ = ["SM", "SQM", "SQ.M", "SQ-M", "SQ-METER", "SQ-METERS", "M²", "m²"]
__factors__ = {
"M2": "{}*1",
"CM2": "{}*10_000",
Expand All @@ -22,7 +22,15 @@ class CentimeterSquare(Base_UnitType):
"""Centimeter Square"""

__symbol__ = "CM2"
__aliases__ = ["SQCM", "SQ.CM", "SQ-CM", "SQ-CENTIMETER", "SQ-CENTIMETERS", "CM²"]
__aliases__ = [
"SQCM",
"SQ.CM",
"SQ-CM",
"SQ-CENTIMETER",
"SQ-CENTIMETERS",
"CM²",
"cm²",
]
__factors__ = {
"MM2": "{}*100",
"CM2": "{}*1",
Expand All @@ -36,7 +44,15 @@ class MillimeterSquare(Base_UnitType):
"""Millimeter Square"""

__symbol__ = "MM2"
__aliases__ = ["SQMM", "SQ.MM", "SQ-MM", "SQ-MILLIMETER", "SQ-MILLIMETERS", "MM²"]
__aliases__ = [
"SQMM",
"SQ.MM",
"SQ-MM",
"SQ-MILLIMETER",
"SQ-MILLIMETERS",
"MM²",
"mm²",
]
__factors__ = {
"MM2": "{}*1",
"CM2": "{}*0.01",
Expand All @@ -58,6 +74,7 @@ class FootSquare(Base_UnitType):
"SQ-FT",
"SQ-FOOT",
"FT²",
"ft²",
"SQ-FEET",
]
__factors__ = {
Expand All @@ -81,6 +98,7 @@ class InchSquare(Base_UnitType):
"SQ-IN",
"SQ-INCH",
"IN²",
"in²",
"SQ-INCHES",
]
__factors__ = {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from ph_units.unit_type import Unit


def test_space():
assert convert(" ", "M2", "M2") == 0


def test_meter_squared():
assert convert(1, "M2", "M2") == 1
assert convert(1, "M²", "M2") == 1
Expand Down

0 comments on commit a6428c6

Please sign in to comment.