-
Notifications
You must be signed in to change notification settings - Fork 1
/
plan.test.js
145 lines (113 loc) · 2.05 KB
/
plan.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const test = require('ava');
const {permutation} = require('js-combinatorics');
const {plan} = require('./plan');
test('totally missing', t => {
const planA = plan([], 'a');
t.deepEqual(planA, undefined);
});
test('missing', t => {
const a = {
id: 'a',
interface: 'a',
dependencies: ['b']
};
const planA = plan([a], 'a');
t.deepEqual(planA, undefined);
});
test('missing circular', t => {
const a = {
id: 'a',
interface: 'a',
dependencies: ['a']
};
const planA = plan([a], 'a');
t.deepEqual(planA, undefined);
});
test('ok', t => {
const a = {
id: 'a',
interface: 'a',
dependencies: []
};
const planA = plan([a], 'a');
t.deepEqual(planA, a);
});
test('ok 2', t => {
const a = {
id: 'a',
interface: 'a',
dependencies: ['b']
};
const b = {
id: 'b',
interface: 'b',
dependencies: []
};
const planB = b;
const planA = {
id: 'a',
interface: 'a',
dependencies: [planB]
};
permutation([a, b]).forEach(p => {
const f = plan(p);
t.deepEqual(f('a'), planA);
t.deepEqual(f('b'), planB);
});
});
test('ok circular', t => {
const a = {
id: 'a',
interface: 'a',
dependencies: ['b']
};
const b1 = {
id: 'b1',
interface: 'b',
dependencies: ['b']
};
const b2 = {
id: 'b2',
interface: 'b',
dependencies: []
};
const planB2 = b2;
const planB1 = {
id: 'b1',
interface: 'b',
dependencies: [planB2]
};
const planA = {
id: 'a',
interface: 'a',
dependencies: [planB1]
};
permutation([a, b1, b2]).forEach(p => {
const f = plan(p);
t.deepEqual(f('a'), planA);
t.deepEqual(f('b'), planB1);
});
});
test('ok circular greedy', t => {
const a1 = {
id: 'a1',
interface: 'a',
dependencies: ['a']
};
const a2 = {
id: 'a2',
interface: 'a',
dependencies: ['a']
};
const a3 = {
id: 'a3',
interface: 'a',
dependencies: []
};
permutation([a1, a2, a3]).forEach(p => {
const planA = plan(p, 'a');
t.truthy(['a1', 'a2'].includes(planA.id));
t.truthy(['a1', 'a2'].includes(planA.dependencies[0].id));
t.deepEqual(planA.dependencies[0].dependencies[0], a3);
});
});