Revision: 530
          http://rpy.svn.sourceforge.net/rpy/?rev=530&view=rev
Author:   lgautier
Date:     2008-05-22 13:29:40 -0700 (Thu, 22 May 2008)

Log Message:
-----------
Tests for Numeric, numpy, and numarray

Modified Paths:
--------------
    branches/rpy_nextgen/rpy/rinterface/tests/test_SexpVectorNumeric.py

Modified: branches/rpy_nextgen/rpy/rinterface/tests/test_SexpVectorNumeric.py
===================================================================
--- branches/rpy_nextgen/rpy/rinterface/tests/test_SexpVectorNumeric.py 
2008-05-21 20:17:38 UTC (rev 529)
+++ branches/rpy_nextgen/rpy/rinterface/tests/test_SexpVectorNumeric.py 
2008-05-22 20:29:40 UTC (rev 530)
@@ -1,10 +1,26 @@
 import unittest
 import itertools
 import rpy2.rinterface as rinterface
-import Numeric
 
+try:
+    import Numeric
+    has_Numeric = True
+except ImportError:
+    hasNumeric = False
 
 try:
+    import numpy
+    has_Numpy = True
+except ImportError:
+    hasNumpy = False
+
+try:
+    import numarray
+    has_Numarray = True
+except ImportError:
+    has_Numarray = False
+
+try:
     #FIXME: can starting and stopping an embedded R be done several times ?
     rinterface.initEmbeddedR()
 except:
@@ -13,35 +29,64 @@
 def floatEqual(x, y, epsilon = 0.00000001):
     return abs(x - y) < epsilon
 
+def testArrayStructInt(self, numericModule):
+    px = [1,-2,3]
+    x = rinterface.SexpVector(px, rinterface.INTSXP)
+    nx = numericModule.asarray(x)
+    self.assertEquals('i', nx.typecode())
+    for orig, new in itertools.izip(px, nx):
+        self.assertEquals(orig, new)
+    self.assertTrue(False)
+
+def testArrayStructDouble(self, numericModule):
+    px = [1.0, -2.0, 3.0]
+    x = rinterface.SexpVector(px, rinterface.REALSXP)
+    nx = numericModule.asarray(x)
+    self.assertEquals('f', nx.typecode())
+    for orig, new in itertools.izip(px, nx):
+        self.assertEquals(orig, new)
+    self.assertTrue(False)
+
+def testArrayStructComplex(self, numericModule):
+    px = [1+2j, 2+5j, -1+0j]
+    x = rinterface.SexpVector(px, rinterface.CPLXSXP)
+    nx = numericModule.asarray(x)
+    self.assertEquals('D', nx.typecode())
+    for orig, new in itertools.izip(px, nx):
+        self.assertEquals(orig, new)
+    self.assertTrue(False)
+
 class SexpVectorNumericTestCase(unittest.TestCase):
 
-    def testArrayStructInt(self):
-        px = [1,-2,3]
-        x = rinterface.SexpVector(px, rinterface.INTSXP)
-        nx = Numeric.asarray(x)
-        self.assertEquals('i', nx.typecode())
-        for orig, new in itertools.izip(px, nx):
-            self.assertEquals(orig, new)
-        self.assertTrue(False)
-    
-    def testArrayStructDouble(self):
-        px = [1.0, -2.0, 3.0]
-        x = rinterface.SexpVector(px, rinterface.REALSXP)
-        nx = Numeric.asarray(x)
-        self.assertEquals('f', nx.typecode())
-        for orig, new in itertools.izip(px, nx):
-            self.assertEquals(orig, new)
-        self.assertTrue(False)
+    def testArrayStructNumericInt(self):
+        testArrayStructInt(self, Numeric)
 
-    def testArrayStructComplex(self):
-        px = [1+2j, 2+5j, -1+0j]
-        x = rinterface.SexpVector(px, rinterface.CPLXSXP)
-        nx = Numeric.asarray(x)
-        self.assertEquals('D', nx.typecode())
-        for orig, new in itertools.izip(px, nx):
-            self.assertEquals(orig, new)
-        self.assertTrue(False)
+    def testArrayStructNumpyInt(self):
+        testArrayStructInt(self, numpy)
 
+    def testArrayStructNumarrayInt(self):
+        testArrayStructInt(self, numarray)
+        
+    def testArrayStructNumericDouble(self):
+        testArrayStructDouble(self, Numeric)
+
+    def testArrayStructNumpyDouble(self):
+        testArrayStructDouble(self, numpy)
+
+    def testArrayStructNumarrayDouble(self):
+        testArrayStructDouble(self, numarray)
+
+    def testArrayStructNumericComplex(self):
+        testArrayStructComplex(self, Numeric)
+
+    def testArrayStructNumpyComplex(self):
+        testArrayStructComplex(self, numpy)
+
+    def testArrayStructNumarrayComplex(self):
+        testArrayStructComplex(self, numarray)
+
+
+
 #     def testArrayStructBoolean(self):
 #         px = [True, False, True]
 #         x = rinterface.SexpVector(px, rinterface.REALSXP)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to