mirror of
https://github.com/gpujs/gpu.js.git
synced 2025-12-08 20:35:56 +00:00
fix: implied else issue discovered, and fixed when testing boolean using leading and following return statements fix: Added a section in documentation about types and added reference to boolean fix: Bump and build
88 lines
1.8 KiB
JavaScript
88 lines
1.8 KiB
JavaScript
const { assert, skip, test, module: describe } = require('qunit');
|
|
const { GPU } = require('../../src');
|
|
|
|
describe('features: constants bool');
|
|
|
|
function boolTrueConstantTest(mode) {
|
|
const gpu = new GPU({ mode });
|
|
const bool = true;
|
|
const tryConst = gpu.createKernel(
|
|
function() {
|
|
return this.constants.bool ? 1 : 0;
|
|
},
|
|
{
|
|
constants: { bool },
|
|
output: [1]
|
|
},
|
|
);
|
|
const result = tryConst();
|
|
assert.equal(result[0], 1, 'bool constant passed test');
|
|
gpu.destroy();
|
|
}
|
|
|
|
test('true auto', () => {
|
|
boolTrueConstantTest(null);
|
|
});
|
|
|
|
test('true gpu', () => {
|
|
boolTrueConstantTest('gpu');
|
|
});
|
|
|
|
(GPU.isWebGLSupported ? test : skip)('true webgl', () => {
|
|
boolTrueConstantTest('webgl');
|
|
});
|
|
|
|
(GPU.isWebGL2Supported ? test : skip)('true webgl2', () => {
|
|
boolTrueConstantTest('webgl2');
|
|
});
|
|
|
|
(GPU.isHeadlessGLSupported ? test : skip)('true headlessgl', () => {
|
|
boolTrueConstantTest('headlessgl');
|
|
});
|
|
|
|
test('true cpu', () => {
|
|
boolTrueConstantTest('cpu');
|
|
});
|
|
|
|
|
|
function boolFalseConstantTest(mode) {
|
|
const gpu = new GPU({ mode });
|
|
const bool = false;
|
|
const tryConst = gpu.createKernel(
|
|
function() {
|
|
return this.constants.bool ? 1 : 0;
|
|
},
|
|
{
|
|
constants: { bool },
|
|
output: [1]
|
|
},
|
|
);
|
|
const result = tryConst();
|
|
assert.equal(result[0], 0, 'bool constant passed test');
|
|
gpu.destroy();
|
|
}
|
|
|
|
test('false auto', () => {
|
|
boolFalseConstantTest(null);
|
|
});
|
|
|
|
test('false gpu', () => {
|
|
boolFalseConstantTest('gpu');
|
|
});
|
|
|
|
(GPU.isWebGLSupported ? test : skip)('false webgl', () => {
|
|
boolFalseConstantTest('webgl');
|
|
});
|
|
|
|
(GPU.isWebGL2Supported ? test : skip)('false webgl2', () => {
|
|
boolFalseConstantTest('webgl2');
|
|
});
|
|
|
|
(GPU.isHeadlessGLSupported ? test : skip)('false headlessgl', () => {
|
|
boolFalseConstantTest('headlessgl');
|
|
});
|
|
|
|
test('false cpu', () => {
|
|
boolFalseConstantTest('cpu');
|
|
});
|