(nestingLvl = 2, maxItems = 5)
| 436 | } |
| 437 | |
| 438 | export 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 | |
| 459 | export function randomMutation<T>(o: T): void { |
| 460 | if (o == null || typeof o !== 'object') { |
no test coverage detected