gpu.js/test/internal/function-builder.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
2.5 KiB
JavaScript

(function() {
///
/// Test the various basic functionality of functionBuilder
///
// Three layer template for multiple tests
function threeLayerTemplate() {
function layerOne() {
return 42;
}
function layerTwo() {
return layerOne() * 2;
}
function layerThree() {
return layerTwo() * 2;
}
// Create a function hello node
var builder = new GPU.WebGLFunctionBuilder();
builder.addFunction(null, layerOne);
builder.addFunction(null, layerTwo);
builder.addFunction(null, layerThree);
return builder;
}
/// Test the function tracing of 3 layers
QUnit.test( 'traceFunctionCalls: 3 layer test', function( assert ) {
assert.notEqual( GPU.WebGLFunctionBuilder, null, 'script include check' );
var builder = threeLayerTemplate();
assert.notEqual( builder, null, 'class creation check' );
assert.deepEqual( builder.traceFunctionCalls('layerOne'), ['layerOne'] );
assert.deepEqual( builder.traceFunctionCalls('layerTwo'), ['layerTwo','layerOne'] );
assert.deepEqual( builder.traceFunctionCalls('layerThree'), ['layerThree','layerTwo','layerOne'] );
});
/// Test the function tracing of 3 layers
QUnit.test( 'webglString: 3 layer test', function( assert ) {
assert.notEqual( GPU.WebGLFunctionBuilder, null, 'script include check' );
var builder = threeLayerTemplate();
assert.notEqual( builder, null, 'class creation check' );
assert.equal(
builder.getStringFromFunctionNames(['layerOne']),
'float layerOne() {\nreturn 42.0;\n}'
);
assert.equal(
builder.getString('layerOne'),
builder.getStringFromFunctionNames(['layerOne'])
);
assert.equal(
builder.getStringFromFunctionNames(['layerOne','layerTwo']),
'float layerOne() {\nreturn 42.0;\n}\nfloat layerTwo() {\nreturn (layerOne()*2.0);\n}'
);
assert.equal(
builder.getString('layerTwo'),
builder.getStringFromFunctionNames(['layerOne','layerTwo'])
);
assert.equal(
builder.getStringFromFunctionNames(['layerOne','layerTwo','layerThree']),
'float layerOne() {\nreturn 42.0;\n}\nfloat layerTwo() {\nreturn (layerOne()*2.0);\n}\nfloat layerThree() {\nreturn (layerTwo()*2.0);\n}'
);
assert.equal(
builder.getString('layerThree'),
builder.getStringFromFunctionNames(['layerOne','layerTwo','layerThree'])
);
assert.equal(
builder.getString(null),
builder.getString('layerThree')
);
});
})();