@@ -31,7 +31,7 @@ class ArraySubclassWithKwargs(array.array):
3131 def __init__ (self , typecode , newarg = None ):
3232 array .array .__init__ (self )
3333
34- typecodes = 'uwbBhHiIlLfdqQ '
34+ typecodes = 'uwbBhHiIlLfdqQFD '
3535
3636class MiscTest (unittest .TestCase ):
3737
@@ -113,6 +113,10 @@ def __index__(self):
113113UTF16_BE = 19
114114UTF32_LE = 20
115115UTF32_BE = 21
116+ IEEE_754_FLOAT_COMPLEX_LE = 22
117+ IEEE_754_FLOAT_COMPLEX_BE = 23
118+ IEEE_754_DOUBLE_COMPLEX_LE = 24
119+ IEEE_754_DOUBLE_COMPLEX_BE = 25
116120
117121
118122class ArrayReconstructorTest (unittest .TestCase ):
@@ -139,7 +143,7 @@ def test_error(self):
139143 self .assertRaises (ValueError , array_reconstructor ,
140144 array .array , "b" , UNKNOWN_FORMAT , b"" )
141145 self .assertRaises (ValueError , array_reconstructor ,
142- array .array , "b" , 22 , b"" )
146+ array .array , "b" , 26 , b"" )
143147 self .assertRaises (ValueError , array_reconstructor ,
144148 array .array , "d" , 16 , b"a" )
145149
@@ -279,7 +283,7 @@ def test_byteswap(self):
279283 example = self .example
280284 a = array .array (self .typecode , example )
281285 self .assertRaises (TypeError , a .byteswap , 42 )
282- if a .itemsize in (1 , 2 , 4 , 8 ):
286+ if a .itemsize in (1 , 2 , 4 , 8 , 16 ):
283287 b = array .array (self .typecode , example )
284288 b .byteswap ()
285289 if a .itemsize == 1 :
@@ -1525,6 +1529,55 @@ def test_byteswap(self):
15251529 b .byteswap ()
15261530 self .assertEqual (a , b )
15271531
1532+ class CFPTest (NumberTest ):
1533+ example = [- 42j , 0 , 42 + 1j , 1e5j , - 1e10 ]
1534+ outside = 23
1535+
1536+ def assertEntryEqual (self , entry1 , entry2 ):
1537+ self .assertAlmostEqual (entry1 , entry2 )
1538+
1539+ def test_cmp (self ):
1540+ a = array .array (self .typecode , self .example )
1541+ self .assertIs (a == 42 , False )
1542+ self .assertIs (a != 42 , True )
1543+
1544+ self .assertIs (a == a , True )
1545+ self .assertIs (a != a , False )
1546+ self .assertIs (a < a , False )
1547+ self .assertIs (a <= a , True )
1548+ self .assertIs (a > a , False )
1549+ self .assertIs (a >= a , True )
1550+
1551+ self .assertIs (a == 2 * a , False )
1552+ self .assertIs (a != 2 * a , True )
1553+ self .assertIs (a < 2 * a , True )
1554+ self .assertIs (a <= 2 * a , True )
1555+ self .assertIs (a > 2 * a , False )
1556+ self .assertIs (a >= 2 * a , False )
1557+
1558+ def test_nan (self ):
1559+ a = array .array (self .typecode , [float ('nan' )])
1560+ b = array .array (self .typecode , [float ('nan' )])
1561+ self .assertIs (a != b , True )
1562+ self .assertIs (a == b , False )
1563+
1564+ def test_byteswap (self ):
1565+ a = array .array (self .typecode , self .example )
1566+ self .assertRaises (TypeError , a .byteswap , 42 )
1567+ if a .itemsize in (1 , 2 , 4 , 8 ):
1568+ b = array .array (self .typecode , self .example )
1569+ b .byteswap ()
1570+ if a .itemsize == 1 :
1571+ self .assertEqual (a , b )
1572+ else :
1573+ # On alphas treating the byte swapped bit patterns as
1574+ # floats/doubles results in floating-point exceptions
1575+ # => compare the 8bit string values instead
1576+ self .assertNotEqual (a .tobytes (), b .tobytes ())
1577+ b .byteswap ()
1578+ self .assertEqual (a , b )
1579+
1580+
15281581class FloatTest (FPTest , unittest .TestCase ):
15291582 typecode = 'f'
15301583 minitemsize = 4
@@ -1551,6 +1604,15 @@ def test_alloc_overflow(self):
15511604 self .fail ("Array of size > maxsize created - MemoryError expected" )
15521605
15531606
1607+ class ComplexFloatTest (CFPTest , unittest .TestCase ):
1608+ typecode = 'F'
1609+ minitemsize = 8
1610+
1611+ class ComplexDoubleTest (CFPTest , unittest .TestCase ):
1612+ typecode = 'D'
1613+ minitemsize = 16
1614+
1615+
15541616class LargeArrayTest (unittest .TestCase ):
15551617 typecode = 'b'
15561618
0 commit comments