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

Method test_fractions

Lib/test/test_numeric_tower.py:137–150  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

135 self.check_equal_hash(D('12300.000'), D(12300))
136
137 def test_fractions(self):
138 # check special case for fractions where either the numerator
139 # or the denominator is a multiple of _PyHASH_MODULUS
140 self.assertEqual(hash(F(1, _PyHASH_MODULUS)), _PyHASH_INF)
141 self.assertEqual(hash(F(-1, 3*_PyHASH_MODULUS)), -_PyHASH_INF)
142 self.assertEqual(hash(F(7*_PyHASH_MODULUS, 1)), 0)
143 self.assertEqual(hash(F(-_PyHASH_MODULUS, 1)), 0)
144
145 # The numbers ABC doesn't enforce that the "true" division
146 # of integers produces a float. This tests that the
147 # Rational.__float__() method has required type conversions.
148 x = F._from_coprime_ints(DummyIntegral(1), DummyIntegral(2))
149 self.assertRaises(TypeError, lambda: x.numerator/x.denominator)
150 self.assertEqual(float(x), 0.5)
151
152 def test_hash_normalization(self):
153 # Test for a bug encountered while changing long_hash.

Callers

nothing calls this directly

Calls 5

DummyIntegralClass · 0.85
_from_coprime_intsMethod · 0.80
FClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected