mailRe: r2777 - /branches/test_suite/test_suite/unit_tests/test_float.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on November 11, 2006 - 05:59:
Gary, in these tests you have been using the 'float()' function for
creating numbers.  Would it be better to create a large number of
IEEE-754 bit patterns (as strings) covering all number types (and
possibly multiple +/- NaNs with different bits in the mantissa) and
then convert these to 64 bit floats taking endianness into account?
This should be more portable than using the 'float()' function and
give us much better control of the floats.

Cheers,

Edward



On 11/9/06, garyt@xxxxxxxxxxxxxxx <garyt@xxxxxxxxxxxxxxx> wrote:
Author: varioustoxins
Date: Wed Nov  8 23:39:23 2006
New Revision: 2777

URL: http://svn.gna.org/viewcvs/relax?rev=2777&view=rev
Log:
Added tests for isZero & isPositive & id based dicts and subset removal


Modified: branches/test_suite/test_suite/unit_tests/test_float.py

Modified: branches/test_suite/test_suite/unit_tests/test_float.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/test_suite/test_suite/unit_tests/test_float.py?rev=2777&r1=2776&r2=2777&view=diff
==============================================================================
--- branches/test_suite/test_suite/unit_tests/test_float.py (original)
+++ branches/test_suite/test_suite/unit_tests/test_float.py Wed Nov  8 
23:39:23 2006
@@ -2,24 +2,76 @@

 import unittest
 from float  import *
+from copy import copy
+
 FLOAT_EPSILON=float(4.94065645841247e-324) # replace a a later date
+FLOAT_NORMAL = float(1e6)
+ZERO = float(+0.0)
+NEG_ZERO = -ZERO
+NEG_FLOAT_EPSILON = -FLOAT_EPSILON
+NEG_FLOAT_NORMAL =  -FLOAT_NORMAL
+
+def makeDictById(elements):
+    result ={}
+    for element in elements:
+        result[id(element)]=element
+
+    return result
+
+def winnowDictToListById(dict,elements):
+    resultDict = copy(dict)
+
+    for element in elements:
+        del(resultDict[id(element)])
+
+    return resultDict.values()

 class Test_float(unittest.TestCase):
-    def test_GetFloatClass(self):
+
+    tests = makeDictById([pos_inf, neg_inf, FLOAT_NORMAL,
+                          NEG_FLOAT_NORMAL, FLOAT_EPSILON,
+                          NEG_FLOAT_EPSILON, nan, ZERO, NEG_ZERO])
+
+
+    def test_getFloatClass(self):
+
         tests = ( CLASS_POS_INF, pos_inf,
                   CLASS_NEG_INF, neg_inf,
-                  CLASS_POS_NORMAL, float(1e6),
-                  CLASS_NEG_NORMAL, -float(1e6),
+                  CLASS_POS_NORMAL, FLOAT_NORMAL,
+                  CLASS_NEG_NORMAL, -FLOAT_NORMAL,
                   CLASS_POS_DENORMAL,  FLOAT_EPSILON,
                   CLASS_NEG_DENORMAL,  -FLOAT_EPSILON,
                   CLASS_QUIET_NAN,     nan,
                   # WE DON'T USE SIGNAL NANS CLASS_SIGNAL_NAN,
-                  CLASS_POS_ZERO,    float(0),
-                  CLASS_NEG_ZERO,    -float(0))
+                  CLASS_POS_ZERO,    ZERO,
+                  CLASS_NEG_ZERO,    -ZERO)

         i=iter(tests)
         for (fpClass, value) in zip(i,i):
             self.assertEqual(fpClass, getFloatClass(value))
+
+    def test_isZero(self):
+        positives = (ZERO,NEG_ZERO)
+        negatives= winnowDictToListById(self.tests,positives)
+
+        self.doTestSets(isZero,positives=positives, negatives=negatives)
+
+
+    def test_isPositive(self):
+        negatives = (neg_inf, NEG_FLOAT_NORMAL,NEG_FLOAT_EPSILON, NEG_ZERO)
+        positives= winnowDictToListById(self.tests,negatives)
+
+        self.doTestSets(isPositive,positives=positives, negatives=negatives)
+
+    #todo add reporting of failed number class...
+    def doTestSets(self,function,positives=[],negatives=[]):
+        for positive in positives:
+            self.assertEqual(function(positive),True)
+
+        for negative in negatives:
+            self.assertEqual(function(negative),False)
+
+


if __name__ == '__main__':


_______________________________________________ relax (http://nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits




Related Messages


Powered by MHonArc, Updated Mon Nov 13 12:01:45 2006