Back to index

python3.2  3.2.2
Public Member Functions
test.test_float.ReprTestCase Class Reference

List of all members.

Public Member Functions

def test_repr
def test_short_repr

Detailed Description

Definition at line 593 of file test_float.py.


Member Function Documentation

Definition at line 594 of file test_float.py.

00594 
00595     def test_repr(self):
00596         floats_file = open(os.path.join(os.path.split(__file__)[0],
00597                            'floating_points.txt'))
00598         for line in floats_file:
00599             line = line.strip()
00600             if not line or line.startswith('#'):
00601                 continue
00602             v = eval(line)
00603             self.assertEqual(v, eval(repr(v)))
00604         floats_file.close()

Here is the call graph for this function:

Definition at line 607 of file test_float.py.

00607 
00608     def test_short_repr(self):
00609         # test short float repr introduced in Python 3.1.  One aspect
00610         # of this repr is that we get some degree of str -> float ->
00611         # str roundtripping.  In particular, for any numeric string
00612         # containing 15 or fewer significant digits, those exact same
00613         # digits (modulo trailing zeros) should appear in the output.
00614         # No more repr(0.03) -> "0.029999999999999999"!
00615 
00616         test_strings = [
00617             # output always includes *either* a decimal point and at
00618             # least one digit after that point, or an exponent.
00619             '0.0',
00620             '1.0',
00621             '0.01',
00622             '0.02',
00623             '0.03',
00624             '0.04',
00625             '0.05',
00626             '1.23456789',
00627             '10.0',
00628             '100.0',
00629             # values >= 1e16 get an exponent...
00630             '1000000000000000.0',
00631             '9999999999999990.0',
00632             '1e+16',
00633             '1e+17',
00634             # ... and so do values < 1e-4
00635             '0.001',
00636             '0.001001',
00637             '0.00010000000000001',
00638             '0.0001',
00639             '9.999999999999e-05',
00640             '1e-05',
00641             # values designed to provoke failure if the FPU rounding
00642             # precision isn't set correctly
00643             '8.72293771110361e+25',
00644             '7.47005307342313e+26',
00645             '2.86438000439698e+28',
00646             '8.89142905246179e+28',
00647             '3.08578087079232e+35',
00648             ]
00649 
00650         for s in test_strings:
00651             negs = '-'+s
00652             self.assertEqual(s, repr(float(s)))
00653             self.assertEqual(negs, repr(float(negs)))
00654             # Since Python 3.2, repr and str are identical
00655             self.assertEqual(repr(float(s)), str(float(s)))
00656             self.assertEqual(repr(float(negs)), str(float(negs)))
00657 
@support.requires_IEEE_754

Here is the call graph for this function:


The documentation for this class was generated from the following file: