1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17   
 18   
 19   
 20   
 21   
 22   
 23   
 24  from unittest import TestCase 
 25  from copy import copy 
 26   
 27   
 28  from lib.float import CLASS_POS_DENORMAL, CLASS_POS_INF, CLASS_POS_NORMAL, CLASS_POS_ZERO, CLASS_NEG_DENORMAL, CLASS_NEG_INF, CLASS_NEG_NORMAL, CLASS_NEG_ZERO, CLASS_QUIET_NAN, getFloatClass, isPositive, isZero, nan, neg_inf, packBytesAsPyFloat, pos_inf 
 29   
 30   
 31   
 32  FLOAT_EPSILON = packBytesAsPyFloat([1, 0, 0, 0, 0, 0, 0, 0]) 
 33  NEG_FLOAT_EPSILON = packBytesAsPyFloat([1, 0, 0, 0, 0, 0, 0, 128]) 
 34  FLOAT_NORMAL = packBytesAsPyFloat([0, 0, 0, 0, 128, 132, 46, 65]) 
 35  NEG_FLOAT_NORMAL = packBytesAsPyFloat([0, 0, 0, 0, 128, 132, 46, 193]) 
 36  ZERO = packBytesAsPyFloat([0, 0, 0, 0, 0, 0, 0, 0]) 
 37  NEG_ZERO = packBytesAsPyFloat([0, 0, 0, 0, 0, 0, 0, 128]) 
 38   
 39   
 41      """Convert the list into a dictionary of pointer:value pairs.""" 
 42   
 43       
 44      result = {} 
 45      for element in elements: 
 46          result[id(element)] = element 
 47   
 48       
 49      return result 
  50   
 51   
 53      """Generate a list of values in dict excluding the values given.""" 
 54   
 55       
 56      resultDict = copy(dict) 
 57      for val in exclude: 
 58          del(resultDict[id(val)]) 
 59   
 60       
 61      return list(resultDict.values()) 
  62   
 63   
 65      """Unit tests for the functions of the 'float' module.""" 
 66   
 67       
 68      num_types = make_dict_by_id([pos_inf, neg_inf, FLOAT_NORMAL, NEG_FLOAT_NORMAL, FLOAT_EPSILON, NEG_FLOAT_EPSILON, nan, ZERO, NEG_ZERO]) 
 69   
 70 -    def do_test_sets(self, function, true_class=[], false_class=[]): 
  71          """Method for checking all the values against the given function.""" 
 72   
 73           
 74          for val in true_class: 
 75              self.assertEqual(function(val), True) 
 76   
 77           
 78          for val in false_class: 
 79              self.assertEqual(function(val), False) 
  80   
 81   
 83          """Test the float.getFloatClass() function.""" 
 84   
 85          tests = (CLASS_POS_INF,        pos_inf, 
 86                   CLASS_NEG_INF,        neg_inf, 
 87                   CLASS_POS_NORMAL,     FLOAT_NORMAL, 
 88                   CLASS_NEG_NORMAL,     -FLOAT_NORMAL, 
 89                   CLASS_POS_DENORMAL,   FLOAT_EPSILON, 
 90                   CLASS_NEG_DENORMAL,   -FLOAT_EPSILON, 
 91                   CLASS_QUIET_NAN,      nan, 
 92                    
 93                   CLASS_POS_ZERO,       ZERO, 
 94                   CLASS_NEG_ZERO,       -ZERO 
 95          ) 
 96   
 97          i = iter(tests) 
 98          for (fpClass, value) in zip(i, i): 
 99              self.assertEqual(fpClass, getFloatClass(value)) 
 100   
101   
113   
114   
 126