Skip to content

Commit

Permalink
.sort() method
Browse files Browse the repository at this point in the history
  • Loading branch information
cootshk committed Nov 2, 2023
1 parent 07e7e5c commit 0b06cc8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@ def __add__(self, other: Any) -> "Table":
return Table(self.list, self.dict | other)
else:
raise TypeError(f"unsupported operand type(s) for +: 'Table' and '{type(other).__name__}'")

@override
def sort(self, key: Optional[Callable]=None, reverse: bool=False):
self.list.sort(key=key, reverse=reverse)
return self
1 change: 1 addition & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ def test_tables():
assert x == Table(1,2,3, foo="bar", spam="eggs"), "Test 7 failed!"
assert x + Table(4,5,6) == Table(1,2,3,4,5,6, foo="bar", spam="eggs"), "Test 8 failed!"
assert x.foreach(lambda k, v: [k, v]) == [0, 1, 1, 2, 2, 3, "foo", "bar", "spam", "eggs"], "Test 9 failed!"
assert Table(1,3,2).sort() == Table(1,2,3), "Test 10 failed!"
#congrats, the code works!
print("All tests passed!")

0 comments on commit 0b06cc8

Please sign in to comment.