示例工程 02-syntax-c-go-java
02-syntax-c-go-java/01-truthiness-table/test_truthiness_table.py
"""test_truthiness_table.py"""
from __future__ import annotations
from truthiness_table import Flag, samples, truthiness
def test_standard_falsy_values() -> None:
values: list[object] = [None, 0, 0.0, "", [], {}, ()]
assert truthiness(values) == [False] * len(values)
def test_non_empty_and_custom_bool() -> None:
assert truthiness([1, "0", [0], {"a": 0}]) == [True, True, True, True]
assert bool(Flag(False)) is False
assert bool(Flag(True)) is True
def test_samples_cover_both() -> None:
result = truthiness(list(samples().values()))
assert False in result
assert True in result