Improved unittests

This commit is contained in:
Sven Heidemann 2021-07-27 12:48:22 +02:00
parent a26c6f1bd9
commit a080119c44
3 changed files with 20 additions and 4 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)