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 Gary S. Thompson on November 13, 2006 - 11:46:
Edward d'Auvergne wrote:

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.

The logic here was that we should use the in-built float function for anything other than special values as they will always be more rigourously tested than anything we produce ;-)

as to testing multiple nan patterns that is a good idea, and I was planning to add that at a later date. There is just a single nan pattern in float.py here so that we can create a constant...

I tried to keep the float.py module containing just the constants & functions which are used to check the contents of floats and to give values for the special floats inf, zero,and nan

I have another file which I haven't submitted to svn yet which contains utility functions and information about the float capabilites of a platform. However, it is extremley ropey in places....

It also has functions for printing floats as bit patterns of hex and binary ;-)

regards
gary

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


.



--
-------------------------------------------------------------------
Dr Gary Thompson
Astbury Centre for Structural Molecular Biology,
University of Leeds, Astbury Building,
Leeds, LS2 9JT, West-Yorkshire, UK             Tel. +44-113-3433024
email: garyt@xxxxxxxxxxxxxxx                   Fax  +44-113-2331407
-------------------------------------------------------------------





Related Messages


Powered by MHonArc, Updated Mon Nov 13 15:20:36 2006