gpu.js/test/features/if-else.js
Robert Plummer b2df0ab604 fix #316
Change `HTMLImageArray` render strategy to `gl.NEAREST`, like all the others
Let `WebGL2FunctionNode` extend `WebGLFunctionNode` and lighten
Remove all the different html pages associated with tests, and just use one file to handle them and use qunit for filtering them
Bump version number
2018-06-12 14:07:41 -04:00

78 lines
1.6 KiB
JavaScript

(function() {
function booleanBranch(mode) {
var gpu = new GPU({
mode: mode
});
var f = gpu.createKernel(function() {
var result = 0.0;
if(true) {
result = 4.0;
} else {
result = 2.0;
}
return result;
}, {
output : [1]
});
QUnit.assert.ok( f !== null, 'function generated test');
QUnit.assert.close(f()[0], 4, 0.01, 'basic return function test');
}
QUnit.test( 'booleanBranch (auto)', function() {
booleanBranch(null);
});
QUnit.test( 'booleanBranch (gpu)', function() {
booleanBranch('gpu');
});
QUnit.test( 'booleanBranch (webgl)', function() {
booleanBranch('webgl');
});
QUnit.test( 'booleanBranch (webgl2)', function() {
booleanBranch('webgl2');
});
QUnit.test( 'booleanBranch (CPU)', function() {
booleanBranch('cpu');
});
function ifElse( mode ) {
var gpu = new GPU({ mode });
var f = gpu.createKernel(function(x) {
if (x[this.thread.x] > 0) {
return 0;
} else {
return 1;
}
}, {
output : [4]
});
QUnit.assert.ok( f !== null, 'function generated test');
QUnit.assert.deepEqual(QUnit.extend([], f([1, 1, 0, 0])), [0, 0, 1, 1], 'basic return function test');
}
QUnit.test( 'ifElse (auto)', function() {
ifElse(null);
});
QUnit.test( 'ifElse (gpu)', function() {
ifElse('gpu');
});
QUnit.test( 'ifElse (webgl)', function() {
ifElse('webgl');
});
QUnit.test( 'ifElse (webgl2)', function() {
ifElse('webgl2');
});
QUnit.test( 'ifElse (cpu)', function() {
ifElse('cpu');
});
})();