Debian Codegraph @

tests/test_tools.py

raw
1 from rich._loop import loop_first, loop_last, loop_first_last
2 from rich._ratio import ratio_distribute
3
4
5 def test_loop_first():
6 assert list(loop_first([])) == []
7 iterable = loop_first(["apples", "oranges", "pears", "lemons"])
8 assert next(iterable) == (True, "apples")
9 assert next(iterable) == (False, "oranges")
10 assert next(iterable) == (False, "pears")
11 assert next(iterable) == (False, "lemons")
12
13
14 def test_loop_last():
15 assert list(loop_last([])) == []
16 iterable = loop_last(["apples", "oranges", "pears", "lemons"])
17 assert next(iterable) == (False, "apples")
18 assert next(iterable) == (False, "oranges")
19 assert next(iterable) == (False, "pears")
20 assert next(iterable) == (True, "lemons")
21
22
23 def test_loop_first_last():
24 assert list(loop_first_last([])) == []
25 iterable = loop_first_last(["apples", "oranges", "pears", "lemons"])
26 assert next(iterable) == (True, False, "apples")
27 assert next(iterable) == (False, False, "oranges")
28 assert next(iterable) == (False, False, "pears")
29 assert next(iterable) == (False, True, "lemons")
30
31
32 def test_ratio_distribute():
33 assert ratio_distribute(10, [1]) == [10]
34 assert ratio_distribute(10, [1, 1]) == [5, 5]
35 assert ratio_distribute(12, [1, 3]) == [3, 9]
36 assert ratio_distribute(0, [1, 3]) == [0, 0]
37 assert ratio_distribute(0, [1, 3], [1, 1]) == [1, 1]
38 assert ratio_distribute(10, [1, 0]) == [10, 0]