/[thuban]/branches/WIP-pyshapelib-bramz/test/support.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/support.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1263 by jonathan, Fri Jun 20 14:15:43 2003 UTC revision 1397 by jonathan, Thu Jul 10 14:55:37 2003 UTC
# Line 172  class FloatComparisonMixin(unittest.Test Line 172  class FloatComparisonMixin(unittest.Test
172      fp_epsilon = 1e-6      fp_epsilon = 1e-6
173      fp_inf = float('1e1000')   # FIXME: hack for infinite      fp_inf = float('1e1000')   # FIXME: hack for infinite
174            
175      def assertFloatEqual(self, test, value):      def assertFloatEqual(self, test, value, epsilon = None):
176          """Assert equality of test and value with some tolerance.          """Assert equality of test and value with some tolerance.
177    
178          Assert that the absolute difference between test and value is          Assert that the absolute difference between test and value is
179          less than self.fp_epsilon.          less than self.fp_epsilon.
180          """          """
181            if epsilon is None:
182                epsilon = self.fp_epsilon
183          if abs(test) == self.fp_inf:          if abs(test) == self.fp_inf:
184              self.assertEqual(test, value)              self.assertEqual(test, value)
185          else:          else:
186              self.assert_(self.fp_epsilon > abs(test - value),              self.assert_(epsilon > abs(test - value),
187                       "abs(%g - %g) >= %g" % (test, value, self.fp_epsilon))                       "abs(%g - %g) >= %g" % (test, value, epsilon))
188    
189      def assertFloatSeqEqual(self, test, value, epsilon = None):      def assertFloatSeqEqual(self, test, value, epsilon = None):
190          """Assert equality of the sequences test and value with some tolerance.          """Assert equality of the sequences test and value with some tolerance.
# Line 191  class FloatComparisonMixin(unittest.Test Line 193  class FloatComparisonMixin(unittest.Test
193          value in test and value is less than the optional parameter          value in test and value is less than the optional parameter
194          epsilon. If epsilon is not given use self.fp_epsilon.          epsilon. If epsilon is not given use self.fp_epsilon.
195          """          """
         if epsilon is None:  
             epsilon = self.fp_epsilon  
196          for i in range(len(test)):          for i in range(len(test)):
197              self.assert_(epsilon > abs(test[i] - value[i]),              self.assertFloatEqual(test[i], value[i], epsilon)
                          "abs(%g - %g) >= %g" % (test[i], value[i], epsilon))  
   
198    
199  class SubscriberMixin:  class SubscriberMixin:
200    

Legend:
Removed from v.1263  
changed lines
  Added in v.1397

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26