Skip to content

Commit aa5eb96

Browse files
(Gsoc'21)➕ Added tests for listener3d.js, panner3d.js
1 parent 50c6fad commit aa5eb96

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

test/tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ import('./tests/p5.SoundFile.js');
2020
import('./tests/p5.Amplitude.js');
2121
import('./tests/p5.Oscillator.js');
2222
import('./tests/p5.Panner.js');
23+
import('./tests/p5.Panner3d.js');
24+
import('./tests/p5.Listener3d.js');

test/tests/p5.Listener3d.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const expect = chai.expect;
2+
3+
describe('p5.Listener3D', function () {
4+
let listener3d;
5+
it('can be created', function () {
6+
listener3d = new p5.Listener3D();
7+
console.log(listener3d);
8+
expect(listener3d).to.have.property('ac');
9+
expect(listener3d.listener).to.have.property('forwardX');
10+
expect(listener3d.listener).to.have.property('positionY');
11+
expect(listener3d.listener).to.have.property('upZ');
12+
});
13+
14+
it('can be connected to a source', function () {
15+
let gain = new p5.Gain();
16+
listener3d = new p5.Listener3D();
17+
listener3d.process(gain);
18+
});
19+
20+
describe('methods', function () {
21+
describe('position', function () {
22+
it('can set positionX, positionY, positionZ without a delay', function () {
23+
listener3d = new p5.Listener3D();
24+
expect(listener3d.positionX()).to.equal(0);
25+
expect(listener3d.positionX(-100)).to.equal(-100);
26+
expect(listener3d.positionY()).to.equal(0);
27+
expect(listener3d.positionY(300)).to.equal(300);
28+
expect(listener3d.positionZ()).to.equal(0);
29+
expect(listener3d.positionZ(200)).to.equal(200);
30+
});
31+
it('can set positionX, positionY, positionZ with a delay', function () {
32+
//TODO
33+
});
34+
it('can set positionX, positionY, positionZ using position function without a delay', function () {
35+
listener3d = new p5.Listener3D();
36+
expect(listener3d.position(10, 500, 100)).to.deep.equal([10, 500, 100]);
37+
expect(listener3d.positionX()).to.equal(10);
38+
expect(listener3d.positionY()).to.equal(500);
39+
expect(listener3d.positionZ()).to.equal(100);
40+
});
41+
it('can set positionX, positionY, positionZ using position function with a delay', function () {
42+
//TODO
43+
});
44+
});
45+
46+
describe('orientation forward', function () {
47+
it('can set forwardX, forwardY, forwardZ without a delay', function () {
48+
listener3d = new p5.Listener3D();
49+
expect(listener3d.forwardX()).to.equal(0);
50+
expect(listener3d.forwardX(400)).to.equal(400);
51+
expect(listener3d.forwardY()).to.equal(0);
52+
expect(listener3d.forwardY(700)).to.equal(700);
53+
expect(listener3d.forwardZ()).to.equal(-1);
54+
expect(listener3d.forwardZ(-800)).to.equal(-800);
55+
});
56+
it('can set forwardX, forwardY, forwardZ with a delay', function () {
57+
//TODO
58+
});
59+
it('can set forwardX, forwardY, forwardZ using orientForward function without a delay', function () {
60+
listener3d = new p5.Listener3D();
61+
listener3d.orientForward(-100, 100, 300);
62+
expect(listener3d.forwardX()).to.equal(-100);
63+
expect(listener3d.forwardY()).to.equal(100);
64+
expect(listener3d.forwardZ()).to.equal(300);
65+
});
66+
it('can set forwardX, forwardY, forwardZ using orientForward function without a delay', function () {
67+
//TODO
68+
});
69+
});
70+
71+
describe('orientation up', function () {
72+
it('can set upX, forwardY, upZ without a delay', function () {
73+
listener3d = new p5.Listener3D();
74+
expect(listener3d.upX()).to.equal(0);
75+
expect(listener3d.upX(900)).to.equal(900);
76+
expect(listener3d.upY()).to.equal(1);
77+
expect(listener3d.upY(250)).to.equal(250);
78+
expect(listener3d.upZ()).to.equal(0);
79+
expect(listener3d.upZ(-100)).to.equal(-100);
80+
});
81+
it('can set upX, forwardY, upZ with a delay', function () {
82+
//TODO
83+
});
84+
it('can set upX, forwardY, upZ using orientup function without a delay', function () {
85+
listener3d = new p5.Listener3D();
86+
listener3d.orientUp(-1000, 700, 300);
87+
expect(listener3d.upX()).to.equal(-1000);
88+
expect(listener3d.upY()).to.equal(700);
89+
expect(listener3d.upZ()).to.equal(300);
90+
});
91+
it('can set upX, forwardY, upZ using orientup function without a delay', function () {
92+
//TODO
93+
});
94+
});
95+
96+
describe('orientation', function () {
97+
it('can set forward orientations by passing 3 params to orient function (without delay) ', function () {
98+
listener3d = new p5.Listener3D();
99+
expect(listener3d.orient(450, -987, 123)).to.include(450, -987, 123);
100+
expect(listener3d.forwardX()).to.equal(450);
101+
expect(listener3d.forwardY()).to.equal(-987);
102+
expect(listener3d.forwardZ()).to.equal(123);
103+
});
104+
it('can set forward orientations by passing 4 params to orient function (with delay) ', function () {
105+
//TODO
106+
});
107+
it('can set all orientations using orient function without a delay', function () {
108+
listener3d = new p5.Listener3D();
109+
listener3d.orient(-300, -200, -100, 0, 100, 200);
110+
expect(listener3d.forwardX()).to.equal(-300);
111+
expect(listener3d.forwardY()).to.equal(-200);
112+
expect(listener3d.forwardZ()).to.equal(-100);
113+
expect(listener3d.upX()).to.equal(0);
114+
expect(listener3d.upY()).to.equal(100);
115+
expect(listener3d.upZ()).to.equal(200);
116+
});
117+
it('can set forwardX, forwardY, forwardZ using orientForward function without a delay', function () {
118+
//TODO
119+
});
120+
});
121+
});
122+
});

test/tests/p5.Panner3d.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const expect = chai.expect;
2+
3+
describe('p5.Panner3d', function () {
4+
it('can be created and disposed', function () {
5+
let panner3d = new p5.Panner3D();
6+
expect(panner3d).to.have.property('ac');
7+
expect(panner3d).to.have.property('input');
8+
expect(panner3d).to.have.property('output');
9+
expect(panner3d).to.have.property('panner');
10+
panner3d.dispose();
11+
expect(panner3d).to.have.property('ac');
12+
expect(panner3d).to.not.have.property('panner');
13+
});
14+
15+
it('can be connected to a source', function () {
16+
let gain = new p5.Gain();
17+
let panner3d = new p5.Panner3D();
18+
panner3d.connect(gain);
19+
});
20+
describe('methods', function () {
21+
describe('position', function () {
22+
it('can set positionX, positionY, positionZ without a delay', function () {
23+
let panner3d = new p5.Panner3D();
24+
expect(panner3d.positionX()).to.equal(0);
25+
expect(panner3d.positionX(100)).to.equal(100);
26+
expect(panner3d.positionY()).to.equal(0);
27+
expect(panner3d.positionY(-100)).to.equal(-100);
28+
expect(panner3d.positionZ()).to.equal(0);
29+
expect(panner3d.positionZ(200)).to.equal(200);
30+
});
31+
it('can set positionX, positionY, positionZ with a delay', function () {
32+
//TODO
33+
});
34+
it('can set positionX, positionY, positionZ using set function without a delay', function () {
35+
let panner3d = new p5.Panner3D();
36+
expect(panner3d.set(200, 300, -100)).to.deep.equal([200, 300, -100]);
37+
expect(panner3d.positionX()).to.equal(200);
38+
expect(panner3d.positionY()).to.equal(300);
39+
expect(panner3d.positionZ()).to.equal(-100);
40+
});
41+
it('can set positionX, positionY, positionZ using set function with a delay', function () {
42+
//TODO
43+
});
44+
});
45+
describe('orientation', function () {
46+
it('can set orientationX, orientationY, orientationZ without a delay', function () {
47+
let panner3d = new p5.Panner3D();
48+
expect(panner3d.orientX()).to.equal(1);
49+
expect(panner3d.orientX(100)).to.equal(100);
50+
expect(panner3d.orientY()).to.equal(0);
51+
expect(panner3d.orientY(-100)).to.equal(-100);
52+
expect(panner3d.orientZ()).to.equal(0);
53+
expect(panner3d.orientZ(200)).to.equal(200);
54+
});
55+
it('can set orientationX, orientationY, orientationZ with a delay', function () {
56+
//TODO
57+
});
58+
it('can set orientationX, orientationY, orientationZ using orient function without a delay', function () {
59+
let panner3d = new p5.Panner3D();
60+
61+
expect(panner3d.orient(200, 300, -100)).to.deep.equal([200, 300, -100]);
62+
expect(panner3d.orientX()).to.equal(200);
63+
expect(panner3d.orientY()).to.equal(300);
64+
expect(panner3d.orientZ()).to.equal(-100);
65+
});
66+
it('can set orientationX, orientationY, orientationZ using orient function with a delay', function () {
67+
//TODO
68+
});
69+
});
70+
it('can get and set rolloffFactor using rolloff', function () {
71+
let panner3d = new p5.Panner3D();
72+
expect(panner3d.rolloff()).to.equal(1);
73+
expect(panner3d.rolloff(0.4)).to.equal(0.4);
74+
expect(panner3d.panner.rolloffFactor).to.equal(0.4);
75+
});
76+
it('can get and set maxDistance using maxDist', function () {
77+
let panner3d = new p5.Panner3D();
78+
expect(panner3d.maxDist()).to.equal(10000);
79+
expect(panner3d.maxDist(5500)).to.equal(5500);
80+
expect(panner3d.panner.maxDistance).to.equal(5500);
81+
});
82+
it('can set maxDistance and rolloffFactor using setFalloff', function () {
83+
let panner3d = new p5.Panner3D();
84+
panner3d.setFalloff(4000, 0.6);
85+
expect(panner3d.maxDist()).to.equal(4000);
86+
expect(panner3d.rolloff()).to.equal(0.6);
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)