2021.10 #41
@ -64,10 +64,10 @@ class Iterable(IterableABC):
|
|||||||
def for_each(self, func: Callable):
|
def for_each(self, func: Callable):
|
||||||
for_each_query(self, func)
|
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)
|
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)
|
return min_query(self, func)
|
||||||
|
|
||||||
def order_by(self, func: Callable) -> OrderedIterableABC:
|
def order_by(self, func: Callable) -> OrderedIterableABC:
|
||||||
|
@ -69,10 +69,10 @@ class IterableABC(ABC, list):
|
|||||||
def for_each(self, func: Callable) -> Union[int, float, complex]: pass
|
def for_each(self, func: Callable) -> Union[int, float, complex]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def max(self, func: Callable) -> Union[int, float, complex]: pass
|
def max(self, func: Callable = None) -> Union[int, float, complex]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def min(self, func: Callable) -> Union[int, float, complex]: pass
|
def min(self, func: Callable = None) -> Union[int, float, complex]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def order_by(self, func: Callable) -> 'IterableABC': pass
|
def order_by(self, func: Callable) -> 'IterableABC': pass
|
||||||
|
@ -171,10 +171,26 @@ class QueryTest(unittest.TestCase):
|
|||||||
res = self._tests.max(lambda u: u.address.nr)
|
res = self._tests.max(lambda u: u.address.nr)
|
||||||
self.assertEqual(self._t_user.address.nr, res)
|
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):
|
def test_min(self):
|
||||||
res = self._tests.min(lambda u: u.address.nr)
|
res = self._tests.min(lambda u: u.address.nr)
|
||||||
self.assertEqual(1, res)
|
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):
|
def test_order_by(self):
|
||||||
res = self._tests.order_by(lambda user: user.address.street)
|
res = self._tests.order_by(lambda user: user.address.street)
|
||||||
res2 = self._tests.order_by(lambda user: user.address.nr)
|
res2 = self._tests.order_by(lambda user: user.address.nr)
|
||||||
|
Loading…
Reference in New Issue
Block a user