66is not in effect.
77"""
88
9- from __future__ import (absolute_import ,
9+ from __future__ import (absolute_import ,
1010 print_function , unicode_literals )
1111from future import standard_library
1212from future .builtins import *
2020@unittest .skipIf (not PY2 , 'old division tests only for Py2' )
2121class IntTestCasesOldDivision (unittest .TestCase ):
2222
23+ def setUp (self ):
24+ self .longMessage = True
25+
26+
2327 def test_div (self ):
2428 """
2529 Issue #38
2630 """
2731 a = int (3 )
2832 self .assertEqual (a / 5. , 0.6 )
2933 self .assertEqual (a / 5 , 0 )
30-
34+
3135
3236 def test_idiv (self ):
3337 a = int (3 )
@@ -42,7 +46,7 @@ def test_idiv(self):
4246 c /= 2.0
4347 self .assertEqual (c , - 1.5 )
4448 self .assertTrue (isinstance (c , float ))
45-
49+
4650
4751 def test_truediv (self ):
4852 """
@@ -74,5 +78,24 @@ def test_truediv(self):
7478 self .assertTrue (isinstance (e , int ))
7579
7680
81+ def test_divmod (self ):
82+ """
83+ Test int.__divmod__
84+ """
85+ vals = [10 ** i for i in range (0 , 20 )]
86+ for i in range (200 ):
87+ x = random .choice (vals )
88+ y = random .choice (vals )
89+ self .assertEqual (int (y ).__rdivmod__ (int (x )), divmod (x , y ), msg = 'x={0}; y={1}' .format (x , y ))
90+ self .assertEqual (int (- y ).__rdivmod__ (int (x )), divmod (x , - y ), msg = 'x={0}; y={1}' .format (x , y ))
91+ self .assertEqual (int (y ).__rdivmod__ (int (- x )), divmod (- x , y ), msg = 'x={0}; y={1}' .format (x , y ))
92+ self .assertEqual (int (- y ).__rdivmod__ (int (- x )), divmod (- x , - y ), msg = 'x={0}; y={1}' .format (x , y ))
93+
94+ self .assertEqual (int (x ).__rdivmod__ (int (y )), long (x ).__rdivmod__ (y ), msg = 'x={0}; y={1}' .format (x , y ))
95+ self .assertEqual (int (- x ).__rdivmod__ (int (y )), long (- x ).__rdivmod__ (y ), msg = 'x={0}; y={1}' .format (x , y ))
96+ self .assertEqual (int (x ).__rdivmod__ (int (- y )), long (x ).__rdivmod__ (- y ), msg = 'x={0}; y={1}' .format (x , y ))
97+ self .assertEqual (int (- x ).__rdivmod__ (int (- y )), long (- x ).__rdivmod__ (- y ), msg = 'x={0}; y={1}' .format (x , y ))
98+
99+
77100if __name__ == "__main__" :
78101 unittest .main ()
0 commit comments