diff --git a/main.py b/main.py index 5be43a2..62b428b 100644 --- a/main.py +++ b/main.py @@ -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 diff --git a/tests/test_main.py b/tests/test_main.py index f62519c..55b0c95 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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!") \ No newline at end of file