Files
puter/tests/api-tester/lib/CoverageModel.js
Xiaochen Cui c93a53ead2 ci: init e2e test for browser env, tidy other tests (#1796)
* ci: init e2e test for browser env

stash changes

* test: update fsentry definition, add tests

stash changes

* test: pass puter-js mkdir test

* test: add test for puter-js move

* tidy code

* tidy code

* doc: add docs for playwright test

* recover memoryfs

* test: puter-js readdir/stat

* test: puter-js write

* test: puter-js read

* test: puter-js move_cart

* test: fix failed tests on move

* tests: rename files

* test: puter-js copy_cart

* tests: puter-js batch/delete, read config from file

* ci: add vitest

* ci: update names and timeout

* ci: simplify playwright-test

* ci: simplify api-test

* move "api-tester" from tools to tests

* test: update example config

* test: remove folder tests/api-tester/ci

* test: unify config location

* test: remove unused files

* ci: fix wrong config

* ci: fix wrong path

* test: add docs

* ci: update timeout, print artifact url
2025-10-28 16:35:37 -07:00

71 lines
1.7 KiB
JavaScript

const cartesianProduct = (obj) => {
// Get array of keys
let keys = Object.keys(obj);
// Generate the Cartesian Product
return keys.reduce((acc, key) => {
let appendArrays = Array.isArray(obj[key]) ? obj[key] : [obj[key]];
let newAcc = [];
acc.forEach(arr => {
appendArrays.forEach(item => {
newAcc.push([...arr, item]);
});
});
return newAcc;
}, [[]]); // start with the "empty product"
}
let obj = {
a: [1, 2],
b: ["a", "b"]
};
console.log(cartesianProduct(obj));
module.exports = class CoverageModel {
constructor (spec) {
const flat = {};
const flatten = (object, prefix) => {
for ( const k in object ) {
let targetKey = k;
if ( prefix ) {
targetKey = prefix + '.' + k;
}
let type = typeof object[k];
if ( Array.isArray(object[k]) ) type = 'array';
if ( type === 'object' ) {
flatten(object[k], targetKey);
continue;
}
if ( object[k].length == 0 ) {
object[k] = [false, true];
}
flat[targetKey] = object[k];
}
};
flatten(spec);
this.flat = flat;
const states = cartesianProduct(flat).map(
values => {
const o = {};
const keys = Object.keys(flat);
for ( let i=0 ; i < keys.length ; i++ ) {
o[keys[i]] = values[i];
}
return o;
}
);
this.states = states;
this.covered = Array(this.states.length).fill(false);
}
}