Skip to content

Commit 47bae6b

Browse files
fix: Add more unit tests for function return, covering Array(2), Array(3), and Array(4)
1 parent 0125e2c commit 47bae6b

File tree

1 file changed

+143
-18
lines changed

1 file changed

+143
-18
lines changed

test/features/function-return.js

Lines changed: 143 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,165 @@
1-
const { assert, skip, test, module: describe } = require('qunit');
1+
const { assert, skip, test, module: describe, only } = require('qunit');
22
const { GPU } = require('../../src');
33

4-
describe('function return');
4+
describe('features: function return');
55

6-
function functionReturn( mode ) {
6+
function functionReturnFloat( mode ) {
77
const gpu = new GPU({ mode });
88
const f = gpu.createKernel(function() {
9-
return 42.0;
9+
return 42;
1010
}, {
1111
output : [1]
1212
});
13-
assert.ok( f !== null, "function generated test");
14-
assert.equal(f()[0], 42.0, "basic return function test");
13+
assert.ok( f !== null, 'function generated test');
14+
assert.equal(f()[0], 42);
1515
gpu.destroy();
1616
}
1717

18-
test("auto", () => {
19-
functionReturn(null);
18+
test('float auto', () => {
19+
functionReturnFloat(null);
2020
});
2121

22-
test("gpu", () => {
23-
functionReturn("gpu");
22+
test('float gpu', () => {
23+
functionReturnFloat('gpu');
2424
});
2525

26-
(GPU.isWebGLSupported ? test : skip)("webgl", () => {
27-
functionReturn("webgl");
26+
(GPU.isWebGLSupported ? test : skip)('float webgl', () => {
27+
functionReturnFloat('webgl');
2828
});
2929

30-
(GPU.isWebGL2Supported ? test : skip)("webgl2", () => {
31-
functionReturn("webgl2");
30+
(GPU.isWebGL2Supported ? test : skip)('float webgl2', () => {
31+
functionReturnFloat('webgl2');
3232
});
3333

34-
(GPU.isHeadlessGLSupported ? test : skip)("headlessgl", () => {
35-
functionReturn("headlessgl");
34+
(GPU.isHeadlessGLSupported ? test : skip)('float headlessgl', () => {
35+
functionReturnFloat('headlessgl');
3636
});
3737

38-
test("cpu", () => {
39-
functionReturn("cpu");
38+
test('float cpu', () => {
39+
functionReturnFloat('cpu');
40+
});
41+
42+
43+
function functionReturnArray2( mode ) {
44+
const gpu = new GPU({ mode });
45+
const f = gpu.createKernel(function() {
46+
return [42, 43];
47+
}, {
48+
output : [1]
49+
});
50+
assert.ok( f !== null, 'function generated test');
51+
const result = f();
52+
// TODO, make assertion work
53+
// assert(result[0].constructor, Float32Array);
54+
assert.equal(result[0][0], 42);
55+
assert.equal(result[0][1], 43);
56+
gpu.destroy();
57+
}
58+
59+
test('Array(2) auto', () => {
60+
functionReturnArray2(null);
61+
});
62+
63+
test('Array(2) gpu', () => {
64+
functionReturnArray2('gpu');
65+
});
66+
67+
(GPU.isWebGLSupported ? test : skip)('Array(2) webgl', () => {
68+
functionReturnArray2('webgl');
69+
});
70+
71+
(GPU.isWebGL2Supported ? test : skip)('Array(2) webgl2', () => {
72+
functionReturnArray2('webgl2');
73+
});
74+
75+
(GPU.isHeadlessGLSupported ? test : skip)('Array(2) headlessgl', () => {
76+
functionReturnArray2('headlessgl');
77+
});
78+
79+
test('Array(2) cpu', () => {
80+
functionReturnArray2('cpu');
81+
});
82+
83+
function functionReturnArray3( mode ) {
84+
const gpu = new GPU({ mode });
85+
const f = gpu.createKernel(function() {
86+
return [42, 43, 44];
87+
}, {
88+
output : [1]
89+
});
90+
assert.ok( f !== null, 'function generated test');
91+
const result = f();
92+
// TODO, make assertion work
93+
// assert(result[0].constructor, Float32Array);
94+
assert.equal(result[0][0], 42);
95+
assert.equal(result[0][1], 43);
96+
assert.equal(result[0][2], 44);
97+
gpu.destroy();
98+
}
99+
100+
test('Array(3) auto', () => {
101+
functionReturnArray3(null);
102+
});
103+
104+
test('Array(3) gpu', () => {
105+
functionReturnArray3('gpu');
106+
});
107+
108+
(GPU.isWebGLSupported ? test : skip)('Array(3) webgl', () => {
109+
functionReturnArray3('webgl');
110+
});
111+
112+
(GPU.isWebGL2Supported ? test : skip)('Array(3) webgl2', () => {
113+
functionReturnArray3('webgl2');
114+
});
115+
116+
(GPU.isHeadlessGLSupported ? test : skip)('Array(3) headlessgl', () => {
117+
functionReturnArray3('headlessgl');
118+
});
119+
120+
test('Array(3) cpu', () => {
121+
functionReturnArray3('cpu');
122+
});
123+
124+
125+
function functionReturnArray4( mode ) {
126+
const gpu = new GPU({ mode });
127+
const f = gpu.createKernel(function() {
128+
return [42, 43, 44, 45];
129+
}, {
130+
output : [1]
131+
});
132+
assert.ok( f !== null, 'function generated test');
133+
const result = f();
134+
// TODO, make assertion work
135+
// assert(result[0].constructor, Float32Array);
136+
assert.equal(result[0][0], 42);
137+
assert.equal(result[0][1], 43);
138+
assert.equal(result[0][2], 44);
139+
assert.equal(result[0][3], 45);
140+
gpu.destroy();
141+
}
142+
143+
test('Array(4) auto', () => {
144+
functionReturnArray4(null);
145+
});
146+
147+
test('Array(4) gpu', () => {
148+
functionReturnArray4('gpu');
149+
});
150+
151+
(GPU.isWebGLSupported ? test : skip)('Array(4) webgl', () => {
152+
functionReturnArray4('webgl');
153+
});
154+
155+
(GPU.isWebGL2Supported ? test : skip)('Array(4) webgl2', () => {
156+
functionReturnArray4('webgl2');
157+
});
158+
159+
(GPU.isHeadlessGLSupported ? test : skip)('Array(4) headlessgl', () => {
160+
functionReturnArray4('headlessgl');
161+
});
162+
163+
test('Array(4) cpu', () => {
164+
functionReturnArray4('cpu');
40165
});

0 commit comments

Comments
 (0)