-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
111 lines (102 loc) · 2.48 KB
/
test.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const test = require( 'ava' );
const oneWise = require( '.' );
test( 'empty object returns an empty object in an array', t => {
const r = oneWise( {} );
t.deepEqual( r, [ {} ] );
} );
test( 'single property with two values returns one object for each value', t => {
const r = oneWise( {
"A": [ 1, 2 ]
} );
t.deepEqual( r, [
{ "A": 1 },
{ "A": 2 }
] );
} );
test( 'two properties, the second empty, returns only objects of the first property', t => {
const r = oneWise( {
"A": [ 1, 2 ],
"B": []
} );
t.deepEqual( r, [
{ "A": 1 },
{ "A": 2 }
] );
} );
test( 'two properties, the second empty, returns only objects of the first property, even being arrays', t => {
const r = oneWise( {
"A": [ [ 1 ], [ 2 ] ],
"B": []
} );
t.deepEqual( r, [
{ "A": [ 1 ] },
{ "A": [ 2 ] }
] );
} );
test( 'combination of 2 with lengths 2 and 1', t => {
const fakeRandom = () => 0.1;
const r = oneWise( {
"A": [ 1, 2 ],
"B": [ "x" ]
}, fakeRandom );
t.deepEqual( r, [
{ "A": 1, "B": "x" },
{ "A": 2, "B": "x" },
] );
} );
test( 'combination of 2 with lengths 2 and 3', t => {
const fakeRandom = () => 0.1;
const r = oneWise( {
"A": [ 1, 2 ],
"B": [ "x", "y", "z" ]
}, fakeRandom );
t.deepEqual( r, [
{ "A": 1, "B": "x" },
{ "A": 2, "B": "y" },
{ "A": 1, "B": "z" }
] );
} );
test( 'combination of 3 with lengths 2, 3, and 2', t => {
const fakeRandom = () => 0.1;
const r = oneWise(
{
"A": [ 1, 2 ],
"B": [ "x", "y", "z" ],
"C": [ "foo", "bar" ]
},
fakeRandom
);
t.deepEqual( r, [
{ "A": 1, "B": "x", "C": "foo" },
{ "A": 2, "B": "y", "C": "bar" },
{ "A": 1, "B": "z", "C": "foo" },
] );
} );
test( 'combination of 3 with lengths 4, 3, 2', t => {
const fakeRandom = () => 0.1;
const r = oneWise( {
"A": [ 1, 2, 3, 4 ],
"B": [ "x", "y", "z" ],
"C": [ "foo", "bar" ]
}, fakeRandom );
t.deepEqual( r, [
{ "A": 1, "B": "x", "C": "foo" },
{ "A": 2, "B": "y", "C": "bar" },
{ "A": 3, "B": "z", "C": "foo" },
{ "A": 4, "B": "x", "C": "foo" },
] );
} );
test( 'combination of 3 with lengths 4, 1, 0', t => {
const fakeRandom = () => 0.1;
const r = oneWise( {
"A": [ 1, 2, 3, 4 ],
"B": [ "x" ],
"C": []
}, fakeRandom );
t.deepEqual( r, [
{ "A": 1, "B": "x" },
{ "A": 2, "B": "x" },
{ "A": 3, "B": "x" },
{ "A": 4, "B": "x" },
] );
} );