mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	svn+ssh://pythondev@svn.python.org/python/trunk ........ r60482 | raymond.hettinger | 2008-01-31 23:07:16 +0100 (Thu, 31 Jan 2008) | 1 line Minor wordsmithing on docstring ........ r60483 | mark.dickinson | 2008-01-31 23:17:37 +0100 (Thu, 31 Jan 2008) | 5 lines Issue #1678380. Fix a bug that identifies 0j and -0j when they appear in the same code unit. The fix is essentially the same as the fix for a previous bug identifying 0. and -0. ........ r60484 | christian.heimes | 2008-02-01 00:08:23 +0100 (Fri, 01 Feb 2008) | 1 line Fixed bug #1983: Return from fork() is pid_t, not int ........ r60486 | jeffrey.yasskin | 2008-02-01 07:22:46 +0100 (Fri, 01 Feb 2008) | 4 lines Move __builtins__.trunc() to math.trunc() per http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue 1965. ........ r60487 | jeffrey.yasskin | 2008-02-01 08:05:46 +0100 (Fri, 01 Feb 2008) | 3 lines Roll back r60248. It's useful to encourage users not to change Rational instances. ........ r60488 | neal.norwitz | 2008-02-01 08:22:59 +0100 (Fri, 01 Feb 2008) | 1 line Fix refleak ........
		
			
				
	
	
		
			54 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
"""Unit tests for numbers.py."""
 | 
						|
 | 
						|
import math
 | 
						|
import operator
 | 
						|
import unittest
 | 
						|
from numbers import Complex, Real, Rational, Integral
 | 
						|
from numbers import Exact, Inexact
 | 
						|
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.failUnless(issubclass(int, Exact))
 | 
						|
        self.failIf(issubclass(int, Inexact))
 | 
						|
 | 
						|
        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.failIf(issubclass(float, Exact))
 | 
						|
        self.failUnless(issubclass(float, Inexact))
 | 
						|
 | 
						|
        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))
 | 
						|
        self.failIf(issubclass(complex, Exact))
 | 
						|
        self.failUnless(issubclass(complex, Inexact))
 | 
						|
 | 
						|
        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()
 |