Skip to content
This repository
Browse code

This commit was manufactured by cvs2svn to create tag 'v0_3_0'.

  • Loading branch information...
commit ed1680d2a3e79777c0176e6884f73417f2793cfc 1 parent a2acd69
nobody authored

Showing 2 changed files with 0 additions and 297 deletions. Show diff stats Hide diff stats

  1. +0 253 Lib/tests/test_handy.py
  2. +0 44 Lib/tests/test_limits.py
253 Lib/tests/test_handy.py
... ... @@ -1,253 +0,0 @@
1   -""" Test functions for handy module
2   -
3   -"""
4   -
5   -import unittest
6   -import scipy.limits as limits
7   -from scipy_base.testing import assert_array_equal, assert_equal
8   -from scipy_base.testing import assert_almost_equal, assert_array_almost_equal
9   -from scipy import *
10   -
11   -##################################################
12   -
13   -class test_grid(unittest.TestCase):
14   - def check_basic(self):
15   - a = grid[-1:1:10j]
16   - b = grid[-1:1:0.1]
17   - assert(a.shape == (10,))
18   - assert(b.shape == (20,))
19   - assert(a[0] == -1)
20   - assert_almost_equal(a[-1],1)
21   - assert(b[0] == -1)
22   - assert_almost_equal(b[1]-b[0],0.1,11)
23   - assert_almost_equal(b[-1],b[0]+19*0.1,11)
24   - assert_almost_equal(a[1]-a[0],2.0/9.0,11)
25   -
26   - def check_nd(self):
27   - c = grid[-1:1:10j,-2:2:10j]
28   - d = grid[-1:1:0.1,-2:2:0.2]
29   - assert(c.shape == (2,10,10))
30   - assert(d.shape == (2,20,20))
31   - assert_array_equal(c[0][0,:],-ones(10,'d'))
32   - assert_array_equal(c[1][:,0],-2*ones(10,'d'))
33   - assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11)
34   - assert_array_almost_equal(c[1][:,-1],2*ones(10,'d'),11)
35   - assert_array_almost_equal(d[0,1,:]-d[0,0,:], 0.1*ones(20,'d'),11)
36   - assert_array_almost_equal(d[1,:,1]-d[1,:,0], 0.2*ones(20,'d'),11)
37   -
38   -class test_concatenator(unittest.TestCase):
39   - def check_1d(self):
40   - assert_array_equal(r_[1,2,3,4,5,6],array([1,2,3,4,5,6]))
41   - b = ones(5)
42   - c = r_[b,0,0,b]
43   - assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])
44   - c = c_[b,0,0,b]
45   - assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])
46   -
47   - def check_2d(self):
48   - b = rand(5,5)
49   - c = rand(5,5)
50   - d = c_[b,c] # append columns
51   - assert(d.shape == (5,10))
52   - assert_array_equal(d[:,:5],b)
53   - assert_array_equal(d[:,5:],c)
54   - d = r_[b,c]
55   - assert(d.shape == (10,5))
56   - assert_array_equal(d[:5,:],b)
57   - assert_array_equal(d[5:,:],c)
58   -
59   -class test_logspace(unittest.TestCase):
60   - def check_basic(self):
61   - y = logspace(0,6)
62   - assert(len(y)==50)
63   - y = logspace(0,6,num=100)
64   - assert(y[-1] == 10**6)
65   - y = logspace(0,6,endpoint=0)
66   - assert(y[-1] < 10**6)
67   - y = logspace(0,6,num=7)
68   - assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])
69   -
70   -class test_linspace(unittest.TestCase):
71   - def check_basic(self):
72   - y = linspace(0,10)
73   - assert(len(y)==50)
74   - y = linspace(2,10,num=100)
75   - assert(y[-1] == 10)
76   - y = linspace(2,10,endpoint=0)
77   - assert(y[-1] < 10)
78   - y,st = linspace(2,10,retstep=1)
79   - assert_almost_equal(st,8/49.0)
80   - assert_array_almost_equal(y,grid[2:10:50j],13)
81   -
82   -class test_any(unittest.TestCase):
83   - def check_basic(self):
84   - y1 = [0,0,1,0]
85   - y2 = [0,0,0,0]
86   - y3 = [1,0,1,0]
87   - assert(any(y1))
88   - assert(any(y3))
89   - assert(not any(y2))
90   -
91   - def check_nd(self):
92   - y1 = [[0,0,0],[0,1,0],[1,1,0]]
93   - assert_array_equal(any(y1),[1,1,0])
94   - assert_array_equal(any(y1,axis=1),[0,1,1])
95   -
96   -class test_all(unittest.TestCase):
97   - def check_basic(self):
98   - y1 = [0,1,1,0]
99   - y2 = [0,0,0,0]
100   - y3 = [1,1,1,1]
101   - assert(not all(y1))
102   - assert(all(y3))
103   - assert(not all(y2))
104   - assert(all(~array(y2)))
105   -
106   - def check_nd(self):
107   - y1 = [[0,0,1],[0,1,1],[1,1,1]]
108   - assert_array_equal(all(y1),[0,0,1])
109   - assert_array_equal(all(y1,axis=1),[0,0,1])
110   -
111   -class test_fix(unittest.TestCase):
112   - def check_basic(self):
113   - y1 = [-3.5,4.2,-0.0,0.0,5.5,-1.7]
114   - assert_array_almost_equal(fix(y1),[-3,4,0.0,0.0,5,-1.0],13)
115   -
116   -class test_fftshift(unittest.TestCase):
117   - def check_basic(self):
118   - y1 = grid[:10]
119   - y2 = grid[:11]
120   - y1s = fftshift(y1)
121   - y2s = fftshift(y2)
122   - assert_array_equal(y1s[:5],y1[5:])
123   - assert_array_equal(y1s[5:],y1[:5])
124   - assert_array_equal(y2s[:5],y2[6:])
125   - assert_array_equal(y2s[5:],y2[:6])
126   -
127   - def check_nd(self):
128   - y1 = grid[0:10,0:11,0:13][0]
129   - y1s = fftshift(y1,(0,2))
130   - assert_array_equal(y1s[0],5*ones((11,13),'d'))
131   - assert_array_equal(y1s[:,0,0],fftshift(grid[0:10]))
132   - assert_array_equal(y1,ifftshift(y1s,(0,2)))
133   -
134   -
135   -class test_ifftshift(unittest.TestCase):
136   - def check_basic(self):
137   - for k in range(5,11):
138   - y1 = rand(k)
139   - assert_array_equal(y1,ifftshift(fftshift(y1)))
140   -
141   - def check_nd(self):
142   - for k in range(5,11):
143   - y1 = rand(k-1,k,k+1)
144   - assert_array_equal(y1,ifftshift(fftshift(y1,(0,1)),(0,1)))
145   - assert_array_equal(y1,ifftshift(fftshift(y1,(1,2)),(1,2)))
146   -
147   -class test_fftfreq(unittest.TestCase):
148   - def check_basic(self):
149   - for k in range(4,11):
150   - y = fftfreq(k)*k
151   - lower = -(k/2)
152   - upper = (k-1)/2
153   - assert_array_equal(fftshift(y),grid[lower:upper+1])
154   -
155   -class test_cont_ft(unittest.TestCase):
156   - def check_basic(self):
157   - n = arange(100) - 49.5
158   - x = grid[-2:2:100j]
159   - dx = x[2] - x[1]
160   - gn = exp(-pi*x**2)
161   - fr = grid[-2:2:20j]
162   - actual = exp(-pi*fr**2)
163   - comp = cont_ft(gn,fr,delta=dx,n=n).real
164   - assert_array_almost_equal(comp,actual,6)
165   -
166   -class test_atleast_1d(unittest.TestCase):
167   - def check_basic(self):
168   - assert(atleast_1d(3).shape == (1,))
169   - assert(atleast_1d(3j).shape == (1,))
170   - assert(atleast_1d(3L).shape == (1,))
171   - assert(atleast_1d(3.0).shape == (1,))
172   - assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))
173   -
174   -class test_r2array(unittest.TestCase):
175   - def check_basic(self):
176   - assert(r2array(3).shape == (1,1))
177   - assert(r2array([3j,1]).shape == (1,2))
178   - assert(r2array([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))
179   -
180   -class test_isscalar(unittest.TestCase):
181   - def check_basic(self):
182   - assert(isscalar(3))
183   - assert(not isscalar([3]))
184   - assert(not isscalar((3,)))
185   - assert(isscalar(3j))
186   - assert(isscalar(10L))
187   - assert(isscalar(4.0))
188   -
189   -class test_toeplitz(unittest.TestCase):
190   - def check_basic(self):
191   - y = toeplitz([1,2,3])
192   - assert_array_equal(y,[[1,2,3],[2,1,2],[3,2,1]])
193   - y = toeplitz([1,2,3],[1,4,5])
194   - assert_array_equal(y,[[1,4,5],[2,1,4],[3,2,1]])
195   -
196   -class test_hankel(unittest.TestCase):
197   - def check_basic(self):
198   - y = hankel([1,2,3])
199   - assert_array_equal(y,[[1,2,3],[2,3,0],[3,0,0]])
200   - y = hankel([1,2,3],[3,4,5])
201   - assert_array_equal(y,[[1,2,3],[2,3,4],[3,4,5]])
202   -
203   -
204   -class test_real_if_close(unittest.TestCase):
205   - def check_basic(self):
206   - a = randn(10)
207   - b = real_if_close(a+1e-15j)
208   - assert(isrealobj(b))
209   - assert_array_equal(a,b)
210   - b = real_if_close(a+1e-7j)
211   - assert(iscomplexobj(b))
212   - b = real_if_close(a+1e-7j,tol=1e-6)
213   - assert(isrealobj(b))
214   -
215   -class test_polyint(unittest.TestCase):
216   - def check_order1_noconstant(self):
217   - a = rand(10)*4
218   -
219   -
220   -##################################################
221   -
222   -def test_suite(level=1):
223   - suites = []
224   - if level > 0:
225   - suites.append( unittest.makeSuite(test_grid,'check_') )
226   - suites.append( unittest.makeSuite(test_concatenator,'check_') )
227   - suites.append( unittest.makeSuite(test_logspace,'check_') )
228   - suites.append( unittest.makeSuite(test_linspace,'check_') )
229   - suites.append( unittest.makeSuite(test_any,'check_') )
230   - suites.append( unittest.makeSuite(test_all,'check_') )
231   - suites.append( unittest.makeSuite(test_fix,'check_') )
232   - suites.append( unittest.makeSuite(test_fftshift,'check_') )
233   - suites.append( unittest.makeSuite(test_ifftshift,'check_') )
234   - suites.append( unittest.makeSuite(test_fftfreq,'check_') )
235   - suites.append( unittest.makeSuite(test_cont_ft,'check_') )
236   - suites.append( unittest.makeSuite(test_atleast_1d,'check_') )
237   - suites.append( unittest.makeSuite(test_r2array,'check_') )
238   - suites.append( unittest.makeSuite(test_isscalar,'check_') )
239   - suites.append( unittest.makeSuite(test_toeplitz,'check_') )
240   - suites.append( unittest.makeSuite(test_hankel,'check_') )
241   - suites.append( unittest.makeSuite(test_real_if_close,'check_') )
242   - total_suite = unittest.TestSuite(suites)
243   - return total_suite
244   -
245   -def test(level=10):
246   - all_tests = test_suite(level)
247   - runner = unittest.TextTestRunner()
248   - runner.run(all_tests)
249   - return runner
250   -
251   -
252   -if __name__ == "__main__":
253   - test()
44 Lib/tests/test_limits.py
... ... @@ -1,44 +0,0 @@
1   -""" Test functions for limits module.
2   -
3   - Currently empty -- not sure how to test these values
4   - and routines as they are machine dependent. Suggestions?
5   -"""
6   -
7   -from scipy_base import *
8   -import unittest
9   -import scipy_base.limits
10   -
11   -
12   -
13   -##################################################
14   -### Test for sum
15   -
16   -class test_float(unittest.TestCase):
17   - def check_nothing(self):
18   - pass
19   -
20   -class test_double(unittest.TestCase):
21   - def check_nothing(self):
22   - pass
23   -
24   -##################################################
25   -
26   -
27   -def test_suite(level=1):
28   - suites = []
29   - if level > 0:
30   - suites.append( unittest.makeSuite(test_float,'check_') )
31   - suites.append( unittest.makeSuite(test_double,'check_') )
32   -
33   - total_suite = unittest.TestSuite(suites)
34   - return total_suite
35   -
36   -def test(level=10):
37   - all_tests = test_suite(level)
38   - runner = unittest.TextTestRunner()
39   - runner.run(all_tests)
40   - return runner
41   -
42   -
43   -if __name__ == "__main__":
44   - test()

0 comments on commit ed1680d

Please sign in to comment.
Something went wrong with that request. Please try again.