background image

Test involving Floating Point

def test_with_limited_precision( self ):

    self.

assertAlmostEqual

        2.33333333, average([1,2,4]), 

places=8

 )

Calculations using floating point values often result in  

rounding error

 or 

finite-precision error

.

This is normal.

To test a result which may have 

rounding error

, use

 

assertAlmostEqual

Comments:

Unit Testing in Python

navigate_before navigate_next