forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-builder.js
More file actions
75 lines (64 loc) · 2.23 KB
/
function-builder.js
File metadata and controls
75 lines (64 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
///
/// 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")
);
});