Skip to content

Commit

Permalink
fix(areas): Add more area types
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-p-may committed Jun 25, 2024
1 parent a7cee2e commit 3c8b1ac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
23 changes: 22 additions & 1 deletion ph_units/unit_types/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ class MeterSquare(Base_UnitType):

__symbol__ = "M2"
__aliases__ = ["SM", "SQM", "SQ.M", "SQ-M", "SQ-METER", "SQ-METERS", "M²"]
__factors__ = {"M2": "{}*1", "FT2": "{}*10.76391042"}
__factors__ = {
"M2": "{}*1",
"CM2": "{}*10_000",
"MM2": "{}*1_000_000",
"FT2": "{}*10.76391042",
}


class CentimeterSquare(Base_UnitType):
"""Centimeter Square"""

__symbol__ = "CM2"
__aliases__ = ["SQCM", "SQ.CM", "SQ-CM", "SQ-CENTIMETER", "SQ-CENTIMETERS", "CM²"]
__factors__ = {"MM2": "{}*100", "CM2": "{}*1", "M2": "{}*0.0001", "FT2": "{}*1"}


class MillimeterSquare(Base_UnitType):
"""Millimeter Square"""

__symbol__ = "MM2"
__aliases__ = ["SQMM", "SQ.MM", "SQ-MM", "SQ-MILLIMETER", "SQ-MILLIMETERS", "MM²"]
__factors__ = {"MM2": "{}*1", "CM2": "{}*0.01", "M2": "{}*0.000001", "FT2": "{}*1"}


class FootSquare(Base_UnitType):
Expand Down
20 changes: 19 additions & 1 deletion tests/test_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@

def test_meter_squared():
assert convert(1, "M2", "M2") == 1
assert convert(1, "M²", "M2") == 1
assert convert(1, "M2", "CM2") == 10_000
assert convert(1, "M2", "MM2") == 1_000_000
assert convert(00.0553, "M2", "MM2") == 55_300
assert convert(1, "M2", "FT2") == pytest.approx(10.76391042)
assert convert(1, "M²", "FT2") == pytest.approx(10.76391042)


def test_centimeter_squared():
assert convert(1, "CM2", "CM2") == 1
assert convert(1, "CM²", "CM2") == 1
assert convert(1, "CM2", "M2") == 0.0001
assert convert(1, "CM2", "MM2") == 100


def test_millimeter_squared():
assert convert(1, "MM2", "MM2") == 1
assert convert(1, "MM²", "MM2") == 1
assert convert(1, "MM2", "M2") == 0.000001
assert convert(34_565_678, "MM2", "M2") == 34.565678
assert convert(1, "MM2", "CM2") == 0.01


def test_foot_squared():
Expand Down

0 comments on commit 3c8b1ac

Please sign in to comment.