(self)
| 1692 | @cpython_only |
| 1693 | @requires_specialization |
| 1694 | def test_to_bool(self): |
| 1695 | def to_bool_bool(): |
| 1696 | true_cnt, false_cnt = 0, 0 |
| 1697 | elems = [e % 2 == 0 for e in range(_testinternalcapi.SPECIALIZATION_THRESHOLD)] |
| 1698 | for e in elems: |
| 1699 | if e: |
| 1700 | true_cnt += 1 |
| 1701 | else: |
| 1702 | false_cnt += 1 |
| 1703 | d, m = divmod(_testinternalcapi.SPECIALIZATION_THRESHOLD, 2) |
| 1704 | self.assertEqual(true_cnt, d + m) |
| 1705 | self.assertEqual(false_cnt, d) |
| 1706 | |
| 1707 | to_bool_bool() |
| 1708 | self.assert_specialized(to_bool_bool, "TO_BOOL_BOOL") |
| 1709 | self.assert_no_opcode(to_bool_bool, "TO_BOOL") |
| 1710 | |
| 1711 | def to_bool_int(): |
| 1712 | count = 0 |
| 1713 | for i in range(_testinternalcapi.SPECIALIZATION_THRESHOLD): |
| 1714 | if i: |
| 1715 | count += 1 |
| 1716 | else: |
| 1717 | count -= 1 |
| 1718 | self.assertEqual(count, _testinternalcapi.SPECIALIZATION_THRESHOLD - 2) |
| 1719 | |
| 1720 | to_bool_int() |
| 1721 | self.assert_specialized(to_bool_int, "TO_BOOL_INT") |
| 1722 | self.assert_no_opcode(to_bool_int, "TO_BOOL") |
| 1723 | |
| 1724 | def to_bool_list(): |
| 1725 | count = 0 |
| 1726 | elems = list(range(_testinternalcapi.SPECIALIZATION_THRESHOLD)) |
| 1727 | while elems: |
| 1728 | count += elems.pop() |
| 1729 | self.assertEqual(elems, []) |
| 1730 | self.assertEqual(count, sum(range(_testinternalcapi.SPECIALIZATION_THRESHOLD))) |
| 1731 | |
| 1732 | to_bool_list() |
| 1733 | self.assert_specialized(to_bool_list, "TO_BOOL_LIST") |
| 1734 | self.assert_no_opcode(to_bool_list, "TO_BOOL") |
| 1735 | |
| 1736 | def to_bool_none(): |
| 1737 | count = 0 |
| 1738 | elems = [None] * _testinternalcapi.SPECIALIZATION_THRESHOLD |
| 1739 | for e in elems: |
| 1740 | if not e: |
| 1741 | count += 1 |
| 1742 | self.assertEqual(count, _testinternalcapi.SPECIALIZATION_THRESHOLD) |
| 1743 | |
| 1744 | to_bool_none() |
| 1745 | self.assert_specialized(to_bool_none, "TO_BOOL_NONE") |
| 1746 | self.assert_no_opcode(to_bool_none, "TO_BOOL") |
| 1747 | |
| 1748 | def to_bool_str(): |
| 1749 | count = 0 |
| 1750 | elems = [""] + ["foo"] * (_testinternalcapi.SPECIALIZATION_THRESHOLD - 1) |
| 1751 | for e in elems: |
nothing calls this directly
no test coverage detected