-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #872 ### Summary of Changes This pull request improves the tests for rows and lazyVectorizedRows. --------- Co-authored-by: thelenf0 <[email protected]> Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
ee1aea0
commit c485987
Showing
16 changed files
with
382 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
19 changes: 19 additions & 0 deletions
19
tests/safeds/data/tabular/containers/_row/test_column_count.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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": [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 |
24 changes: 24 additions & 0 deletions
24
tests/safeds/data/tabular/containers/_row/test_column_names.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
("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 |
23 changes: 23 additions & 0 deletions
23
tests/safeds/data/tabular/containers/_row/test_contains.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 | ||
|
||
|
||
@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_type(table1: Table, table2: Table) -> None: | ||
row1: Row[any] = _LazyVectorizedRow(table=table1) | ||
assert (row1.__eq__(table2)) == NotImplemented |
20 changes: 20 additions & 0 deletions
20
tests/safeds/data/tabular/containers/_row/test_get_column_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
46 changes: 46 additions & 0 deletions
46
tests/safeds/data/tabular/containers/_row/test_get_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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] |
21 changes: 21 additions & 0 deletions
21
tests/safeds/data/tabular/containers/_row/test_has_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.