6
6
from test .support import import_helper
7
7
from test .support import script_helper
8
8
from test .support import warnings_helper
9
+ from test .support .testcase import FloatsAreIdenticalMixin
9
10
# Skip this test if the _testcapi module isn't available.
10
11
_testcapi = import_helper .import_module ('_testcapi' )
11
12
from _testcapi import getargs_keywords , getargs_keyword_only
@@ -436,11 +437,7 @@ def test_K(self):
436
437
self .assertEqual (VERY_LARGE & ULLONG_MAX , getargs_K (VERY_LARGE ))
437
438
438
439
439
- class Float_TestCase (unittest .TestCase ):
440
- def assertEqualWithSign (self , actual , expected ):
441
- self .assertEqual (actual , expected )
442
- self .assertEqual (math .copysign (1 , actual ), math .copysign (1 , expected ))
443
-
440
+ class Float_TestCase (unittest .TestCase , FloatsAreIdenticalMixin ):
444
441
def test_f (self ):
445
442
from _testcapi import getargs_f
446
443
self .assertEqual (getargs_f (4.25 ), 4.25 )
@@ -462,10 +459,10 @@ def test_f(self):
462
459
self .assertEqual (getargs_f (DBL_MAX ), INF )
463
460
self .assertEqual (getargs_f (- DBL_MAX ), - INF )
464
461
if FLT_MIN > DBL_MIN :
465
- self .assertEqualWithSign (getargs_f (DBL_MIN ), 0.0 )
466
- self .assertEqualWithSign (getargs_f (- DBL_MIN ), - 0.0 )
467
- self .assertEqualWithSign (getargs_f (0.0 ), 0.0 )
468
- self .assertEqualWithSign (getargs_f (- 0.0 ), - 0.0 )
462
+ self .assertFloatsAreIdentical (getargs_f (DBL_MIN ), 0.0 )
463
+ self .assertFloatsAreIdentical (getargs_f (- DBL_MIN ), - 0.0 )
464
+ self .assertFloatsAreIdentical (getargs_f (0.0 ), 0.0 )
465
+ self .assertFloatsAreIdentical (getargs_f (- 0.0 ), - 0.0 )
469
466
r = getargs_f (NAN )
470
467
self .assertNotEqual (r , r )
471
468
@@ -494,8 +491,8 @@ def test_d(self):
494
491
self .assertEqual (getargs_d (x ), x )
495
492
self .assertRaises (OverflowError , getargs_d , 1 << DBL_MAX_EXP )
496
493
self .assertRaises (OverflowError , getargs_d , - 1 << DBL_MAX_EXP )
497
- self .assertEqualWithSign (getargs_d (0.0 ), 0.0 )
498
- self .assertEqualWithSign (getargs_d (- 0.0 ), - 0.0 )
494
+ self .assertFloatsAreIdentical (getargs_d (0.0 ), 0.0 )
495
+ self .assertFloatsAreIdentical (getargs_d (- 0.0 ), - 0.0 )
499
496
r = getargs_d (NAN )
500
497
self .assertNotEqual (r , r )
501
498
@@ -519,10 +516,10 @@ def test_D(self):
519
516
self .assertEqual (getargs_D (c ), c )
520
517
c = complex (1.0 , x )
521
518
self .assertEqual (getargs_D (c ), c )
522
- self .assertEqualWithSign (getargs_D (complex (0.0 , 1.0 )).real , 0.0 )
523
- self .assertEqualWithSign (getargs_D (complex (- 0.0 , 1.0 )).real , - 0.0 )
524
- self .assertEqualWithSign (getargs_D (complex (1.0 , 0.0 )).imag , 0.0 )
525
- self .assertEqualWithSign (getargs_D (complex (1.0 , - 0.0 )).imag , - 0.0 )
519
+ self .assertFloatsAreIdentical (getargs_D (complex (0.0 , 1.0 )).real , 0.0 )
520
+ self .assertFloatsAreIdentical (getargs_D (complex (- 0.0 , 1.0 )).real , - 0.0 )
521
+ self .assertFloatsAreIdentical (getargs_D (complex (1.0 , 0.0 )).imag , 0.0 )
522
+ self .assertFloatsAreIdentical (getargs_D (complex (1.0 , - 0.0 )).imag , - 0.0 )
526
523
527
524
528
525
class Paradox :
0 commit comments