From e84b9752fa73cd9009b1a0228f2868421cf14c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 10:43:03 +0200 Subject: [PATCH 01/14] added folder and testfiles --- tests/safeds/data/tabular/containers/_row/__init__.py | 0 tests/safeds/data/tabular/containers/_row/test_column_count.py | 0 tests/safeds/data/tabular/containers/_row/test_column_names.py | 0 tests/safeds/data/tabular/containers/_row/test_contains.py | 0 tests/safeds/data/tabular/containers/_row/test_eq.py | 0 tests/safeds/data/tabular/containers/_row/test_get_column_type.py | 0 tests/safeds/data/tabular/containers/_row/test_get_value.py | 0 tests/safeds/data/tabular/containers/_row/test_getitem.py | 0 tests/safeds/data/tabular/containers/_row/test_has_column.py | 0 tests/safeds/data/tabular/containers/_row/test_hash.py | 0 tests/safeds/data/tabular/containers/_row/test_iter.py | 0 tests/safeds/data/tabular/containers/_row/test_len.py | 0 tests/safeds/data/tabular/containers/_row/test_schema.py | 0 tests/safeds/data/tabular/containers/_row/test_sizeof.py | 0 14 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/safeds/data/tabular/containers/_row/__init__.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_column_count.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_column_names.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_contains.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_eq.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_get_column_type.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_get_value.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_getitem.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_has_column.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_hash.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_iter.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_len.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_schema.py create mode 100644 tests/safeds/data/tabular/containers/_row/test_sizeof.py diff --git a/tests/safeds/data/tabular/containers/_row/__init__.py b/tests/safeds/data/tabular/containers/_row/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_column_count.py b/tests/safeds/data/tabular/containers/_row/test_column_count.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_column_names.py b/tests/safeds/data/tabular/containers/_row/test_column_names.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_contains.py b/tests/safeds/data/tabular/containers/_row/test_contains.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_get_value.py b/tests/safeds/data/tabular/containers/_row/test_get_value.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_getitem.py b/tests/safeds/data/tabular/containers/_row/test_getitem.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_has_column.py b/tests/safeds/data/tabular/containers/_row/test_has_column.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_hash.py b/tests/safeds/data/tabular/containers/_row/test_hash.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_iter.py b/tests/safeds/data/tabular/containers/_row/test_iter.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_len.py b/tests/safeds/data/tabular/containers/_row/test_len.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_schema.py b/tests/safeds/data/tabular/containers/_row/test_schema.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/safeds/data/tabular/containers/_row/test_sizeof.py b/tests/safeds/data/tabular/containers/_row/test_sizeof.py new file mode 100644 index 000000000..e69de29bb From 5d88e435388183a10f6860b28ee48157b66c52bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 10:47:47 +0200 Subject: [PATCH 02/14] added assert_row_operation_works --- tests/helpers/_assertions.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/helpers/_assertions.py b/tests/helpers/_assertions.py index 4c4847c6e..f592ac018 100644 --- a/tests/helpers/_assertions.py +++ b/tests/helpers/_assertions.py @@ -3,7 +3,7 @@ from polars.testing import assert_frame_equal from safeds.data.labeled.containers import TabularDataset -from safeds.data.tabular.containers import Cell, Column, Table +from safeds.data.tabular.containers import Cell, Column, Row, Table def assert_tables_equal(table1: Table, table2: Table) -> None: @@ -57,3 +57,24 @@ def assert_cell_operation_works( column = Column("A", [input_value]) transformed_column = column.transform(transformer) assert transformed_column == Column("A", [expected_value]), f"Expected: {expected_value}\nGot: {transformed_column}" + +def assert_row_operation_works( + input_value: Any, + transformer: Callable[[Row], Row], + expected_value: Any, +) -> None: + """ + Assert that a row operation works as expected. + + Parameters + ---------- + input_value: + The value in the input row. + transformer: + The transformer to apply to the rows. + expected_value: + The expected value of the transformed row. + """ + row = Row("A", [input_value]) + transformed_row = row.transform(transformer) + assert transformed_row == Row("A", [expected_value]), f"Expected: {expected_value}\nGot: {transformed_row}" \ No newline at end of file From 3e25a387b09689f7b647ae3f09d29b6463405792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 10:50:58 +0200 Subject: [PATCH 03/14] added assert_row_operation_works to test.helpers --- tests/helpers/__init__.py | 1 + tests/safeds/data/tabular/containers/_row/test_sizeof.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index 1215fa494..a59f8ac14 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -1,5 +1,6 @@ from ._assertions import ( assert_cell_operation_works, + assert_row_operation_works, assert_tables_equal, assert_that_tabular_datasets_are_equal, ) diff --git a/tests/safeds/data/tabular/containers/_row/test_sizeof.py b/tests/safeds/data/tabular/containers/_row/test_sizeof.py index e69de29bb..3c703e4ff 100644 --- a/tests/safeds/data/tabular/containers/_row/test_sizeof.py +++ b/tests/safeds/data/tabular/containers/_row/test_sizeof.py @@ -0,0 +1 @@ +from tests.helpers import assert_row_operation_works \ No newline at end of file From bdb4fb5fe99305f234deefc30227aa8f1b2015d5 Mon Sep 17 00:00:00 2001 From: thelenf0 Date: Fri, 12 Jul 2024 14:28:05 +0200 Subject: [PATCH 04/14] Added test column_count, column_names, contains for rows --- .../containers/_row/test_column_count.py | 21 +++++++++++++++++ .../containers/_row/test_column_names.py | 21 +++++++++++++++++ .../tabular/containers/_row/test_contains.py | 23 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_row/test_column_count.py b/tests/safeds/data/tabular/containers/_row/test_column_count.py index e69de29bb..bac25835f 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_count.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_count.py @@ -0,0 +1,21 @@ +import pytest +from safeds.data.tabular.containers import Table, Row +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + +@pytest.mark.parametrize( + ("table", "expected"), + [ + ([], 0), + ([1, 2, 3], 1), + ], + ids=[ + "empty", + "non-empty", + ], + ) +def test_should_return_the_number_of_columns(table: Table, expected: int) -> None: + row: Row[any]=_LazyVectorizedRow(table=table) + assert row.column_count == expected + + + diff --git a/tests/safeds/data/tabular/containers/_row/test_column_names.py b/tests/safeds/data/tabular/containers/_row/test_column_names.py index e69de29bb..788719ca2 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_names.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_names.py @@ -0,0 +1,21 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table", "expected"), + [ + (Table ({}), []), + (Table({"A": [1, 2, 3]}), ["A"]), + (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), ["A", "B", "C", "D"]), + ], + ids=[ + "empty", + "one-column", + "four-column", + ], + ) +def test_should_return_the_column_names(table: Table,expected: list[str]) -> None: + row: Row[any]=_LazyVectorizedRow(table=table) + assert row.column_names == expected \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_contains.py b/tests/safeds/data/tabular/containers/_row/test_contains.py index e69de29bb..9494e8acb 100644 --- a/tests/safeds/data/tabular/containers/_row/test_contains.py +++ b/tests/safeds/data/tabular/containers/_row/test_contains.py @@ -0,0 +1,23 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table", "column_name", "expected"), + [ + (Table ({}), "A", False), + (Table({"A": [1, 2, 3]}), "A", True), + (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"]}), "C", False), + (Table({"col1": [1, 2, 3], "B": ["A", "A", "Bla"]}), 1, False), + ], + ids=[ + "empty row", + "column exists", + "column does not exist", + "not a string", + ], + ) +def test_should_return_whether_the_row_has_the_column(table: Table, column_name: str, expected: bool) -> None: + row: Row[any]=_LazyVectorizedRow(table=table) + assert (column_name in row) == expected \ No newline at end of file From 4a3b889ff5a8f552a78841acc92b31d92eee9d8c Mon Sep 17 00:00:00 2001 From: thelenf0 Date: Fri, 12 Jul 2024 14:57:44 +0200 Subject: [PATCH 05/14] Added eq Test to row --- .../data/tabular/containers/_row/test_eq.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index e69de29bb..a1098db0e 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -0,0 +1,27 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table1", "table2", "expected"), + [ + (Table({"col1": []}),Table({"col1": []}),True), + (Table({"col1": [1,2]}),Table({"col1": [1,2]}),True), + (Table({"col1": [1,2]}),Table({"col1": [2,3]}),False), + (Table({"col1": [1,2]}),Table({"col2": [1,2]}),False), + (Table({"col1": ["1", "2"]}),Table({"col1": [1,2]}),False), + + ], + ids=[ + "empty rows", + "equal rows", + "different values", + "different columns", + "different types", + ], + ) +def test_should_return_whether_two_rows_are_equal(table1: Table, table2:Table, expected: bool) -> None: + row1: Row[any]=_LazyVectorizedRow(table=table1) + row2: Row[any]=_LazyVectorizedRow(table=table2) + assert (row1.__eq__(row2)) == expected \ No newline at end of file From a2240d1130dcc86113d12fb60846e10f9af77ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 15:04:28 +0200 Subject: [PATCH 06/14] implemented other half of row tests --- tests/helpers/__init__.py | 1 + tests/helpers/_assertions.py | 10 ++--- .../tabular/containers/_row/test_get_value.py | 45 +++++++++++++++++++ .../tabular/containers/_row/test_getitem.py | 45 +++++++++++++++++++ .../containers/_row/test_has_column.py | 21 +++++++++ .../data/tabular/containers/_row/test_hash.py | 24 ++++++++++ .../data/tabular/containers/_row/test_iter.py | 22 +++++++++ .../data/tabular/containers/_row/test_len.py | 21 +++++++++ .../tabular/containers/_row/test_schema.py | 21 +++++++++ .../tabular/containers/_row/test_sizeof.py | 14 +++++- 10 files changed, 218 insertions(+), 6 deletions(-) diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py index a59f8ac14..973be40b1 100644 --- a/tests/helpers/__init__.py +++ b/tests/helpers/__init__.py @@ -39,6 +39,7 @@ __all__ = [ "assert_cell_operation_works", + "assert_row_operation_works", "assert_tables_equal", "assert_that_tabular_datasets_are_equal", "configure_test_with_device", diff --git a/tests/helpers/_assertions.py b/tests/helpers/_assertions.py index f592ac018..66eba2f85 100644 --- a/tests/helpers/_assertions.py +++ b/tests/helpers/_assertions.py @@ -3,7 +3,7 @@ from polars.testing import assert_frame_equal from safeds.data.labeled.containers import TabularDataset -from safeds.data.tabular.containers import Cell, Column, Row, Table +from safeds.data.tabular.containers import Cell, Column, Table def assert_tables_equal(table1: Table, table2: Table) -> None: @@ -60,7 +60,7 @@ def assert_cell_operation_works( def assert_row_operation_works( input_value: Any, - transformer: Callable[[Row], Row], + transformer: Callable[[Table], Table], expected_value: Any, ) -> None: """ @@ -75,6 +75,6 @@ def assert_row_operation_works( expected_value: The expected value of the transformed row. """ - row = Row("A", [input_value]) - transformed_row = row.transform(transformer) - assert transformed_row == Row("A", [expected_value]), f"Expected: {expected_value}\nGot: {transformed_row}" \ No newline at end of file + table = Table(input_value) + transformed_table = transformer(table) + assert transformed_table == Table(expected_value), f"Expected: {expected_value}\nGot: {transformed_table}" \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_get_value.py b/tests/safeds/data/tabular/containers/_row/test_get_value.py index e69de29bb..4c690a514 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_value.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_value.py @@ -0,0 +1,45 @@ +import re + +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow +from safeds.exceptions import ColumnNotFoundError + +from tests.helpers import assert_row_operation_works + + +@pytest.mark.parametrize( + ("table_data", "column_name", "target", "expected"), + [ + ({"A": [1, 2]}, "A", 1, {"A": [2]}), + ({"A": [1, 2, 3], "B": [4, 5, 2]}, "B", 2, {"A": [1, 2], "B": [4, 5]}), + ], + ids=[ + "one column", + "two columns", + ], +) +def test_should_get_correct_item(table_data: dict, column_name: str, target: int, expected: dict) -> None: + assert_row_operation_works( + table_data, + lambda table: table.remove_rows(lambda row: row.get_value(column_name).eq(target)), + expected, + ) + +@pytest.mark.parametrize( + ("table", "column_name"), + [ + (Table(), "A"), + (Table({"A": ["a", "aa", "aaa"]}), "B"), + (Table({"A": ["b", "aa", "aaa"], "C": ["b", "aa", "aaa"]}), "B"), + ], + ids=[ + "empty table", + "table with one column", + "table with two columns", + ], +) +def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")): + row.get_value(column_name) \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_getitem.py b/tests/safeds/data/tabular/containers/_row/test_getitem.py index e69de29bb..a54cf6a79 100644 --- a/tests/safeds/data/tabular/containers/_row/test_getitem.py +++ b/tests/safeds/data/tabular/containers/_row/test_getitem.py @@ -0,0 +1,45 @@ +import re + +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow +from safeds.exceptions import ColumnNotFoundError + +from tests.helpers import assert_row_operation_works + + +@pytest.mark.parametrize( + ("table_data", "column_name", "target", "expected"), + [ + ({"A": [1, 2]}, "A", 1, {"A": [2]}), + ({"A": [1, 2, 3], "B": [4, 5, 2]}, "B", 2, {"A": [1, 2], "B": [4, 5]}), + ], + ids=[ + "table one column", + "table two columns", + ], +) +def test_should_get_correct_item(table_data: dict, column_name: str, target: int, expected: dict) -> None: + assert_row_operation_works( + table_data, + lambda table: table.remove_rows(lambda row: row[column_name].eq(target)), + expected, + ) + +@pytest.mark.parametrize( + ("table", "column_name"), + [ + (Table(), "A"), + (Table({"A": ["a", "aa", "aaa"]}), "B"), + (Table({"A": ["b", "aa", "aaa"], "C": ["b", "aa", "aaa"]}), "B"), + ], + ids=[ + "empty table", + "table with one column", + "table with two columns", + ], +) +def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")): + row[column_name] \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_has_column.py b/tests/safeds/data/tabular/containers/_row/test_has_column.py index e69de29bb..3d496ceda 100644 --- a/tests/safeds/data/tabular/containers/_row/test_has_column.py +++ b/tests/safeds/data/tabular/containers/_row/test_has_column.py @@ -0,0 +1,21 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table", "column_name", "expected"), + [ + (Table(), "A", False), + (Table({"A": ["a", "aa", "aaa"]}), "A", True), + (Table({"A": ["a", "aa", "aaa"]}), "B", False), + ], + ids=[ + "empty table", + "table with existing column_name", + "table with non existing column_name", + ], +) +def test_should_have_column_name(table: Table, column_name: str, expected: bool) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + assert row.has_column(column_name) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_hash.py b/tests/safeds/data/tabular/containers/_row/test_hash.py index e69de29bb..9ec756db3 100644 --- a/tests/safeds/data/tabular/containers/_row/test_hash.py +++ b/tests/safeds/data/tabular/containers/_row/test_hash.py @@ -0,0 +1,24 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table1", "table2", "expected"), + [ + (Table(), Table({"A": ["a", "aa", "aaa"]}), False), + (Table(), Table(), True), + (Table({"A": ["a", "aa", "aaa"]}), Table({"A": ["a", "aa", "aaa"]}), True), + (Table({"A": ["a", "aa", "aaa"]}), Table({"B": ["a", "aa", "aaa"]}), False), + ], + ids=[ + "empty and different table", + "same empty tables", + "same tables", + "different tables", + ], +) +def test_should_return_consistent_hashes(table1: Table, table2: Table, expected: bool) -> None: + row1: Row[any] = _LazyVectorizedRow(table=table1) + row2: Row[any] = _LazyVectorizedRow(table=table2) + assert (hash(row1) == hash(row2)) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_iter.py b/tests/safeds/data/tabular/containers/_row/test_iter.py index e69de29bb..8aaf276a3 100644 --- a/tests/safeds/data/tabular/containers/_row/test_iter.py +++ b/tests/safeds/data/tabular/containers/_row/test_iter.py @@ -0,0 +1,22 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table", "expected"), + [ + (Table(), []), + (Table({"A": ["a", "aa", "aaa"]}), ["A"]), + (Table({"A": ["a", "aa", "aaa"], "B": ["b", "bb", "bbb"], "C": ["c", "cc", "ccc"]}), ["A", "B", "C"]), + ], + ids=[ + "empty", + "one column", + "three columns", + ], +) +def test_should_return_same_list_of_column_name_with_iter(table: Table, expected: list) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + iterable = iter(row) + assert list(iterable) == expected \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_len.py b/tests/safeds/data/tabular/containers/_row/test_len.py index e69de29bb..348fa5532 100644 --- a/tests/safeds/data/tabular/containers/_row/test_len.py +++ b/tests/safeds/data/tabular/containers/_row/test_len.py @@ -0,0 +1,21 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table", "expected"), + [ + (Table(), 0), + (Table({"A": ["a", "aa", "aaa"]}), 1), + (Table({"A": ["a", "aa", "aaa"], "B": ["b", "bb", "bbb"]}), 2), + ], + ids=[ + "empty", + "one column", + "two columns", + ], +) +def test_should_have_same_length_as_number_of_columns(table: Table, expected: int) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + assert len(row) == expected \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_schema.py b/tests/safeds/data/tabular/containers/_row/test_schema.py index e69de29bb..9a6253cec 100644 --- a/tests/safeds/data/tabular/containers/_row/test_schema.py +++ b/tests/safeds/data/tabular/containers/_row/test_schema.py @@ -0,0 +1,21 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + + +@pytest.mark.parametrize( + ("table"), + [ + (Table()), + (Table({"A": ["a", "aa", "aaa"]})), + (Table({"A": ["a", "aa", "aaa"], "B": ["b", "bb", "bbb"]})), + ], + ids=[ + "empty", + "one column", + "two columns", + ], +) +def test_should_return_same_schema(table: Table) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + assert table.schema == row.schema \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_sizeof.py b/tests/safeds/data/tabular/containers/_row/test_sizeof.py index 3c703e4ff..e2a0caf3c 100644 --- a/tests/safeds/data/tabular/containers/_row/test_sizeof.py +++ b/tests/safeds/data/tabular/containers/_row/test_sizeof.py @@ -1 +1,13 @@ -from tests.helpers import assert_row_operation_works \ No newline at end of file +import sys +from typing import TYPE_CHECKING, Any + +import polars as pl +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + +if TYPE_CHECKING: + from safeds.data.tabular.containers import Row + + +def test_should_return_size_greater_than_normal_object() -> None: + cell: Row[Any] = _LazyVectorizedRow(pl.col("a")) + assert sys.getsizeof(cell) > sys.getsizeof(object()) \ No newline at end of file From 3a5bfd7e53879c0b288e6f3890e573522c52cfdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 15:06:08 +0200 Subject: [PATCH 07/14] sorted imports --- tests/safeds/data/tabular/containers/_row/test_column_count.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_row/test_column_count.py b/tests/safeds/data/tabular/containers/_row/test_column_count.py index bac25835f..b28bc137e 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_count.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_count.py @@ -1,7 +1,8 @@ import pytest -from safeds.data.tabular.containers import Table, Row +from safeds.data.tabular.containers import Row, Table from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow + @pytest.mark.parametrize( ("table", "expected"), [ From f4c57dd4d7152561ca49787c4c86459e906d90aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 15:10:46 +0200 Subject: [PATCH 08/14] fixed test_column_count --- .../containers/_row/test_column_count.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_row/test_column_count.py b/tests/safeds/data/tabular/containers/_row/test_column_count.py index b28bc137e..e7df1d525 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_count.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_count.py @@ -4,18 +4,18 @@ @pytest.mark.parametrize( - ("table", "expected"), - [ - ([], 0), - ([1, 2, 3], 1), - ], - ids=[ - "empty", - "non-empty", - ], - ) + ("table", "expected"), + [ + (Table(), 0), + (Table({"A": [1, 2, 3]}), 1), + ], + ids=[ + "empty", + "non-empty", + ], +) def test_should_return_the_number_of_columns(table: Table, expected: int) -> None: - row: Row[any]=_LazyVectorizedRow(table=table) + row: Row[any] = _LazyVectorizedRow(table=table) assert row.column_count == expected From 21bffa1b43718d4ddbf8ab917f82d61c814666cd Mon Sep 17 00:00:00 2001 From: thelenf0 Date: Fri, 12 Jul 2024 15:18:19 +0200 Subject: [PATCH 09/14] Added test_get_column_type to _row --- .../containers/_row/test_get_column_type.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py index e69de29bb..eecc8a204 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py @@ -0,0 +1,20 @@ +import pytest +from safeds.data.tabular.containers import Row, Table +from safeds.data.tabular.containers._lazy_vectorized_row import _LazyVectorizedRow +from safeds.data.tabular.typing import DataType + + +@pytest.mark.parametrize( + ("table", "column_name", "expected"), + [ + (Table({"col1": ["A"]}), "col1", "String"), + (Table({"col1": ["a"],"col2": [1]}), "col2", "Int64"), + ], + ids=[ + "one column", + "two columns", + ], + ) +def test_should_return_the_type_of_the_column(table: Table, column_name: str, expected: DataType) -> None: + row: Row[any]=_LazyVectorizedRow(table=table) + assert str(row.get_column_type(column_name)) == expected From 7f36ca83f31b2422503dc27e8f8aede87e5d439e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 12 Jul 2024 15:25:30 +0200 Subject: [PATCH 10/14] fixed intendation --- .../containers/_row/test_column_names.py | 24 +++++++------- .../tabular/containers/_row/test_contains.py | 32 +++++++++--------- .../data/tabular/containers/_row/test_eq.py | 33 +++++++++---------- .../containers/_row/test_get_column_type.py | 20 +++++------ 4 files changed, 54 insertions(+), 55 deletions(-) diff --git a/tests/safeds/data/tabular/containers/_row/test_column_names.py b/tests/safeds/data/tabular/containers/_row/test_column_names.py index 788719ca2..cc7f53b31 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_names.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_names.py @@ -4,18 +4,18 @@ @pytest.mark.parametrize( - ("table", "expected"), - [ - (Table ({}), []), - (Table({"A": [1, 2, 3]}), ["A"]), - (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), ["A", "B", "C", "D"]), - ], - ids=[ - "empty", - "one-column", - "four-column", - ], - ) + ("table", "expected"), + [ + (Table ({}), []), + (Table({"A": [1, 2, 3]}), ["A"]), + (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), ["A", "B", "C", "D"]), + ], + ids=[ + "empty", + "one-column", + "four-column", + ], +) def test_should_return_the_column_names(table: Table,expected: list[str]) -> None: row: Row[any]=_LazyVectorizedRow(table=table) assert row.column_names == expected \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_contains.py b/tests/safeds/data/tabular/containers/_row/test_contains.py index 9494e8acb..6dc80cb22 100644 --- a/tests/safeds/data/tabular/containers/_row/test_contains.py +++ b/tests/safeds/data/tabular/containers/_row/test_contains.py @@ -4,20 +4,20 @@ @pytest.mark.parametrize( - ("table", "column_name", "expected"), - [ - (Table ({}), "A", False), - (Table({"A": [1, 2, 3]}), "A", True), - (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"]}), "C", False), - (Table({"col1": [1, 2, 3], "B": ["A", "A", "Bla"]}), 1, False), - ], - ids=[ - "empty row", - "column exists", - "column does not exist", - "not a string", - ], - ) + ("table", "column_name", "expected"), + [ + (Table ({}), "A", False), + (Table({"A": [1, 2, 3]}), "A", True), + (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"]}), "C", False), + (Table({"col1": [1, 2, 3], "B": ["A", "A", "Bla"]}), 1, False), + ], + ids=[ + "empty row", + "column exists", + "column does not exist", + "not a string", + ], +) def test_should_return_whether_the_row_has_the_column(table: Table, column_name: str, expected: bool) -> None: - row: Row[any]=_LazyVectorizedRow(table=table) - assert (column_name in row) == expected \ No newline at end of file + row: Row[any]=_LazyVectorizedRow(table=table) + assert (column_name in row) == expected \ No newline at end of file diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index a1098db0e..68636916b 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -4,23 +4,22 @@ @pytest.mark.parametrize( - ("table1", "table2", "expected"), - [ - (Table({"col1": []}),Table({"col1": []}),True), - (Table({"col1": [1,2]}),Table({"col1": [1,2]}),True), - (Table({"col1": [1,2]}),Table({"col1": [2,3]}),False), - (Table({"col1": [1,2]}),Table({"col2": [1,2]}),False), - (Table({"col1": ["1", "2"]}),Table({"col1": [1,2]}),False), - - ], - ids=[ - "empty rows", - "equal rows", - "different values", - "different columns", - "different types", - ], - ) + ("table1", "table2", "expected"), + [ + (Table({"col1": []}),Table({"col1": []}),True), + (Table({"col1": [1,2]}),Table({"col1": [1,2]}),True), + (Table({"col1": [1,2]}),Table({"col1": [2,3]}),False), + (Table({"col1": [1,2]}),Table({"col2": [1,2]}),False), + (Table({"col1": ["1", "2"]}),Table({"col1": [1,2]}),False), + ], + ids=[ + "empty rows", + "equal rows", + "different values", + "different columns", + "different types", + ], +) def test_should_return_whether_two_rows_are_equal(table1: Table, table2:Table, expected: bool) -> None: row1: Row[any]=_LazyVectorizedRow(table=table1) row2: Row[any]=_LazyVectorizedRow(table=table2) diff --git a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py index eecc8a204..4f5ef6d3c 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py @@ -5,16 +5,16 @@ @pytest.mark.parametrize( - ("table", "column_name", "expected"), - [ - (Table({"col1": ["A"]}), "col1", "String"), - (Table({"col1": ["a"],"col2": [1]}), "col2", "Int64"), - ], - ids=[ - "one column", - "two columns", - ], - ) + ("table", "column_name", "expected"), + [ + (Table({"col1": ["A"]}), "col1", "String"), + (Table({"col1": ["a"],"col2": [1]}), "col2", "Int64"), + ], + ids=[ + "one column", + "two columns", + ], +) def test_should_return_the_type_of_the_column(table: Table, column_name: str, expected: DataType) -> None: row: Row[any]=_LazyVectorizedRow(table=table) assert str(row.get_column_type(column_name)) == expected From b813ac81be73632c08053081bfd82704243ccf55 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:29:35 +0000 Subject: [PATCH 11/14] style: apply automated linter fixes --- tests/helpers/_assertions.py | 3 ++- .../containers/_row/test_column_count.py | 7 ++----- .../containers/_row/test_column_names.py | 13 ++++++++----- .../tabular/containers/_row/test_contains.py | 6 +++--- .../data/tabular/containers/_row/test_eq.py | 18 +++++++++--------- .../containers/_row/test_get_column_type.py | 6 +++--- .../tabular/containers/_row/test_get_value.py | 9 +++++---- .../tabular/containers/_row/test_getitem.py | 9 +++++---- .../data/tabular/containers/_row/test_iter.py | 2 +- .../data/tabular/containers/_row/test_len.py | 2 +- .../tabular/containers/_row/test_schema.py | 2 +- .../tabular/containers/_row/test_sizeof.py | 2 +- 12 files changed, 41 insertions(+), 38 deletions(-) diff --git a/tests/helpers/_assertions.py b/tests/helpers/_assertions.py index 66eba2f85..8f1b1f7e0 100644 --- a/tests/helpers/_assertions.py +++ b/tests/helpers/_assertions.py @@ -58,6 +58,7 @@ def assert_cell_operation_works( transformed_column = column.transform(transformer) assert transformed_column == Column("A", [expected_value]), f"Expected: {expected_value}\nGot: {transformed_column}" + def assert_row_operation_works( input_value: Any, transformer: Callable[[Table], Table], @@ -77,4 +78,4 @@ def assert_row_operation_works( """ table = Table(input_value) transformed_table = transformer(table) - assert transformed_table == Table(expected_value), f"Expected: {expected_value}\nGot: {transformed_table}" \ No newline at end of file + assert transformed_table == Table(expected_value), f"Expected: {expected_value}\nGot: {transformed_table}" diff --git a/tests/safeds/data/tabular/containers/_row/test_column_count.py b/tests/safeds/data/tabular/containers/_row/test_column_count.py index e7df1d525..dacf2dbf8 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_count.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_count.py @@ -15,8 +15,5 @@ ], ) def test_should_return_the_number_of_columns(table: Table, expected: int) -> None: - row: Row[any] = _LazyVectorizedRow(table=table) - assert row.column_count == expected - - - + row: Row[any] = _LazyVectorizedRow(table=table) + assert row.column_count == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_column_names.py b/tests/safeds/data/tabular/containers/_row/test_column_names.py index cc7f53b31..c5f55b6e2 100644 --- a/tests/safeds/data/tabular/containers/_row/test_column_names.py +++ b/tests/safeds/data/tabular/containers/_row/test_column_names.py @@ -6,9 +6,12 @@ @pytest.mark.parametrize( ("table", "expected"), [ - (Table ({}), []), + (Table({}), []), (Table({"A": [1, 2, 3]}), ["A"]), - (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), ["A", "B", "C", "D"]), + ( + Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"], "C": [True, True, False], "D": [1.0, 2.1, 4.5]}), + ["A", "B", "C", "D"], + ), ], ids=[ "empty", @@ -16,6 +19,6 @@ "four-column", ], ) -def test_should_return_the_column_names(table: Table,expected: list[str]) -> None: - row: Row[any]=_LazyVectorizedRow(table=table) - assert row.column_names == expected \ No newline at end of file +def test_should_return_the_column_names(table: Table, expected: list[str]) -> None: + row: Row[any] = _LazyVectorizedRow(table=table) + assert row.column_names == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_contains.py b/tests/safeds/data/tabular/containers/_row/test_contains.py index 6dc80cb22..216cbbcde 100644 --- a/tests/safeds/data/tabular/containers/_row/test_contains.py +++ b/tests/safeds/data/tabular/containers/_row/test_contains.py @@ -6,7 +6,7 @@ @pytest.mark.parametrize( ("table", "column_name", "expected"), [ - (Table ({}), "A", False), + (Table({}), "A", False), (Table({"A": [1, 2, 3]}), "A", True), (Table({"A": [1, 2, 3], "B": ["A", "A", "Bla"]}), "C", False), (Table({"col1": [1, 2, 3], "B": ["A", "A", "Bla"]}), 1, False), @@ -19,5 +19,5 @@ ], ) def test_should_return_whether_the_row_has_the_column(table: Table, column_name: str, expected: bool) -> None: - row: Row[any]=_LazyVectorizedRow(table=table) - assert (column_name in row) == expected \ No newline at end of file + row: Row[any] = _LazyVectorizedRow(table=table) + assert (column_name in row) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index 68636916b..7bc6215b0 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -6,11 +6,11 @@ @pytest.mark.parametrize( ("table1", "table2", "expected"), [ - (Table({"col1": []}),Table({"col1": []}),True), - (Table({"col1": [1,2]}),Table({"col1": [1,2]}),True), - (Table({"col1": [1,2]}),Table({"col1": [2,3]}),False), - (Table({"col1": [1,2]}),Table({"col2": [1,2]}),False), - (Table({"col1": ["1", "2"]}),Table({"col1": [1,2]}),False), + (Table({"col1": []}), Table({"col1": []}), True), + (Table({"col1": [1, 2]}), Table({"col1": [1, 2]}), True), + (Table({"col1": [1, 2]}), Table({"col1": [2, 3]}), False), + (Table({"col1": [1, 2]}), Table({"col2": [1, 2]}), False), + (Table({"col1": ["1", "2"]}), Table({"col1": [1, 2]}), False), ], ids=[ "empty rows", @@ -20,7 +20,7 @@ "different types", ], ) -def test_should_return_whether_two_rows_are_equal(table1: Table, table2:Table, expected: bool) -> None: - row1: Row[any]=_LazyVectorizedRow(table=table1) - row2: Row[any]=_LazyVectorizedRow(table=table2) - assert (row1.__eq__(row2)) == expected \ No newline at end of file +def test_should_return_whether_two_rows_are_equal(table1: Table, table2: Table, expected: bool) -> None: + row1: Row[any] = _LazyVectorizedRow(table=table1) + row2: Row[any] = _LazyVectorizedRow(table=table2) + assert (row1.__eq__(row2)) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py index 4f5ef6d3c..f5cd78a25 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_column_type.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_column_type.py @@ -8,7 +8,7 @@ ("table", "column_name", "expected"), [ (Table({"col1": ["A"]}), "col1", "String"), - (Table({"col1": ["a"],"col2": [1]}), "col2", "Int64"), + (Table({"col1": ["a"], "col2": [1]}), "col2", "Int64"), ], ids=[ "one column", @@ -16,5 +16,5 @@ ], ) def test_should_return_the_type_of_the_column(table: Table, column_name: str, expected: DataType) -> None: - row: Row[any]=_LazyVectorizedRow(table=table) - assert str(row.get_column_type(column_name)) == expected + row: Row[any] = _LazyVectorizedRow(table=table) + assert str(row.get_column_type(column_name)) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_get_value.py b/tests/safeds/data/tabular/containers/_row/test_get_value.py index 4c690a514..dac4f8ee7 100644 --- a/tests/safeds/data/tabular/containers/_row/test_get_value.py +++ b/tests/safeds/data/tabular/containers/_row/test_get_value.py @@ -21,10 +21,11 @@ ) def test_should_get_correct_item(table_data: dict, column_name: str, target: int, expected: dict) -> None: assert_row_operation_works( - table_data, - lambda table: table.remove_rows(lambda row: row.get_value(column_name).eq(target)), + table_data, + lambda table: table.remove_rows(lambda row: row.get_value(column_name).eq(target)), expected, - ) + ) + @pytest.mark.parametrize( ("table", "column_name"), @@ -42,4 +43,4 @@ def test_should_get_correct_item(table_data: dict, column_name: str, target: int def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None: row: Row[any] = _LazyVectorizedRow(table=table) with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")): - row.get_value(column_name) \ No newline at end of file + row.get_value(column_name) diff --git a/tests/safeds/data/tabular/containers/_row/test_getitem.py b/tests/safeds/data/tabular/containers/_row/test_getitem.py index a54cf6a79..93f668ad8 100644 --- a/tests/safeds/data/tabular/containers/_row/test_getitem.py +++ b/tests/safeds/data/tabular/containers/_row/test_getitem.py @@ -21,10 +21,11 @@ ) def test_should_get_correct_item(table_data: dict, column_name: str, target: int, expected: dict) -> None: assert_row_operation_works( - table_data, - lambda table: table.remove_rows(lambda row: row[column_name].eq(target)), + table_data, + lambda table: table.remove_rows(lambda row: row[column_name].eq(target)), expected, - ) + ) + @pytest.mark.parametrize( ("table", "column_name"), @@ -42,4 +43,4 @@ def test_should_get_correct_item(table_data: dict, column_name: str, target: int def test_should_raise_column_not_found_error(table: Table, column_name: str) -> None: row: Row[any] = _LazyVectorizedRow(table=table) with pytest.raises(ColumnNotFoundError, match=re.escape(f"Could not find column(s):\n - '{column_name}'")): - row[column_name] \ No newline at end of file + row[column_name] diff --git a/tests/safeds/data/tabular/containers/_row/test_iter.py b/tests/safeds/data/tabular/containers/_row/test_iter.py index 8aaf276a3..e68aefea9 100644 --- a/tests/safeds/data/tabular/containers/_row/test_iter.py +++ b/tests/safeds/data/tabular/containers/_row/test_iter.py @@ -19,4 +19,4 @@ def test_should_return_same_list_of_column_name_with_iter(table: Table, expected: list) -> None: row: Row[any] = _LazyVectorizedRow(table=table) iterable = iter(row) - assert list(iterable) == expected \ No newline at end of file + assert list(iterable) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_len.py b/tests/safeds/data/tabular/containers/_row/test_len.py index 348fa5532..6a9f9f0db 100644 --- a/tests/safeds/data/tabular/containers/_row/test_len.py +++ b/tests/safeds/data/tabular/containers/_row/test_len.py @@ -18,4 +18,4 @@ ) def test_should_have_same_length_as_number_of_columns(table: Table, expected: int) -> None: row: Row[any] = _LazyVectorizedRow(table=table) - assert len(row) == expected \ No newline at end of file + assert len(row) == expected diff --git a/tests/safeds/data/tabular/containers/_row/test_schema.py b/tests/safeds/data/tabular/containers/_row/test_schema.py index 9a6253cec..4ebdc68f2 100644 --- a/tests/safeds/data/tabular/containers/_row/test_schema.py +++ b/tests/safeds/data/tabular/containers/_row/test_schema.py @@ -18,4 +18,4 @@ ) def test_should_return_same_schema(table: Table) -> None: row: Row[any] = _LazyVectorizedRow(table=table) - assert table.schema == row.schema \ No newline at end of file + assert table.schema == row.schema diff --git a/tests/safeds/data/tabular/containers/_row/test_sizeof.py b/tests/safeds/data/tabular/containers/_row/test_sizeof.py index e2a0caf3c..d252a310a 100644 --- a/tests/safeds/data/tabular/containers/_row/test_sizeof.py +++ b/tests/safeds/data/tabular/containers/_row/test_sizeof.py @@ -10,4 +10,4 @@ def test_should_return_size_greater_than_normal_object() -> None: cell: Row[Any] = _LazyVectorizedRow(pl.col("a")) - assert sys.getsizeof(cell) > sys.getsizeof(object()) \ No newline at end of file + assert sys.getsizeof(cell) > sys.getsizeof(object()) From 86c5aa75879fea7e9c722649fdbcbe49bdbdc5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Wed, 17 Jul 2024 13:13:51 +0200 Subject: [PATCH 12/14] increased code coverage of __eq__ for _LazyVectorizedRow --- .../data/tabular/containers/_row/test_eq.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index 7bc6215b0..0dd97852a 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -24,3 +24,34 @@ def test_should_return_whether_two_rows_are_equal(table1: Table, table2: Table, row1: Row[any] = _LazyVectorizedRow(table=table1) row2: Row[any] = _LazyVectorizedRow(table=table2) assert (row1.__eq__(row2)) == expected + +@pytest.mark.parametrize( + ("table", "expected"), + [ + (Table({"col1": []}), True), + (Table({"col1": [1, 2]}), True), + ], + ids=[ + "empty table", + "filled table", + ], +) +def test_should_return_true_if_rows_are_strict_equal(table: Table, expected: bool) -> None: + row1: Row[any] = _LazyVectorizedRow(table=table) + assert (row1.__eq__(row1)) == expected + + +@pytest.mark.parametrize( + ("table1", "table2"), + [ + (Table({"col1": []}), Table({"col1": []})), + (Table({"col1": [1, 2]}), Table({"col1": [1, 2]})), + ], + ids=[ + "empty tables", + "filled tables", + ], +) +def test_should_return_false_if_object_is_other_instance(table1: Table, table2: Table) -> None: + row1: Row[any] = _LazyVectorizedRow(table=table1) + assert (row1.__eq__(table2)) == NotImplemented From 6054ee6ee2635533dcdebd160ae513efdfc9fc21 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:16:28 +0000 Subject: [PATCH 13/14] style: apply automated linter fixes --- tests/safeds/data/tabular/containers/_row/test_eq.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index 0dd97852a..f6b51e8d9 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -25,6 +25,7 @@ def test_should_return_whether_two_rows_are_equal(table1: Table, table2: Table, row2: Row[any] = _LazyVectorizedRow(table=table2) assert (row1.__eq__(row2)) == expected + @pytest.mark.parametrize( ("table", "expected"), [ From 8af1c33e3725c594781f160c965abb71547e0c5f Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Thu, 18 Jul 2024 12:02:18 +0200 Subject: [PATCH 14/14] refactor: rename test [skip ci] --- tests/safeds/data/tabular/containers/_row/test_eq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds/data/tabular/containers/_row/test_eq.py b/tests/safeds/data/tabular/containers/_row/test_eq.py index f6b51e8d9..1bcfb3470 100644 --- a/tests/safeds/data/tabular/containers/_row/test_eq.py +++ b/tests/safeds/data/tabular/containers/_row/test_eq.py @@ -53,6 +53,6 @@ def test_should_return_true_if_rows_are_strict_equal(table: Table, expected: boo "filled tables", ], ) -def test_should_return_false_if_object_is_other_instance(table1: Table, table2: Table) -> None: +def test_should_return_false_if_object_is_other_type(table1: Table, table2: Table) -> None: row1: Row[any] = _LazyVectorizedRow(table=table1) assert (row1.__eq__(table2)) == NotImplemented