(self)
| 2220 | self.assertEqual(d.as_tuple(), (1, (0,), 'F')) |
| 2221 | |
| 2222 | def test_as_integer_ratio(self): |
| 2223 | Decimal = self.decimal.Decimal |
| 2224 | |
| 2225 | # exceptional cases |
| 2226 | self.assertRaises(OverflowError, |
| 2227 | Decimal.as_integer_ratio, Decimal('inf')) |
| 2228 | self.assertRaises(OverflowError, |
| 2229 | Decimal.as_integer_ratio, Decimal('-inf')) |
| 2230 | self.assertRaises(ValueError, |
| 2231 | Decimal.as_integer_ratio, Decimal('-nan')) |
| 2232 | self.assertRaises(ValueError, |
| 2233 | Decimal.as_integer_ratio, Decimal('snan123')) |
| 2234 | |
| 2235 | for exp in range(-4, 2): |
| 2236 | for coeff in range(1000): |
| 2237 | for sign in '+', '-': |
| 2238 | d = Decimal('%s%dE%d' % (sign, coeff, exp)) |
| 2239 | pq = d.as_integer_ratio() |
| 2240 | p, q = pq |
| 2241 | |
| 2242 | # check return type |
| 2243 | self.assertIsInstance(pq, tuple) |
| 2244 | self.assertIsInstance(p, int) |
| 2245 | self.assertIsInstance(q, int) |
| 2246 | |
| 2247 | # check normalization: q should be positive; |
| 2248 | # p should be relatively prime to q. |
| 2249 | self.assertGreater(q, 0) |
| 2250 | self.assertEqual(math.gcd(p, q), 1) |
| 2251 | |
| 2252 | # check that p/q actually gives the correct value |
| 2253 | self.assertEqual(Decimal(p) / Decimal(q), d) |
| 2254 | |
| 2255 | def test_subclassing(self): |
| 2256 | # Different behaviours when subclassing Decimal |
nothing calls this directly
no test coverage detected