This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
68 lines (60 loc) · 1.67 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
67
68
var assert = require('assert');
var test = it;
var table = require('./');
var almost = require('almost-equal');
test('sin', function () {
var sin = table.sin(1024);
assert.equal(sin[0], 0);
assert.equal(sin[~~(1024/4)], 1);
assert(almost(sin[~~(1024/2)], 0, 0.0001, 0.0001));
});
test('cos', function () {
var cos = table.cos(4);
assert.equal(cos[0], 1);
assert(almost(cos[1], 0, 0.0001, 0.0001));
assert.equal(cos[2], -1);
assert(almost(cos[3], 0, 0.0001, 0.0001));
});
test('delta', function () {
var delta = table.delta(4);
assert.equal(delta[0], 1);
assert.equal(delta[1], 0);
assert.equal(delta[2], 0);
assert.equal(delta[3], 0);
});
test('pulse', function () {
var pulse = table.pulse(10, 0);
assert.equal(pulse[0], 1);
assert.equal(pulse[1], -1);
assert.equal(pulse[9], -1);
});
test('square', function () {
var square = table.square(10);
assert.equal(square[0], 1);
assert.equal(square[4], 1);
assert.equal(square[5], -1);
assert.equal(square[9], -1);
});
test('triangle', function () {
var triangle = table.triangle(8);
// console.log(triangle)
assert.equal(triangle[0], 0);
assert.equal(triangle[1], 0.5);
assert.equal(triangle[2], 1);
assert.equal(triangle[3], 0.5);
assert.equal(triangle[4], 0);
assert.equal(triangle[6], -1);
});
test('saw', function () {
var saw = table.saw(8);
assert.equal(saw[0], 1);
assert.equal(saw[7], -1);
});
test('pass table', function () {
var saw = table.saw(new Float64Array(120));
var sin = table.sin(new Float64Array(120));
var cos = table.cos(new Float64Array(120));
var triangle = table.triangle(new Float64Array(120));
var pulse = table.pulse(new Float64Array(120));
var noise = table.noise(new Float64Array(120));
});