-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
68 lines (53 loc) · 1.31 KB
/
test.js
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
'use strict'
var wfunc = require('./')
var applyWindow = require('./apply')
var generateWindow = require('./generate')
var t = require('tape')
var windows = [
'rectangular',
'triangular',
'bartlett',
'welch',
'hann',
'hamming',
'blackman',
'exactBlackman',
'nuttall',
'blackmanNuttall',
'blackmanHarris',
'flatTop',
'bartlettHann',
'cosine',
'lanczos'
]
t('window functions return a finite number',function(t) {
var i
for(i=0; i<windows.length; i++) {
(function(j) {
t.ok( isFinite(wfunc[windows[j]](50,101)), windows[j] )
})(i)
}
t.ok( isFinite(wfunc.gaussian(50,100,0.4)), 'gaussian (alpha = 0.4)')
t.ok( isFinite(wfunc.tukey(50,100,0.4)), 'tukey (alpha = 0.5)')
t.end()
})
t('applies a window to a signal',function(t) {
var x = [1, 1, 1, 1, 1]
var y = applyWindow( x, wfunc.hamming )
t.equal(y.length, x.length)
t.end()
})
t('passes extra arguments to a window function',function(t) {
var x = [1, 1, 1, 1, 1]
applyWindow( x, wfunc.gaussian, 0.1 )
t.ok( isFinite(x[0]), 'samples are finite' )
t.ok( x[0] < 1e-8, 'samples have been windowed' )
t.end()
})
t('constructs an window function array',function(t) {
var x = generateWindow( wfunc.hamming, 100 )
t.ok( Array.isArray(x) )
t.equal( x.length, 100 )
t.ok( isFinite(x[50]) )
t.end()
})