From ad41d3b086c8f66329e3eaafd64045e5877e22b3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 17 Mar 2025 22:43:31 +0000 Subject: [PATCH 1/3] pint test --- test_pint.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test_pint.py diff --git a/test_pint.py b/test_pint.py new file mode 100644 index 0000000..26348fd --- /dev/null +++ b/test_pint.py @@ -0,0 +1,24 @@ +import pint +import metrology_apis as mt + +Quantity = pint.Quantity +Unit = pint.Unit + + +def test_eq(q: mt.Quantity) -> None: + print(q == q) + +def test_unit(q: mt.Quantity) -> None: + print(q.unit) + +def test_value(q: mt.Quantity) -> None: + print(q.value) + +def test_m(q: mt.Quantity) -> None: + print(q.m) + + +test_eq(Quantity(1, "m")) +test_unit(Quantity(1, "m")) +test_value(Quantity(1, "m")) +# test_m(Quantity(1, "m")) #error: "Quantity[Any, Any]" has no attribute "m" [attr-defined] \ No newline at end of file From b08276db6fa41355f40b39097a1c55d482c17841 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 18 Mar 2025 08:23:49 +0000 Subject: [PATCH 2/3] test unit and dim --- src/metrology_apis/__init__.py | 2 +- test_pint.py | 58 +++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/metrology_apis/__init__.py b/src/metrology_apis/__init__.py index be4d38e..ef29ea2 100644 --- a/src/metrology_apis/__init__.py +++ b/src/metrology_apis/__init__.py @@ -26,7 +26,7 @@ def __pow__(self, other: int | float, /) -> Self: ... def __rmul__(self, other: Self, /) -> Self: ... def __rtruediv__(self, other: Self, /) -> Self: ... - def __rpow__(self, other: int | float, /) -> Self: ... + # def __rpow__(self, other: int | float, /) -> Self: ... @runtime_checkable class Quantity[V, U: Unit](Protocol): diff --git a/test_pint.py b/test_pint.py index 26348fd..fd843bd 100644 --- a/test_pint.py +++ b/test_pint.py @@ -1,24 +1,58 @@ import pint import metrology_apis as mt +import operator as ops Quantity = pint.Quantity Unit = pint.Unit +# Dimension = pint.UnitsContainer -def test_eq(q: mt.Quantity) -> None: - print(q == q) +def test_dimension_op(d: mt.Dimension, op) -> None: + print(op(d, d)) -def test_unit(q: mt.Quantity) -> None: - print(q.unit) -def test_value(q: mt.Quantity) -> None: - print(q.value) +def test_dimension_pow(d: mt.Dimension) -> None: + print(ops.pow(d, 2)) -def test_m(q: mt.Quantity) -> None: - print(q.m) +for op in [ops.mul, ops.truediv]: + test_dimension_op(Unit("m").dimension, op) -test_eq(Quantity(1, "m")) -test_unit(Quantity(1, "m")) -test_value(Quantity(1, "m")) -# test_m(Quantity(1, "m")) #error: "Quantity[Any, Any]" has no attribute "m" [attr-defined] \ No newline at end of file +test_dimension_pow(Unit("m").dimension) + +print(isinstance(Unit("m").dimension, mt.Dimension)) + +def test_unit_op(u: mt.Unit, op) -> None: + print(op(u, u)) + +def test_unit_pow(u: mt.Unit) -> None: + print(ops.pow(u, 2)) + +for op in [ops.mul, ops.truediv]: + test_unit_op(Unit("m"), op) + +test_unit_pow(Unit("m")) + + +print(isinstance(Unit("m"), mt.Unit)) + +# def test_unit(q: mt.Quantity) -> None: +# print(q.unit) + +# def test_value(q: mt.Quantity) -> None: +# print(q.value) + + +# test_unit(Quantity(1, "m")) +# test_value(Quantity(1, "m")) + + +# def test_op(q: mt.Quantity, op) -> None: +# print(op(q, q)) + + +# for op in [ops.eq, ops.ne, ops.lt, ops.le, ops.gt, ops.ge]: +# test_op(Quantity(1, "m"), op) + +# for op in [ops.add, ops.sub, ops.mul, ops.truediv]: +# test_op(Quantity(1, "m"), op) \ No newline at end of file From 26d9538c36eb3447bdbb09c51f7c9a80c05800a9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 19 Mar 2025 07:58:36 +0000 Subject: [PATCH 3/3] test pint --- src/metrology_apis/__init__.py | 1 + test_pint.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/metrology_apis/__init__.py b/src/metrology_apis/__init__.py index ef29ea2..d7f1864 100644 --- a/src/metrology_apis/__init__.py +++ b/src/metrology_apis/__init__.py @@ -38,3 +38,4 @@ def unit(self) -> U: ... ### Dunder Methods def __eq__[B](self: "Quantity[V, U]", other: "Quantity[op.CanEq[V, B], U]", /) -> B: ... +# \ No newline at end of file diff --git a/test_pint.py b/test_pint.py index fd843bd..855bb8d 100644 --- a/test_pint.py +++ b/test_pint.py @@ -36,21 +36,25 @@ def test_unit_pow(u: mt.Unit) -> None: print(isinstance(Unit("m"), mt.Unit)) -# def test_unit(q: mt.Quantity) -> None: -# print(q.unit) +def test_unit(q: mt.Quantity) -> None: + print(q.unit) -# def test_value(q: mt.Quantity) -> None: -# print(q.value) +def test_value(q: mt.Quantity) -> None: + print(q.value) -# test_unit(Quantity(1, "m")) -# test_value(Quantity(1, "m")) +test_unit(Quantity(1, "m")) +test_value(Quantity(1, "m")) +print(isinstance(Quantity(1, "m"), mt.Quantity)) -# def test_op(q: mt.Quantity, op) -> None: -# print(op(q, q)) +def test_op(q: mt.Quantity, op) -> None: + print(op(q, q)) +# for op in [ops.eq]: +# test_op(Quantity(1, "m"), op) + # for op in [ops.eq, ops.ne, ops.lt, ops.le, ops.gt, ops.ge]: # test_op(Quantity(1, "m"), op)