mirror of
https://github.com/python/cpython.git
synced 2025-10-25 10:44:55 +00:00
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61404 | raymond.hettinger | 2008-03-15 21:02:04 +0100 (Sat, 15 Mar 2008) | 17 lines
Removed Exact/Inexact after discussion with Yasskin.
Unlike Scheme where exactness is implemented as taints, the Python
implementation associated exactness with data types. This created
inheritance issues (making an exact subclass of floats would result
in the subclass having both an explicit Exact registration and an
inherited Inexact registration). This was a problem for the
decimal module which was designed to span both exact and inexact
arithmetic. There was also a question of use cases and no examples
were found where ABCs for exactness could be used to improve code.
One other issue was having separate tags for both the affirmative
and negative cases. This is at odds with the approach taken
elsewhere in the Python (i.e. we don't have an ABC both Hashable
and Unhashable).
........
r61405 | raymond.hettinger | 2008-03-15 21:37:50 +0100 (Sat, 15 Mar 2008) | 1 line
Zap one more use of Exact/Inexact.
........
r61406 | neal.norwitz | 2008-03-15 23:03:18 +0100 (Sat, 15 Mar 2008) | 9 lines
Add a warning for code like:
assert (0, 'message')
An empty tuple does not create a warning. While questionable usage:
assert (), 'message'
should not display a warning. Tested manually.
The warning message could be improved. Feel free to update it.
........
r61407 | neal.norwitz | 2008-03-15 23:36:01 +0100 (Sat, 15 Mar 2008) | 1 line
Handle memory allocation failure. Found by Adam Olsen
........
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Unit tests for numbers.py."""
|
|
|
|
import math
|
|
import operator
|
|
import unittest
|
|
from numbers import Complex, Real, Rational, Integral
|
|
from numbers import Number
|
|
from test import test_support
|
|
|
|
class TestNumbers(unittest.TestCase):
|
|
def test_int(self):
|
|
self.failUnless(issubclass(int, Integral))
|
|
self.failUnless(issubclass(int, Complex))
|
|
|
|
self.assertEqual(7, int(7).real)
|
|
self.assertEqual(0, int(7).imag)
|
|
self.assertEqual(7, int(7).conjugate())
|
|
self.assertEqual(7, int(7).numerator)
|
|
self.assertEqual(1, int(7).denominator)
|
|
|
|
def test_float(self):
|
|
self.failIf(issubclass(float, Rational))
|
|
self.failUnless(issubclass(float, Real))
|
|
|
|
self.assertEqual(7.3, float(7.3).real)
|
|
self.assertEqual(0, float(7.3).imag)
|
|
self.assertEqual(7.3, float(7.3).conjugate())
|
|
|
|
def test_complex(self):
|
|
self.failIf(issubclass(complex, Real))
|
|
self.failUnless(issubclass(complex, Complex))
|
|
|
|
c1, c2 = complex(3, 2), complex(4,1)
|
|
# XXX: This is not ideal, but see the comment in math_trunc().
|
|
self.assertRaises(TypeError, math.trunc, c1)
|
|
self.assertRaises(TypeError, operator.mod, c1, c2)
|
|
self.assertRaises(TypeError, divmod, c1, c2)
|
|
self.assertRaises(TypeError, operator.floordiv, c1, c2)
|
|
self.assertRaises(TypeError, float, c1)
|
|
self.assertRaises(TypeError, int, c1)
|
|
|
|
def test_main():
|
|
test_support.run_unittest(TestNumbers)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|