test_helper.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Created by Pearu Peterson, September 2002
  2. __usage__ = """
  3. Build fftpack:
  4. python setup_fftpack.py build
  5. Run tests if scipy is installed:
  6. python -c 'import scipy;scipy.fftpack.test(<level>)'
  7. Run tests if fftpack is not installed:
  8. python tests/test_helper.py [<level>]
  9. """
  10. from numpy.testing import assert_array_almost_equal
  11. from scipy.fftpack import fftshift, ifftshift, fftfreq, rfftfreq
  12. from numpy import pi, random
  13. class TestFFTShift:
  14. def test_definition(self):
  15. x = [0,1,2,3,4,-4,-3,-2,-1]
  16. y = [-4,-3,-2,-1,0,1,2,3,4]
  17. assert_array_almost_equal(fftshift(x),y)
  18. assert_array_almost_equal(ifftshift(y),x)
  19. x = [0,1,2,3,4,-5,-4,-3,-2,-1]
  20. y = [-5,-4,-3,-2,-1,0,1,2,3,4]
  21. assert_array_almost_equal(fftshift(x),y)
  22. assert_array_almost_equal(ifftshift(y),x)
  23. def test_inverse(self):
  24. for n in [1,4,9,100,211]:
  25. x = random.random((n,))
  26. assert_array_almost_equal(ifftshift(fftshift(x)),x)
  27. class TestFFTFreq:
  28. def test_definition(self):
  29. x = [0,1,2,3,4,-4,-3,-2,-1]
  30. assert_array_almost_equal(9*fftfreq(9),x)
  31. assert_array_almost_equal(9*pi*fftfreq(9,pi),x)
  32. x = [0,1,2,3,4,-5,-4,-3,-2,-1]
  33. assert_array_almost_equal(10*fftfreq(10),x)
  34. assert_array_almost_equal(10*pi*fftfreq(10,pi),x)
  35. class TestRFFTFreq:
  36. def test_definition(self):
  37. x = [0,1,1,2,2,3,3,4,4]
  38. assert_array_almost_equal(9*rfftfreq(9),x)
  39. assert_array_almost_equal(9*pi*rfftfreq(9,pi),x)
  40. x = [0,1,1,2,2,3,3,4,4,5]
  41. assert_array_almost_equal(10*rfftfreq(10),x)
  42. assert_array_almost_equal(10*pi*rfftfreq(10,pi),x)