-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsuite.mjs
46 lines (46 loc) · 1.49 KB
/
testsuite.mjs
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
export class BaseTestSuite {
constructor(config) {
Object.assign(this, config);
// depending on what's in config, instantiate:
// primitive, processResults, plots, summarize
// each are a class
// params
// is an object
if ("plots" in config) {
/** this complexity is to make sure that a plot
* that uses a template literal has it evaluated
* in the context of this test suite. By default,
* it's lexically scoped, which is useless. call()
* makes sure it's evaluated in this class's context.
*/
function f(plot, env) {
if (typeof plot === "function") {
return plot.call(env);
} else {
// presumably a plain object
return plot;
}
}
// TODO: i do not understand why 'map' does not work
this.processedPlots = [];
for (let plot of this.plots) {
this.processedPlots.push(f(plot, this));
}
}
}
getPrimitive(deviceAndParams) {
// factory
// arg to primitive is a single object, so what's below combines device and params
// we also need to add any primitive-specific configuration info, specified in this.primitiveConfig
const primitive = new this.primitive({
...deviceAndParams,
...this.primitiveConfig,
});
/* original design: copy all string fields from TestSuite -> Primitive */
/* no longer do this -- unnecessary complexity */
return primitive;
}
getPlots() {
return this.processedPlots;
}
}