-
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 #14. ### Summary of Changes * Add a new method `sort_rows` to the `Table` class to sort rows using some criteria. * Rename the parameter of `sort_columns` for the sorting criteria to `comparator`. --------- Co-authored-by: lars-reimann <lars-reimann@users.noreply.github.com>
- Loading branch information
1 parent
ec011e4
commit 20aaf5e
Showing
2 changed files
with
88 additions
and
11 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
49 changes: 49 additions & 0 deletions
49
tests/safeds/data/tabular/containers/_table/test_sort_rows.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,49 @@ | ||
from typing import Callable | ||
|
||
import pytest | ||
from safeds.data.tabular.containers import Column, Row, Table | ||
|
||
|
||
class TestSortRows: | ||
@pytest.mark.parametrize( | ||
("table", "comparator", "expected"), | ||
[ | ||
# Activate when https://github.com/Safe-DS/Stdlib/issues/75 is fixed. | ||
# ( | ||
# Table.from_columns([Column([], "col1")]), | ||
# lambda row1, row2: row1["col1"] - row2["col1"], | ||
# Table.from_columns([Column([], "col1")]), | ||
# ), | ||
( | ||
Table.from_columns([Column([3, 2, 1], "col1")]), | ||
lambda row1, row2: row1["col1"] - row2["col1"], | ||
Table.from_columns([Column([1, 2, 3], "col1")]), | ||
), | ||
], | ||
) | ||
def test_should_return_sorted_table( | ||
self, table: Table, comparator: Callable[[Row, Row], int], expected: Table | ||
) -> None: | ||
assert table.sort_rows(comparator) == expected | ||
|
||
@pytest.mark.parametrize( | ||
("table", "comparator", "expected"), | ||
[ | ||
# Activate when https://github.com/Safe-DS/Stdlib/issues/75 is fixed. | ||
# ( | ||
# Table.from_columns([Column([], "col1")]), | ||
# lambda row1, row2: row1["col1"] - row2["col1"], | ||
# Table.from_columns([Column([], "col1")]) | ||
# ), | ||
( | ||
Table.from_columns([Column([3, 2, 1], "col1")]), | ||
lambda row1, row2: row1["col1"] - row2["col1"], | ||
Table.from_columns([Column([3, 2, 1], "col1")]), | ||
), | ||
], | ||
) | ||
def test_should_not_modify_original_table( | ||
self, table: Table, comparator: Callable[[Row, Row], int], expected: Table | ||
) -> None: | ||
table.sort_rows(comparator) | ||
assert table == expected |