From 8349ed9db7ee61f8c20c9f13d8765d1003237590 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 26 Sep 2024 13:02:16 +0200 Subject: [PATCH] fix: unwrap operators of cell operations --- src/safeds/data/tabular/containers/_cell.py | 30 +++++++++++++++++++ .../data/tabular/containers/_lazy_cell.py | 6 ++++ .../data/tabular/containers/_cell/test_add.py | 12 ++++++++ .../data/tabular/containers/_cell/test_and.py | 12 ++++++++ .../data/tabular/containers/_cell/test_div.py | 12 ++++++++ .../data/tabular/containers/_cell/test_eq.py | 12 ++++++++ .../tabular/containers/_cell/test_floordiv.py | 9 ++++++ .../data/tabular/containers/_cell/test_ge.py | 12 ++++++++ .../data/tabular/containers/_cell/test_gt.py | 12 ++++++++ .../data/tabular/containers/_cell/test_le.py | 12 ++++++++ .../data/tabular/containers/_cell/test_lt.py | 12 ++++++++ .../data/tabular/containers/_cell/test_mod.py | 12 ++++++++ .../data/tabular/containers/_cell/test_mul.py | 12 ++++++++ .../data/tabular/containers/_cell/test_ne.py | 15 ++++++++++ .../data/tabular/containers/_cell/test_or.py | 12 ++++++++ .../data/tabular/containers/_cell/test_pow.py | 12 ++++++++ .../data/tabular/containers/_cell/test_sub.py | 12 ++++++++ .../data/tabular/containers/_cell/test_xor.py | 12 ++++++++ 18 files changed, 228 insertions(+) diff --git a/src/safeds/data/tabular/containers/_cell.py b/src/safeds/data/tabular/containers/_cell.py index a148a96a4..5c8650f81 100644 --- a/src/safeds/data/tabular/containers/_cell.py +++ b/src/safeds/data/tabular/containers/_cell.py @@ -599,6 +599,36 @@ def eq(self, other: Any) -> Cell[bool]: """ return self.__eq__(other) + def neq(self, other: Any) -> Cell[bool]: + """ + Check if not equal to a value. This is equivalent to the `!=` operator. + + Examples + -------- + >>> from safeds.data.tabular.containers import Column + >>> column = Column("example", [1, 2]) + >>> column.transform(lambda cell: cell.neq(2)) + +---------+ + | example | + | --- | + | bool | + +=========+ + | true | + | false | + +---------+ + + >>> column.transform(lambda cell: cell != 2) + +---------+ + | example | + | --- | + | bool | + +=========+ + | true | + | false | + +---------+ + """ + return self.__ne__(other) + def ge(self, other: Any) -> Cell[bool]: """ Check if greater than or equal to a value. This is equivalent to the `>=` operator. diff --git a/src/safeds/data/tabular/containers/_lazy_cell.py b/src/safeds/data/tabular/containers/_lazy_cell.py index 504db02ed..0e1703c73 100644 --- a/src/safeds/data/tabular/containers/_lazy_cell.py +++ b/src/safeds/data/tabular/containers/_lazy_cell.py @@ -39,21 +39,27 @@ def __invert__(self) -> Cell[bool]: return _wrap(self._expression.cast(pl.Boolean).__invert__()) def __and__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__and__(other)) def __rand__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__rand__(other)) def __or__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__or__(other)) def __ror__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__ror__(other)) def __xor__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__xor__(other)) def __rxor__(self, other: bool | Cell[bool]) -> Cell[bool]: + other = _unwrap(other) return _wrap(self._expression.__rxor__(other)) # Comparison --------------------------------------------------------------- diff --git a/tests/safeds/data/tabular/containers/_cell/test_add.py b/tests/safeds/data/tabular/containers/_cell/test_add.py index 5773ae9d3..4b07e93df 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_add.py +++ b/tests/safeds/data/tabular/containers/_cell/test_add.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeAddition: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell + value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell + _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 + cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) + cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.add(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.add(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_and.py b/tests/safeds/data/tabular/containers/_cell/test_and.py index cbae19fb5..db00a7ac9 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_and.py +++ b/tests/safeds/data/tabular/containers/_cell/test_and.py @@ -2,6 +2,9 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -32,8 +35,17 @@ class TestShouldComputeConjunction: def test_dunder_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell & value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell & _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 & cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) & cell, expected) + def test_named_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.and_(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.and_(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_div.py b/tests/safeds/data/tabular/containers/_cell/test_div.py index e2ad00380..f43517ff3 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_div.py +++ b/tests/safeds/data/tabular/containers/_cell/test_div.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeDivision: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell / value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell / _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 / cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) / cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.div(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.div(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_eq.py b/tests/safeds/data/tabular/containers/_cell/test_eq.py index 9347e1456..692983f75 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_eq.py +++ b/tests/safeds/data/tabular/containers/_cell/test_eq.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeEquality: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell == value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell == _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 == cell, expected) # type: ignore[arg-type,return-value] + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) == cell, expected) # type: ignore[arg-type,return-value] + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.eq(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.eq(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_floordiv.py b/tests/safeds/data/tabular/containers/_cell/test_floordiv.py index 495b129cc..6d9481df2 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_floordiv.py +++ b/tests/safeds/data/tabular/containers/_cell/test_floordiv.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,5 +25,11 @@ class TestShouldComputeDivision: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell // value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell // _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 // cell, expected) + + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) // cell, expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_ge.py b/tests/safeds/data/tabular/containers/_cell/test_ge.py index f285f4ae2..bc9a645dd 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_ge.py +++ b/tests/safeds/data/tabular/containers/_cell/test_ge.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeGreaterThanOrEqual: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell >= value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell >= _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 >= cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) >= cell, expected) + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.ge(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.ge(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_gt.py b/tests/safeds/data/tabular/containers/_cell/test_gt.py index a28704793..5d886f718 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_gt.py +++ b/tests/safeds/data/tabular/containers/_cell/test_gt.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeGreaterThan: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell > value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell > _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 > cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) > cell, expected) + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.gt(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.gt(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_le.py b/tests/safeds/data/tabular/containers/_cell/test_le.py index d2ea39816..11939d2b9 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_le.py +++ b/tests/safeds/data/tabular/containers/_cell/test_le.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeLessThanOrEqual: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell <= value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell <= _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 <= cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) <= cell, expected) + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.le(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.le(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_lt.py b/tests/safeds/data/tabular/containers/_cell/test_lt.py index 2dc961031..2a49b539e 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_lt.py +++ b/tests/safeds/data/tabular/containers/_cell/test_lt.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeLessThan: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell < value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell < _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 < cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) < cell, expected) + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.lt(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.lt(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_mod.py b/tests/safeds/data/tabular/containers/_cell/test_mod.py index e71bc4642..942fd650f 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_mod.py +++ b/tests/safeds/data/tabular/containers/_cell/test_mod.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeModulus: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell % value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell % _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 % cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) % cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.mod(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.mod(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_mul.py b/tests/safeds/data/tabular/containers/_cell/test_mul.py index a9da48885..99ed0827f 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_mul.py +++ b/tests/safeds/data/tabular/containers/_cell/test_mul.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeMultiplication: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell * value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell * _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 * cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) * cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.mul(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.mul(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_ne.py b/tests/safeds/data/tabular/containers/_cell/test_ne.py index e826c2b6e..6ca9a6040 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_ne.py +++ b/tests/safeds/data/tabular/containers/_cell/test_ne.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,5 +25,17 @@ class TestShouldComputeNegatedEquality: def test_dunder_method(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell != value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell != _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: value2 != cell, expected) # type: ignore[arg-type,return-value] + + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: _LazyCell(pl.lit(value2)) != cell, expected) # type: ignore[arg-type,return-value] + + def test_named_method(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.neq(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.neq(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_or.py b/tests/safeds/data/tabular/containers/_cell/test_or.py index edf5bc89c..c3668bd0b 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_or.py +++ b/tests/safeds/data/tabular/containers/_cell/test_or.py @@ -2,6 +2,9 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -32,8 +35,17 @@ class TestShouldComputeDisjunction: def test_dunder_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell | value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell | _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 | cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) | cell, expected) + def test_named_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.or_(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.or_(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_pow.py b/tests/safeds/data/tabular/containers/_cell/test_pow.py index 40a2d5216..89703429e 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_pow.py +++ b/tests/safeds/data/tabular/containers/_cell/test_pow.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputePower: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell**value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell**_LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1**cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1))**cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.pow(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.pow(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_sub.py b/tests/safeds/data/tabular/containers/_cell/test_sub.py index f5dc9b885..9d911a869 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_sub.py +++ b/tests/safeds/data/tabular/containers/_cell/test_sub.py @@ -1,5 +1,8 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -22,8 +25,17 @@ class TestShouldComputeSubtraction: def test_dunder_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell - value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell - _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value2, lambda cell: value1 - cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) - cell, expected) + def test_named_method(self, value1: float, value2: float, expected: float) -> None: assert_cell_operation_works(value1, lambda cell: cell.sub(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: float, value2: float, expected: float) -> None: + assert_cell_operation_works(value1, lambda cell: cell.sub(_LazyCell(pl.lit(value2))), expected) diff --git a/tests/safeds/data/tabular/containers/_cell/test_xor.py b/tests/safeds/data/tabular/containers/_cell/test_xor.py index 256846491..b816a7544 100644 --- a/tests/safeds/data/tabular/containers/_cell/test_xor.py +++ b/tests/safeds/data/tabular/containers/_cell/test_xor.py @@ -2,6 +2,9 @@ import pytest +import polars as pl + +from safeds.data.tabular.containers._lazy_cell import _LazyCell from tests.helpers import assert_cell_operation_works @@ -32,8 +35,17 @@ class TestShouldComputeExclusiveOr: def test_dunder_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell ^ value2, expected) + def test_dunder_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell ^ _LazyCell(pl.lit(value2)), expected) + def test_dunder_method_inverted_order(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value2, lambda cell: value1 ^ cell, expected) + def test_dunder_method_inverted_order_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value2, lambda cell: _LazyCell(pl.lit(value1)) ^ cell, expected) + def test_named_method(self, value1: Any, value2: bool, expected: bool) -> None: assert_cell_operation_works(value1, lambda cell: cell.xor(value2), expected) + + def test_named_method_wrapped_in_cell(self, value1: Any, value2: bool, expected: bool) -> None: + assert_cell_operation_works(value1, lambda cell: cell.xor(_LazyCell(pl.lit(value2))), expected)