diff options
author | manojgudi | 2013-07-23 07:54:12 +0530 |
---|---|---|
committer | manojgudi | 2013-07-23 07:54:12 +0530 |
commit | 43114165fb5e59c4267991f4922970c897fe2d88 (patch) | |
tree | c4cd97ed682dd75c0efa8991243b04b13633e270 /tests | |
download | sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.tar.gz sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.tar.bz2 sciscipy-1.0.0-43114165fb5e59c4267991f4922970c897fe2d88.zip |
initial commit
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_call.py | 53 | ||||
-rw-r--r-- | tests/test_matrix.py | 71 | ||||
-rw-r--r-- | tests/test_read.py | 23 |
4 files changed, 147 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/test_call.py b/tests/test_call.py new file mode 100644 index 0000000..ef7df97 --- /dev/null +++ b/tests/test_call.py @@ -0,0 +1,53 @@ +import unittest +from scilab import Scilab +import sciscipy + +class test_call(unittest.TestCase): + def setUp(self): + self.sci = Scilab() + + def test_spec(self): + """ [test_call] Testing spec + """ + spec1 = self.sci.spec([[1, 2],[3, 4]]) + sciscipy.eval("spec1 = spec([1,2;3,4])") + spec2 = sciscipy.read("spec1") + for l1, l2 in zip(spec1, spec2): + self.assertAlmostEqual(l1, l2) + + def test_mean(self): + """ [test_call] Testing mean + """ + mean1 = self.sci.mean([[1, 2],[3, 4]]) + sciscipy.eval("mean1 = mean([1,2;3,4])") + mean2 = sciscipy.read("mean1") + comp = mean1 == mean2 + assert(comp) + + def test_strcat(self): + """ [test_call] Testing strcat + """ + strcat1 = self.sci.strcat(["1", "4"], "x") + sciscipy.eval("strcat1 = strcat(['1', '4'], 'x')") + strcat2 = sciscipy.read("strcat1") + comp = strcat1 == strcat2 + assert(comp) + + + def test_length(self): + """ [test_call] Testing length + """ + strlength1 = self.sci.length(["3ch","5char","plenty of char"]) + sciscipy.eval("strlength = length(['3ch','5char','plenty of char'])") + strlength2 = sciscipy.read("strlength") + for l1, l2 in zip(strlength1, strlength2): + self.assertEquals(l1, l2) + + + +if __name__ == '__main__': + unittest.main() + + + + diff --git a/tests/test_matrix.py b/tests/test_matrix.py new file mode 100644 index 0000000..4c5534c --- /dev/null +++ b/tests/test_matrix.py @@ -0,0 +1,71 @@ +import unittest +import sciscipy as sci + +try: + import numpy + numpy_is_avail = 1 +except ImportError: + numpy_is_avail = 0 + +class test_matrix(unittest.TestCase): + def setUp(self): + pass + + def test_readwrite1d(self): + sci.eval("x=rand(1, 100)") + sci.eval("my_sum=sum(x)") + x = sci.read("x") + my_sum = 0 + for i in range(len(x)): + my_sum += x[i] + + my_other_sum = sci.read("my_sum") + assert(my_other_sum[0] == my_sum) + + def test_readwrite1dT(self): + sci.eval("x=rand(100, 1)") + sci.eval("my_sum=sum(x)") + x = sci.read("x") + my_sum = 0 + for i in range(len(x)): + my_sum += x[i] + + my_other_sum = sci.read("my_sum") + assert(my_other_sum[0] == my_sum) + + def test_readwrite(self): + sci.eval("x=[1,2,3 ; 4,5,6]") + y = sci.read("x") + sci.write("z", y) + w = sci.read("z") + if numpy_is_avail: + assert(numpy.alltrue(numpy.equal(y, w))) + else: + assert(y == w) + + def test_bigmat(self): + sci.eval("x=rand(1000,800)") + y = sci.read("x") + sci.write("xx", y) + sci.eval("dist = sum((x - xx).^2)") + dist = sci.read("dist") + assert(dist[0] == 0) + + def test_complex(self): + sci.eval("x=[1+11*%i, 2+222*%i, 3+333*%i ; 4+444*%i , 5+55*%i, 6+66*%i]") + y = sci.read("x") + sci.write("z", y) + w = sci.read("z") + + if numpy_is_avail: + assert(numpy.alltrue(numpy.equal(y, w))) + else: + assert(y == w) + + +if __name__ == '__main__': + unittest.main() + + + + diff --git a/tests/test_read.py b/tests/test_read.py new file mode 100644 index 0000000..1a9b991 --- /dev/null +++ b/tests/test_read.py @@ -0,0 +1,23 @@ +import unittest
+from sciscipy import read, eval
+import numpy
+
+try:
+ import numpy
+ numpy_is_avail = 1
+except ImportError:
+ numpy_is_avail = 0
+
+class test_read(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def test_read_tlist(self):
+ eval("x=tlist(['test','a','b'],12,'item')")
+ x=read('x')
+ if numpy_is_avail:
+ num = numpy.array(12)
+ else:
+ num = 12
+ py_x = {'__tlist_name': 'test', 'a': num, 'b': ['item']}
+ assert x == py_x, str(py_x) + " != tlist(['test','a','b'],12,'item')"
\ No newline at end of file |