@@ -174,14 +174,14 @@ test('internal buffer overwritten on repeated calls (view semantics)', () => {
174174
175175test ( 'fft: returns N/2+1 complex bins' , ( ) => {
176176 const N = 64
177- const { re, im } = fft ( new Float32Array ( N ) )
177+ const [ re , im ] = fft ( new Float32Array ( N ) )
178178 assert . equal ( re . length , N / 2 + 1 )
179179 assert . equal ( im . length , N / 2 + 1 )
180180} )
181181
182182test ( 'fft: DC signal → real-only X[0]=N' , ( ) => {
183183 const N = 64
184- const { re, im } = fft ( new Float32Array ( N ) . fill ( 1 ) )
184+ const [ re , im ] = fft ( new Float32Array ( N ) . fill ( 1 ) )
185185 assert ( Math . abs ( re [ 0 ] - N ) < EPSILON , `DC re: ${ re [ 0 ] } ` )
186186 assert ( Math . abs ( im [ 0 ] ) < EPSILON , `DC im: ${ im [ 0 ] } ` )
187187 for ( let k = 1 ; k <= N / 2 ; k ++ ) {
@@ -195,7 +195,7 @@ test('fft: cosine → real component X[k] = N/2', () => {
195195 for ( const k of [ 1 , 5 , 32 ] ) {
196196 const input = new Float32Array ( N )
197197 for ( let n = 0 ; n < N ; n ++ ) input [ n ] = Math . cos ( 2 * Math . PI * k * n / N )
198- const { re, im } = fft ( input )
198+ const [ re , im ] = fft ( input )
199199 assert ( Math . abs ( re [ k ] - N / 2 ) < EPSILON , `cos k=${ k } : re=${ re [ k ] } , expected ${ N / 2 } ` )
200200 assert ( Math . abs ( im [ k ] ) < EPSILON , `cos k=${ k } : im=${ im [ k ] } , expected 0` )
201201 }
@@ -206,7 +206,7 @@ test('fft: sine → imaginary component X[k] = -jN/2', () => {
206206 for ( const k of [ 1 , 5 , 63 ] ) {
207207 const input = new Float32Array ( N )
208208 for ( let n = 0 ; n < N ; n ++ ) input [ n ] = Math . sin ( 2 * Math . PI * k * n / N )
209- const { re, im } = fft ( input )
209+ const [ re , im ] = fft ( input )
210210 assert ( Math . abs ( re [ k ] ) < EPSILON , `sin k=${ k } : re=${ re [ k ] } , expected 0` )
211211 assert ( Math . abs ( im [ k ] - ( - N / 2 ) ) < EPSILON , `sin k=${ k } : im=${ im [ k ] } , expected ${ - N / 2 } ` )
212212 }
@@ -216,7 +216,7 @@ test('fft: DC and Nyquist always have zero imaginary', () => {
216216 for ( const N of [ 4 , 64 , 512 ] ) {
217217 const input = new Float32Array ( N )
218218 for ( let i = 0 ; i < N ; i ++ ) input [ i ] = Math . sin ( i * 1.7 ) + Math . cos ( i * 0.3 )
219- const { im } = fft ( input )
219+ const [ , im ] = fft ( input )
220220 assert . equal ( im [ 0 ] , 0 , `N=${ N } : DC im must be 0` )
221221 assert . equal ( im [ N / 2 ] , 0 , `N=${ N } : Nyquist im must be 0` )
222222 }
@@ -228,7 +228,7 @@ test('fft: magnitude matches rfft', () => {
228228 for ( let i = 0 ; i < N ; i ++ ) input [ i ] = Math . sin ( i * 0.7 ) + Math . cos ( i * 1.3 )
229229
230230 const mag = new Float64Array ( rfft ( input ) )
231- const { re, im } = fft ( input )
231+ const [ re , im ] = fft ( input )
232232
233233 const bSi = 2 / N
234234 assert ( Math . abs ( mag [ 0 ] - Math . abs ( bSi * re [ 0 ] ) ) < EPSILON , `DC mismatch` )
@@ -240,10 +240,10 @@ test('fft: magnitude matches rfft', () => {
240240
241241test ( 'fft: output buffer parameter' , ( ) => {
242242 const N = 64
243- const out = { re : new Float64Array ( N / 2 + 1 ) , im : new Float64Array ( N / 2 + 1 ) }
243+ const out = [ new Float64Array ( N / 2 + 1 ) , new Float64Array ( N / 2 + 1 ) ]
244244 const ret = fft ( new Float32Array ( N ) . fill ( 1 ) , out )
245245 assert . equal ( ret , out )
246- assert ( Math . abs ( out . re [ 0 ] - N ) < EPSILON )
246+ assert ( Math . abs ( out [ 0 ] [ 0 ] - N ) < EPSILON )
247247} )
248248
249249test ( 'fft: view overwritten on repeated calls' , ( ) => {
@@ -254,10 +254,10 @@ test('fft: view overwritten on repeated calls', () => {
254254 b [ i ] = Math . sin ( 2 * Math . PI * 10 * i / N )
255255 }
256256 const ra = fft ( a )
257- assert ( Math . abs ( ra . re [ 5 ] - N / 2 ) < EPSILON )
257+ assert ( Math . abs ( ra [ 0 ] [ 5 ] - N / 2 ) < EPSILON )
258258
259259 fft ( b ) // overwrites ra since same N
260260
261- assert ( Math . abs ( ra . re [ 5 ] ) < EPSILON , 'ra.re [5] should be overwritten' )
262- assert ( Math . abs ( ra . im [ 10 ] - ( - N / 2 ) ) < EPSILON , 'ra now reflects b' )
261+ assert ( Math . abs ( ra [ 0 ] [ 5 ] ) < EPSILON , 'ra[0] [5] should be overwritten' )
262+ assert ( Math . abs ( ra [ 1 ] [ 10 ] - ( - N / 2 ) ) < EPSILON , 'ra now reflects b' )
263263} )
0 commit comments