Files
textual/tests/test_partition.py
Will McGugan b514e9544b test fix
2022-07-29 10:28:50 +01:00

28 lines
778 B
Python

from textual._partition import partition
def test_partition():
def is_odd(value: int) -> bool:
return bool(value % 2)
def is_greater_than_five(value: int) -> bool:
return value > 5
assert partition(is_odd, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == (
[2, 4, 6, 8, 10],
[1, 3, 5, 7, 9],
)
assert partition(is_odd, [1, 2]) == ([2], [1])
assert partition(is_odd, [1]) == ([], [1])
assert partition(is_odd, []) == ([], [])
assert partition(is_greater_than_five, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == (
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
)
assert partition(is_greater_than_five, [6, 7, 8, 9, 10]) == ([], [6, 7, 8, 9, 10])
assert partition(is_greater_than_five, [1, 2, 3]) == ([1, 2, 3], [])