Skip to content

Commit

Permalink
add example to fromMatrix and extendMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 3, 2024
1 parent b745046 commit 19bdf28
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions testing/support/matrix-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ const appendTitle = (title: string, config: string, value: boolean | string | nu
return `${title}${title.length === 0 ? '' : '-'}${newTitle}`;
};

/**
* Create a matrix from a options
* @example
* const matrix = fromMatrix({ a: [true, false], b: [true, false] });
* // {
* // 'a(true)-b(true)': { a: true, b: true },
* // 'a(true)-b(false)': { a: true, b: false },
* // 'a(false)-b(true)': { a: false, b: true },
* // 'a(false)-b(false)': { a: false, b: false },
* // }
*/
export const fromMatrix = (configMatrix: Record<string, any[]>) => {
const configEntries = Object.entries(configMatrix);
const samples = configEntries.reduce(
Expand Down Expand Up @@ -67,6 +78,15 @@ const applyExtendedMatrix = (matrixEntries, configMatrix) => {
return matrixEntries;
};

/**
* Apply new matrix value to existing matrix
* @example
* const matrix = extendMatrix(fromMatrix({ initialMatrix: [true, false] }), { toBeMerged: [true, false] });
* // {
* // 'initialMatrix(true)-toBeMerged(true)': { initialMatrix: true, toBeMerged: true },
* // 'initialMatrix(false)-toBeMerged(false)': { initialMatrix: false, toBeMerged: false },
* // }
*/
export const extendMatrix = (matrix, configMatrix) => {
return Object.fromEntries(applyExtendedMatrix(Object.entries(matrix), configMatrix));
};
Expand Down

0 comments on commit 19bdf28

Please sign in to comment.