forked from applitools/Eyes.Selenium.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtils.js
More file actions
36 lines (31 loc) · 818 Bytes
/
TestUtils.js
File metadata and controls
36 lines (31 loc) · 818 Bytes
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
'use strict';
/**
* Collection of utility methods.
*/
class TestUtils {
/**
* Generates the cartesian product of the sets.
*
* @param {...(Array|Object)} sets - variable number of sets of n elements.
* @return {Generator} yields each product as an array
*/
static* cartesianProduct(...sets) {
const data = [];
function* cartesianUtil(index) {
if (index === sets.length) {
return yield data.slice();
}
if (!Array.isArray(sets[index])) {
data[index] = sets[index];
yield* cartesianUtil(index + 1);
} else {
for (let i = 0; i < sets[index].length; i += 1) {
data[index] = sets[index][i];
yield* cartesianUtil(index + 1);
}
}
}
yield* cartesianUtil(0);
}
}
exports.TestUtils = TestUtils;