Skip to content

Commit

Permalink
added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikguempel committed Jun 6, 2023
1 parent 64dbbcf commit 23b16f7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
17 changes: 16 additions & 1 deletion tests/safeds/data/tabular/containers/_table/test_add_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ def test_should_add_columns(table1: Table, columns: list[Column], expected: Tabl
Table({"col3": [0, -1, -2], "col4": ["a", "b", "c"]}),
Table({"col1": [1, 2, 1], "col2": [1, 2, 4], "col3": [0, -1, -2], "col4": ["a", "b", "c"]}),
),
(
Table(),
Table({"col1": [1, 2], "col2": [60, 2]}),
Table({"col1": [1, 2], "col2": [60, 2]})
),
(
Table({"col1": [1, 2], "col2": [60, 2]}),
Table(),
Table({"col1": [1, 2], "col2": [60, 2]}),
),
(
Table({"yeet": [], "col": []}),
Table({"gg": []}),
Table({"yeet": [], "col": [], "gg": []})
)
],
ids=["add a table with 2 columns"],
ids=["add a table with 2 columns", "empty add filled", "filled add empty", "rowless"],
)
def test_should_add_columns_from_table(table1: Table, table2: Table, expected: Table) -> None:
table1 = table1.add_columns(table2)
Expand Down
14 changes: 11 additions & 3 deletions tests/safeds/data/tabular/containers/_table/test_add_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@
Row({"col1": 5, "col2": 6}),
Table({"col1": [1, 2, 1, 5], "col2": [1, 2, 4, 6]}),
),
(Table({"col2": [], "col4": []}), Row({"col2": 5, "col4": 6}), Table({"col2": [5], "col4": [6]})),
(Table(), Row({"col2": 5, "col4": 6}), Table({"col2": [5], "col4": [6]})),
(
Table({"col2": [], "col4": []}),
Row({"col2": 5, "col4": 6}),
Table({"col2": [5], "col4": [6]})
),
(
Table(),
Row({"col2": 5, "col4": 6}),
Table({"col2": [5], "col4": [6]})
),
],
ids=["added row", "added row to empty column", "empty row to empty table"],
ids=["add row", "add row to rowless table", "add row to empty table"],
)
def test_should_add_row(table: Table, row: Row, expected: Table) -> None:
table = table.add_row(row)
Expand Down
17 changes: 16 additions & 1 deletion tests/safeds/data/tabular/containers/_table/test_add_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,23 @@ def test_should_add_rows(table1: Table, rows: list[Row], table2: Table) -> None:
Table({"col1": [5, 7], "col2": [6, 8]}),
Table({"col1": [1, 2, 1, 5, 7], "col2": [1, 2, 4, 6, 8]}),
),
(
Table({"col1": [2], "yikes": [5]}),
Table(),
Table({"col1": [2], "yikes": [5]}),
),
(
Table(),
Table({"col1": [2], "yikes": [5]}),
Table({"col1": [2], "yikes": [5]}),
),
(
Table({"col1": [], "yikes": []}),
Table({"col1": [], "yikes": []}),
Table({"col1": [], "yikes": []}),
)
],
ids=["Rows from table"],
ids=["Rows from table", "add empty to table", "add on empty table", "rowless"],
)
def test_should_add_rows_from_table(table1: Table, table2: Table, expected: Table) -> None:
table1 = table1.add_rows(table2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[
(
{},
Table.from_dict({}),
Table(),
),
(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@


@pytest.mark.parametrize(
("dataframe", "schema", "expected"),
("dataframe", "schema", "expected", "expected_table"),
[
(
pd.DataFrame({"col1": [0]}),
Schema({"col1": Integer()}),
Schema({"col1": Integer()}),
Table({"col1": [0]})
),
(
pd.DataFrame({"col1": [0], "col2": ["a"]}),
Schema({"col1": Integer(), "col2": String()}),
Schema({"col1": Integer(), "col2": String()}),
Table({"col1": [0], "col2": ["a"]})
),
(
pd.DataFrame({"col1": [0, 1.1]}),
Schema({"col1": String()}),
Schema({"col1": String()}),
Table({"col1": [0, 1.1]})
),
(
pd.DataFrame({"col1": [0, 1.1], "col2": ["a", "b"]}),
Schema({"col1": String(), "col2": String()}),
Schema({"col1": String(), "col2": String()}),
Table({"col1": [0, 1.1], "col2": ["a", "b"]})
),
(
pd.DataFrame(),
Schema({}),
Schema({}),
Table()
),
],
ids=["one row, one column", "one row, two columns", "two rows, one column", "two rows, two columns", "empty"],
)
def test_should_use_the_schema_if_passed(dataframe: pd.DataFrame, schema: Schema, expected: Schema) -> None:
def test_should_use_the_schema_if_passed(dataframe: pd.DataFrame, schema: Schema, expected: Schema, expected_table: Table) -> None:
table = Table._from_pandas_dataframe(dataframe, schema)
assert table._schema == expected
assert table == expected_table


@pytest.mark.parametrize(
Expand Down
23 changes: 19 additions & 4 deletions tests/safeds/data/tabular/containers/_table/test_remove_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@
@pytest.mark.parametrize(
("table1", "expected", "columns"),
[
(Table({"col1": [1, 2, 1], "col2": ["a", "b", "c"]}), Table({"col1": [1, 2, 1]}), ["col2"]),
(Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}), Table({}), ["col1", "col2"]),
(Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}), Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}), []),
(
Table({"col1": [1, 2, 1], "col2": ["a", "b", "c"]}),
Table({"col1": [1, 2, 1]}),
["col2"]
),
(
Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}),
Table({}),
["col1", "col2"]
),
(
Table({"col1": [1, 2, 1], "col2": [1, 2, 4]}),
Table({"col1": [1, 2, 1],"col2": [1, 2, 4]}),
[]
),
(Table(),
Table(),
[]),
],
ids=["one column", "multiple columns", "no columns"],
ids=["one column", "multiple columns", "no columns", "empty"],
)
def test_should_remove_table_columns(table1: Table, expected: Table, columns: list[str]) -> None:
table1 = table1.remove_columns(columns)
Expand Down

0 comments on commit 23b16f7

Please sign in to comment.