From a080119c449e15addcb5dc0c457342cdee874176 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 27 Jul 2021 12:48:22 +0200 Subject: [PATCH] Improved unittests --- src/cpl_query/_extension/iterable.py | 4 ++-- src/cpl_query/extension/iterable_abc.py | 4 ++-- src/cpl_query/tests/query_test.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cpl_query/_extension/iterable.py b/src/cpl_query/_extension/iterable.py index abd06a14..44793b87 100644 --- a/src/cpl_query/_extension/iterable.py +++ b/src/cpl_query/_extension/iterable.py @@ -64,10 +64,10 @@ class Iterable(IterableABC): def for_each(self, func: Callable): for_each_query(self, func) - def max(self, func: Callable) -> Union[int, float, complex]: + def max(self, func: Callable = None) -> Union[int, float, complex]: return max_query(self, func) - def min(self, func: Callable) -> Union[int, float, complex]: + def min(self, func: Callable = None) -> Union[int, float, complex]: return min_query(self, func) def order_by(self, func: Callable) -> OrderedIterableABC: diff --git a/src/cpl_query/extension/iterable_abc.py b/src/cpl_query/extension/iterable_abc.py index e8b8c8a9..d21cb116 100644 --- a/src/cpl_query/extension/iterable_abc.py +++ b/src/cpl_query/extension/iterable_abc.py @@ -69,10 +69,10 @@ class IterableABC(ABC, list): def for_each(self, func: Callable) -> Union[int, float, complex]: pass @abstractmethod - def max(self, func: Callable) -> Union[int, float, complex]: pass + def max(self, func: Callable = None) -> Union[int, float, complex]: pass @abstractmethod - def min(self, func: Callable) -> Union[int, float, complex]: pass + def min(self, func: Callable = None) -> Union[int, float, complex]: pass @abstractmethod def order_by(self, func: Callable) -> 'IterableABC': pass diff --git a/src/cpl_query/tests/query_test.py b/src/cpl_query/tests/query_test.py index f150f56b..cc850237 100644 --- a/src/cpl_query/tests/query_test.py +++ b/src/cpl_query/tests/query_test.py @@ -171,10 +171,26 @@ class QueryTest(unittest.TestCase): res = self._tests.max(lambda u: u.address.nr) self.assertEqual(self._t_user.address.nr, res) + tests = List(values=list(range(0, 100))) + self.assertEqual(99, tests.max()) + + def wrong(): + e_res = List(str, list([str(v) for v in range(0, 100)])).max() + + self.assertRaises(WrongTypeException, wrong) + def test_min(self): res = self._tests.min(lambda u: u.address.nr) self.assertEqual(1, res) + tests = List(values=list(range(0, 100))) + self.assertEqual(0, tests.min()) + + def wrong(): + e_res = List(str, list([str(v) for v in range(0, 100)])).min() + + self.assertRaises(WrongTypeException, wrong) + def test_order_by(self): res = self._tests.order_by(lambda user: user.address.street) res2 = self._tests.order_by(lambda user: user.address.nr)