MCPcopy Create free account
hub / github.com/activejs/activejs / randomClusterItems

Function randomClusterItems

packages/core/src/tests/utils.ts:438–457  ·  view source on GitHub ↗
(nestingLvl = 2, maxItems = 5)

Source from the content-addressed store, hash-verified

436}
437
438export function randomClusterItems(nestingLvl = 2, maxItems = 5): ClusterItems {
439 --nestingLvl;
440 const itemsKeys = randomKeys(maxItems, 1);
441 const itemsCtors = itemsKeys.map(() => selectRandom(ALL_CTORS));
442
443 return itemsKeys.reduce((reduced, key, index) => {
444 if (itemsCtors[index] === Cluster) {
445 if (nestingLvl >= 0) {
446 const nestedClusterItems = randomClusterItems(nestingLvl, maxItems);
447 reduced[key] = new itemsCtors[index](
448 // cluster needs at least one item, otherwise it throws error
449 Object.keys(nestedClusterItems).length ? nestedClusterItems : {unit: randomUnit()}
450 );
451 }
452 } else {
453 reduced[key] = new itemsCtors[index]();
454 }
455 return reduced;
456 }, {});
457}
458
459export function randomMutation<T>(o: T): void {
460 if (o == null || typeof o !== 'object') {

Callers 2

cluster.spec.tsFile · 0.90

Calls 3

randomKeysFunction · 0.85
selectRandomFunction · 0.85
randomUnitFunction · 0.85

Tested by

no test coverage detected