-
Notifications
You must be signed in to change notification settings - Fork 24
/
test.js
47 lines (42 loc) · 1.95 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
var assert = require('assert'),
fft = require('../').fft;
describe('FFT (Cooley-Tukey)', function () {
describe('1,0,1,0', function () {
it('Should properly compute [1,0,1,0]', function () {
var coef = fft([1,0,1,0]);
assert(equalWithThresh(coef[0][0], 2, 0.01));
assert(equalWithThresh(coef[0][1], 0, 0.01));
assert(equalWithThresh(coef[1][0], 0, 0.01));
assert(equalWithThresh(coef[1][1], 0, 0.01));
assert(equalWithThresh(coef[2][0], 2, 0.01));
assert(equalWithThresh(coef[2][1], 0, 0.01));
assert(equalWithThresh(coef[3][0], 0, 0.01));
assert(equalWithThresh(coef[3][1], 0, 0.01));
});
});
describe('1,0,1,0,2,0,2,0', function () {
it('Should properly compute [1,0,1,0,2,0,2,0]', function () {
var coef = fft([1,0,1,0,2,0,2,0]);
assert(equalWithThresh(coef[0][0], 6, 0.01));
assert(equalWithThresh(coef[0][1], 0, 0.01));
assert(equalWithThresh(coef[1][0], -1, 0.01));
assert(equalWithThresh(coef[1][1], 1, 0.01));
assert(equalWithThresh(coef[2][0], 0, 0.01));
assert(equalWithThresh(coef[2][1], 0, 0.01));
assert(equalWithThresh(coef[3][0], -1, 0.01));
assert(equalWithThresh(coef[3][1], -1, 0.01));
assert(equalWithThresh(coef[4][0], 6, 0.01));
assert(equalWithThresh(coef[4][1], 0, 0.01));
assert(equalWithThresh(coef[5][0], -1, 0.01));
assert(equalWithThresh(coef[5][1], 1, 0.01));
assert(equalWithThresh(coef[6][0], 0, 0.01));
assert(equalWithThresh(coef[6][1], 0, 0.01));
assert(equalWithThresh(coef[7][0], -1, 0.01));
assert(equalWithThresh(coef[7][1], -1, 0.01));
});
});
});
function equalWithThresh(val1, val2, threshold) {
return (val1 > val2 - threshold) &&
(val1 < val2 + threshold);
}