MCPcopy Index your code
hub / github.com/python/cpython / testFromFloat

Method testFromFloat

Lib/test/test_fractions.py:537–563  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

535 self.assertNotEqual(F(4, 2), r)
536
537 def testFromFloat(self):
538 self.assertRaises(TypeError, F.from_float, 3+4j)
539 self.assertEqual((10, 1), _components(F.from_float(10)))
540 bigint = 1234567890123456789
541 self.assertEqual((bigint, 1), _components(F.from_float(bigint)))
542 self.assertEqual((0, 1), _components(F.from_float(-0.0)))
543 self.assertEqual((10, 1), _components(F.from_float(10.0)))
544 self.assertEqual((-5, 2), _components(F.from_float(-2.5)))
545 self.assertEqual((99999999999999991611392, 1),
546 _components(F.from_float(1e23)))
547 self.assertEqual(float(10**23), float(F.from_float(1e23)))
548 self.assertEqual((3602879701896397, 1125899906842624),
549 _components(F.from_float(3.2)))
550 self.assertEqual(3.2, float(F.from_float(3.2)))
551
552 inf = 1e1000
553 nan = inf - inf
554 # bug 16469: error types should be consistent with float -> int
555 self.assertRaisesMessage(
556 OverflowError, "cannot convert Infinity to integer ratio",
557 F.from_float, inf)
558 self.assertRaisesMessage(
559 OverflowError, "cannot convert Infinity to integer ratio",
560 F.from_float, -inf)
561 self.assertRaisesMessage(
562 ValueError, "cannot convert NaN to integer ratio",
563 F.from_float, nan)
564
565 def testFromDecimal(self):
566 self.assertRaises(TypeError, F.from_decimal, 3+4j)

Callers

nothing calls this directly

Calls 5

assertRaisesMessageMethod · 0.95
_componentsFunction · 0.85
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
from_floatMethod · 0.45

Tested by

no test coverage detected