Coverage for tests/test_functions.py: 100%
53 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-12 21:24 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-12 21:24 +0000
1# Licensed under the EUPL-1.2 or later.
2# You may obtain a copy of the licence in all the official languages of the
3# European Union at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
5"""Test functions in typed_stream.functions."""
7from __future__ import annotations
9import operator
11from typed_stream.functions import (
12 is_bool,
13 is_complex,
14 is_even,
15 is_falsy,
16 is_float,
17 is_int,
18 is_negative,
19 is_none,
20 is_not_none,
21 is_number,
22 is_odd,
23 is_positive,
24 is_real_number,
25 is_str,
26 is_truthy,
27 noop,
28 one,
29)
31__all__ = (
32 "noop",
33 "is_none",
34 "is_not_none",
35 "is_number",
36 "is_int",
37 "is_str",
38 "is_complex",
39 "is_bool",
40 "is_float",
41 "is_real_number",
42)
44assert is_falsy == operator.not_
45assert is_truthy == operator.truth
47assert noop(100) is None # type: ignore[func-returns-value]
48assert noop() is None # type: ignore[func-returns-value]
50assert one(100) == 1
51assert one() == 1
53assert is_even(100)
54assert is_even(20)
55assert is_even(10)
56assert is_even(2)
57assert not is_odd(100)
58assert not is_odd(20)
59assert not is_odd(10)
60assert not is_odd(2)
61assert is_odd(101)
62assert is_odd(21)
63assert is_odd(11)
64assert is_odd(1)
65assert not is_even(101)
66assert not is_even(21)
67assert not is_even(11)
68assert not is_even(1)
70assert is_positive(1)
71assert not is_positive(0)
72assert not is_positive(-1)
74assert is_negative(-1)
75assert not is_negative(0)
76assert not is_negative(1)
79assert is_int(10)
80assert not is_int(1.1)
81assert not is_float(10)
82assert is_float(1.1)
84assert is_str("a")
85assert not is_str(1e2)
87assert is_complex(10 + 0j)
88assert not is_complex(0)
90assert is_number(10 + 0j)
91assert not is_number("0")
93assert is_real_number(0)
94assert not is_real_number(10 + 0j)
95assert not is_real_number("0")
97assert is_bool(True)
98assert is_bool(False)
99assert not is_bool(1)
100assert not is_bool(0)
102assert is_none(None)
103assert not is_not_none(None)
104assert not is_none(1)
105assert is_not_none(1)