1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
From: Youhei SASAKI <uwabami@gfd-dennou.org>
Date: Tue, 15 Oct 2013 17:00:05 +0900
Subject: RefactTestCases
---
test/complexFFT.rb | 71 +++++++++++++++++++++++++++---------------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/test/complexFFT.rb b/test/complexFFT.rb
index e92f64e..39ae57e 100644
--- a/test/complexFFT.rb
+++ b/test/complexFFT.rb
@@ -1,38 +1,39 @@
+require "test/unit"
+require "narray"
require "numru/fftw3"
include NumRu
-print "\n**TEST** all dimensions\n\n"
-
-na = NArray.float(8,4).fill(1) # will be corced to complex
-na[1,1]=5
-p na
-fc = FFTW3.fft(na, -1)/na.length
-p fc
-p fc.real
-
-p FFTW3.fft(fc, 1).real
-
-print "\n**TEST** single float (treated as single if lib fftw3f exits)\n"
-print " --- see http://www.fftw.org/fftw3_doc/Precision.html for more info\n\n"
-na = NArray.sfloat(8,4).indgen!
-fc = FFTW3.fft(na, -1)/na.length
-p fc
-p FFTW3.fft(fc, 1).real
-
-print "\n**TEST** dimension selection\n\n"
-
-fc = FFTW3.fft(na, -1, 0)/na.shape[0]
-p fc
-p FFTW3.fft(fc, 1, 0).real
-fc = FFTW3.fft(na, -1, 1)/na.shape[1]
-p fc
-p FFTW3.fft(fc, 1, 1).real
-
-na = NArray.float(4,3,8,3)
-na[1,1,1,0]= 1
-p( fc=FFTW3.fft(na, -1, 0,2) / (na.shape[0]*na.shape[2]) )
-p( fc=FFTW3.fft(na, -1, 1) / na.shape[1] )
-p( fc=FFTW3.fft(na, -1, 0,1,2) / (na.shape[0]*na.shape[1]*na.shape[2]) )
-p FFTW3.fft(fc, 1, 0,1,2).real
-
-
+class ComplexTest < Test::Unit::TestCase
+
+ def setup
+ @na_double = NArray.float(8,4).fill(1.0)
+ @na_single = NArray.sfloat(8,4).indgen!
+ @na_complex = NArray.float(4,3,8,3)
+ @na_complex[1,1,1,0] = 1.0
+ @sfloat_delta = 5.0e-5
+ @float_delta = 1.0e-13
+ end
+
+ define_method("test_double_float") do
+ fc_double = FFTW3.fft(@na_double, -1)/@na_double.length
+ assert_in_delta @na_double, FFTW3.fft(fc_double, 1).real, @float_delta
+ end
+
+ define_method("test_single_float") do
+ fc_single = FFTW3.fft(@na_single, -1)/@na_single.length
+ assert_in_delta @na_single, FFTW3.fft(fc_single, 1).real, @sfloat_delta
+ end
+
+ define_method("test_dimenssion_selection") do
+ fc_double = FFTW3.fft(@na_double, -1, 0)/@na_double.shape[0]
+ assert_in_delta @na_double, FFTW3.fft(fc_double, 1, 0).real, @float_delta
+ fc_single = FFTW3.fft(@na_single, -1, 0)/@na_single.shape[0]
+ assert_in_delta @na_single, FFTW3.fft(fc_single, 1, 0).real, @sfloat_delta
+ end
+
+ define_method("test_complex") do
+ fc_complex = FFTW3.fft(@na_complex, -1, 0, 1, 2)/(@na_complex.shape[0]*@na_complex.shape[1]*@na_complex.shape[2])
+ assert_in_delta @na_complex, FFTW3.fft(fc_complex, 1, 0, 1, 2).real, @float_delta
+ end
+
+end
|