File: test_partition.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (27 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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], [])