(self)
| 201 | self.assertEqual(lcm(MyIndexable(120), MyIndexable(84)), 840) |
| 202 | |
| 203 | def test_isqrt(self): |
| 204 | isqrt = self.module.isqrt |
| 205 | # Test a variety of inputs, large and small. |
| 206 | test_values = ( |
| 207 | list(range(1000)) |
| 208 | + list(range(10**6 - 1000, 10**6 + 1000)) |
| 209 | + [2**e + i for e in range(60, 200) for i in range(-40, 40)] |
| 210 | + [3**9999, 10**5001] |
| 211 | ) |
| 212 | |
| 213 | for value in test_values: |
| 214 | with self.subTest(value=value): |
| 215 | s = isqrt(value) |
| 216 | self.assertIs(type(s), int) |
| 217 | self.assertLessEqual(s*s, value) |
| 218 | self.assertLess(value, (s+1)*(s+1)) |
| 219 | |
| 220 | # Negative values |
| 221 | with self.assertRaises(ValueError): |
| 222 | isqrt(-1) |
| 223 | |
| 224 | # Integer-like things |
| 225 | self.assertIntEqual(isqrt(True), 1) |
| 226 | self.assertIntEqual(isqrt(False), 0) |
| 227 | self.assertIntEqual(isqrt(MyIndexable(1729)), 41) |
| 228 | |
| 229 | with self.assertRaises(ValueError): |
| 230 | isqrt(MyIndexable(-3)) |
| 231 | |
| 232 | # Non-integer-like things |
| 233 | bad_values = [ |
| 234 | 3.5, "a string", Decimal("3.5"), 3.5j, |
| 235 | 100.0, -4.0, |
| 236 | ] |
| 237 | for value in bad_values: |
| 238 | with self.subTest(value=value): |
| 239 | with self.assertRaises(TypeError): |
| 240 | isqrt(value) |
| 241 | |
| 242 | @support.bigmemtest(2**32, memuse=0.85) |
| 243 | def test_isqrt_huge(self, size): |
nothing calls this directly
no test coverage detected