@wordpress/interactivity-router 2.25.0 → 2.26.1-next.719a03cbe.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +22 -0
- package/build/assets/dynamic-importmap/fetch.js +60 -0
- package/build/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build/assets/dynamic-importmap/index.js +91 -0
- package/build/assets/dynamic-importmap/index.js.map +1 -0
- package/build/assets/dynamic-importmap/loader.js +286 -0
- package/build/assets/dynamic-importmap/loader.js.map +1 -0
- package/build/assets/dynamic-importmap/resolver.js +220 -0
- package/build/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build/assets/script-modules.js +64 -0
- package/build/assets/script-modules.js.map +1 -0
- package/build/assets/scs.js +62 -0
- package/build/assets/scs.js.map +1 -0
- package/build/assets/styles.js +246 -0
- package/build/assets/styles.js.map +1 -0
- package/build/full-page.js +43 -0
- package/build/full-page.js.map +1 -0
- package/build/index.js +140 -38
- package/build/index.js.map +1 -1
- package/build-module/assets/dynamic-importmap/fetch.js +54 -0
- package/build-module/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build-module/assets/dynamic-importmap/index.js +72 -0
- package/build-module/assets/dynamic-importmap/index.js.map +1 -0
- package/build-module/assets/dynamic-importmap/loader.js +279 -0
- package/build-module/assets/dynamic-importmap/loader.js.map +1 -0
- package/build-module/assets/dynamic-importmap/resolver.js +213 -0
- package/build-module/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build-module/assets/script-modules.js +55 -0
- package/build-module/assets/script-modules.js.map +1 -0
- package/build-module/assets/scs.js +56 -0
- package/build-module/assets/scs.js.map +1 -0
- package/build-module/assets/styles.js +235 -0
- package/build-module/assets/styles.js.map +1 -0
- package/build-module/full-page.js +39 -0
- package/build-module/full-page.js.map +1 -0
- package/build-module/index.js +142 -38
- package/build-module/index.js.map +1 -1
- package/build-types/assets/dynamic-importmap/fetch.d.ts +30 -0
- package/build-types/assets/dynamic-importmap/fetch.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/index.d.ts +42 -0
- package/build-types/assets/dynamic-importmap/index.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts +68 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts +35 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts.map +1 -0
- package/build-types/assets/script-modules.d.ts +26 -0
- package/build-types/assets/script-modules.d.ts.map +1 -0
- package/build-types/assets/scs.d.ts +24 -0
- package/build-types/assets/scs.d.ts.map +1 -0
- package/build-types/assets/styles.d.ts +69 -0
- package/build-types/assets/styles.d.ts.map +1 -0
- package/build-types/full-page.d.ts +3 -0
- package/build-types/full-page.d.ts.map +1 -0
- package/build-types/index.d.ts +4 -5
- package/build-types/index.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/assets/dynamic-importmap/fetch.ts +58 -0
- package/src/assets/dynamic-importmap/index.ts +87 -0
- package/src/assets/dynamic-importmap/loader.ts +366 -0
- package/src/assets/dynamic-importmap/resolver.ts +292 -0
- package/src/assets/script-modules.ts +69 -0
- package/src/assets/scs.ts +61 -0
- package/src/assets/styles.ts +272 -0
- package/src/assets/test/scs.test.ts +367 -0
- package/src/assets/test/styles.test.ts +758 -0
- package/src/full-page.ts +47 -0
- package/src/index.ts +165 -45
- package/tsconfig.full-page.json +12 -0
- package/tsconfig.full-page.tsbuildinfo +1 -0
- package/tsconfig.json +9 -4
- package/tsconfig.main.json +21 -0
- package/tsconfig.main.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { shortestCommonSupersequence } from '../scs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the passed array is a contained sequence of the given
|
|
8
|
+
* supersequence.
|
|
9
|
+
*
|
|
10
|
+
* @param arr Array.
|
|
11
|
+
* @param superseq Supersequence.
|
|
12
|
+
* @param isEqual Optional comparator.
|
|
13
|
+
* @return True if the passed array is contained. False otherwise.
|
|
14
|
+
*/
|
|
15
|
+
function isSubsequence(
|
|
16
|
+
arr: unknown[],
|
|
17
|
+
superseq: unknown[],
|
|
18
|
+
isEqual = ( a: unknown, b: unknown ): boolean => a === b
|
|
19
|
+
) {
|
|
20
|
+
let i = 0;
|
|
21
|
+
let j = 0;
|
|
22
|
+
while ( i < arr.length && j < superseq.length ) {
|
|
23
|
+
if ( isEqual( arr[ i ], superseq[ j ] ) ) {
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
j++;
|
|
27
|
+
}
|
|
28
|
+
return i === arr.length;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe( 'shortestCommonSupersequence', () => {
|
|
32
|
+
describe( 'Basic functionality', () => {
|
|
33
|
+
it( 'should handle empty arrays', () => {
|
|
34
|
+
// Both arrays empty.
|
|
35
|
+
expect( shortestCommonSupersequence( [], [] ) ).toEqual( [] );
|
|
36
|
+
|
|
37
|
+
// X empty, Y with values.
|
|
38
|
+
const Y = [ 1, 2, 3 ];
|
|
39
|
+
expect( shortestCommonSupersequence( [], Y ) ).toEqual( Y );
|
|
40
|
+
|
|
41
|
+
// Y empty, X with values.
|
|
42
|
+
const X = [ 1, 2, 3 ];
|
|
43
|
+
expect( shortestCommonSupersequence( X, [] ) ).toEqual( X );
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
it( 'should handle identical arrays', () => {
|
|
47
|
+
// Same elements, same order.
|
|
48
|
+
const X = [ 1, 2, 3 ];
|
|
49
|
+
const Y = [ 1, 2, 3 ];
|
|
50
|
+
expect( shortestCommonSupersequence( X, Y ) ).toEqual( [
|
|
51
|
+
1, 2, 3,
|
|
52
|
+
] );
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
it( 'should handle simple cases with partial overlap', () => {
|
|
56
|
+
// Overlap at the beginning.
|
|
57
|
+
const result1 = shortestCommonSupersequence(
|
|
58
|
+
[ 1, 2, 3 ],
|
|
59
|
+
[ 1, 2, 4 ]
|
|
60
|
+
);
|
|
61
|
+
// Verify it's a valid supersequence.
|
|
62
|
+
expect( isSubsequence( [ 1, 2, 3 ], result1 ) ).toBe( true );
|
|
63
|
+
expect( isSubsequence( [ 1, 2, 4 ], result1 ) ).toBe( true );
|
|
64
|
+
// Verify optimal length.
|
|
65
|
+
expect( result1.length ).toBe( 4 );
|
|
66
|
+
|
|
67
|
+
// Overlap at the end.
|
|
68
|
+
const result2 = shortestCommonSupersequence(
|
|
69
|
+
[ 1, 2, 3 ],
|
|
70
|
+
[ 0, 2, 3 ]
|
|
71
|
+
);
|
|
72
|
+
// Verify it's a valid supersequence.
|
|
73
|
+
expect( isSubsequence( [ 1, 2, 3 ], result2 ) ).toBe( true );
|
|
74
|
+
expect( isSubsequence( [ 0, 2, 3 ], result2 ) ).toBe( true );
|
|
75
|
+
// Verify optimal length.
|
|
76
|
+
expect( result2.length ).toBe( 4 );
|
|
77
|
+
|
|
78
|
+
// Middle overlap.
|
|
79
|
+
const result3 = shortestCommonSupersequence(
|
|
80
|
+
[ 1, 2, 3 ],
|
|
81
|
+
[ 0, 2, 4 ]
|
|
82
|
+
);
|
|
83
|
+
// Verify it's a valid supersequence.
|
|
84
|
+
expect( isSubsequence( [ 1, 2, 3 ], result3 ) ).toBe( true );
|
|
85
|
+
expect( isSubsequence( [ 0, 2, 4 ], result3 ) ).toBe( true );
|
|
86
|
+
// Verify optimal length.
|
|
87
|
+
expect( result3.length ).toBe( 5 );
|
|
88
|
+
} );
|
|
89
|
+
|
|
90
|
+
it( 'should handle arrays with no overlap', () => {
|
|
91
|
+
const X = [ 1, 2, 3 ];
|
|
92
|
+
const Y = [ 4, 5, 6 ];
|
|
93
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
94
|
+
|
|
95
|
+
// Test that it's a valid supersequence of both arrays.
|
|
96
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
97
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
98
|
+
|
|
99
|
+
// Result length should be X.length + Y.length.
|
|
100
|
+
expect( result.length ).toBe( X.length + Y.length );
|
|
101
|
+
} );
|
|
102
|
+
|
|
103
|
+
it( 'should verify the supersequence length is optimal', () => {
|
|
104
|
+
// Example where the shortest supersequence is shorter than just concatenating.
|
|
105
|
+
const X = [ 1, 2, 3 ];
|
|
106
|
+
const Y = [ 2, 3, 4 ];
|
|
107
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
108
|
+
|
|
109
|
+
expect( result.length ).toBe( 4 );
|
|
110
|
+
expect( result ).toEqual( [ 1, 2, 3, 4 ] );
|
|
111
|
+
} );
|
|
112
|
+
} );
|
|
113
|
+
|
|
114
|
+
describe( 'Edge cases', () => {
|
|
115
|
+
it( 'should handle subsequence cases', () => {
|
|
116
|
+
// X is a subsequence of Y.
|
|
117
|
+
const X1 = [ 1, 3 ];
|
|
118
|
+
const Y1 = [ 1, 2, 3, 4 ];
|
|
119
|
+
expect( shortestCommonSupersequence( X1, Y1 ) ).toEqual( Y1 );
|
|
120
|
+
|
|
121
|
+
// Y is a subsequence of X.
|
|
122
|
+
const X2 = [ 1, 2, 3, 4 ];
|
|
123
|
+
const Y2 = [ 1, 3 ];
|
|
124
|
+
expect( shortestCommonSupersequence( X2, Y2 ) ).toEqual( X2 );
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
it( 'should handle arrays with duplicate elements', () => {
|
|
128
|
+
// Duplicates in X.
|
|
129
|
+
const resultX = shortestCommonSupersequence(
|
|
130
|
+
[ 1, 2, 2, 3 ],
|
|
131
|
+
[ 1, 3, 4 ]
|
|
132
|
+
);
|
|
133
|
+
expect( isSubsequence( [ 1, 2, 2, 3 ], resultX ) ).toBe( true );
|
|
134
|
+
expect( isSubsequence( [ 1, 3, 4 ], resultX ) ).toBe( true );
|
|
135
|
+
expect( resultX.length ).toBe( 5 );
|
|
136
|
+
|
|
137
|
+
// Duplicates in Y.
|
|
138
|
+
const resultY = shortestCommonSupersequence(
|
|
139
|
+
[ 1, 3, 4 ],
|
|
140
|
+
[ 1, 2, 2, 3 ]
|
|
141
|
+
);
|
|
142
|
+
expect( isSubsequence( [ 1, 3, 4 ], resultY ) ).toBe( true );
|
|
143
|
+
expect( isSubsequence( [ 1, 2, 2, 3 ], resultY ) ).toBe( true );
|
|
144
|
+
expect( resultY.length ).toBe( 5 );
|
|
145
|
+
|
|
146
|
+
// Duplicates in both X and Y.
|
|
147
|
+
const resultXY = shortestCommonSupersequence(
|
|
148
|
+
[ 1, 2, 2, 3 ],
|
|
149
|
+
[ 1, 2, 3, 3 ]
|
|
150
|
+
);
|
|
151
|
+
expect( isSubsequence( [ 1, 2, 2, 3 ], resultXY ) ).toBe( true );
|
|
152
|
+
expect( isSubsequence( [ 1, 2, 3, 3 ], resultXY ) ).toBe( true );
|
|
153
|
+
expect( resultXY.length ).toBe( 5 );
|
|
154
|
+
|
|
155
|
+
// Multiple duplicate occurrences.
|
|
156
|
+
const result = shortestCommonSupersequence(
|
|
157
|
+
[ 1, 2, 1, 2 ],
|
|
158
|
+
[ 2, 1, 2, 1 ]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect( isSubsequence( [ 1, 2, 1, 2 ], result ) ).toBe( true );
|
|
162
|
+
expect( isSubsequence( [ 2, 1, 2, 1 ], result ) ).toBe( true );
|
|
163
|
+
expect( result.length ).toBe( 5 );
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
it( 'should handle completely duplicate array', () => {
|
|
167
|
+
expect(
|
|
168
|
+
shortestCommonSupersequence( [ 1, 1, 1 ], [ 1, 1 ] )
|
|
169
|
+
).toEqual( [ 1, 1, 1 ] );
|
|
170
|
+
} );
|
|
171
|
+
|
|
172
|
+
it( 'should handle asymmetric cases with different array lengths', () => {
|
|
173
|
+
// X much longer than Y.
|
|
174
|
+
const X1 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
|
|
175
|
+
const Y1 = [ 2, 5 ];
|
|
176
|
+
const result1 = shortestCommonSupersequence( X1, Y1 );
|
|
177
|
+
|
|
178
|
+
// Result should be same as X since Y is a subsequence.
|
|
179
|
+
expect( result1 ).toEqual( X1 );
|
|
180
|
+
|
|
181
|
+
// Y much longer than X.
|
|
182
|
+
const X2 = [ 2, 5 ];
|
|
183
|
+
const Y2 = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ];
|
|
184
|
+
const result2 = shortestCommonSupersequence( X2, Y2 );
|
|
185
|
+
|
|
186
|
+
// Result should be same as Y since X is a subsequence.
|
|
187
|
+
expect( result2 ).toEqual( Y2 );
|
|
188
|
+
} );
|
|
189
|
+
} );
|
|
190
|
+
|
|
191
|
+
describe( 'Order preservation', () => {
|
|
192
|
+
it( 'should preserve order of elements from input arrays', () => {
|
|
193
|
+
const X = [ 1, 3, 5 ];
|
|
194
|
+
const Y = [ 5, 3, 1 ];
|
|
195
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
196
|
+
|
|
197
|
+
// Test that it's a valid supersequence of both arrays.
|
|
198
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
199
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
200
|
+
|
|
201
|
+
// Verify optimal length.
|
|
202
|
+
expect( result.length ).toBe( 5 );
|
|
203
|
+
|
|
204
|
+
// Test reverse case.
|
|
205
|
+
const result2 = shortestCommonSupersequence( Y, X );
|
|
206
|
+
expect( isSubsequence( X, result2 ) ).toBe( true );
|
|
207
|
+
expect( isSubsequence( Y, result2 ) ).toBe( true );
|
|
208
|
+
|
|
209
|
+
// Verify optimal length.
|
|
210
|
+
expect( result2.length ).toBe( 5 );
|
|
211
|
+
} );
|
|
212
|
+
|
|
213
|
+
it( 'should handle zigzag patterns correctly', () => {
|
|
214
|
+
const X = [ 1, 3, 5, 7, 9 ];
|
|
215
|
+
const Y = [ 2, 4, 6, 8, 10 ];
|
|
216
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
217
|
+
|
|
218
|
+
// Verify it's a valid supersequence.
|
|
219
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
220
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
221
|
+
|
|
222
|
+
// Verify optimal length (should be X.length + Y.length because no common elements).
|
|
223
|
+
expect( result.length ).toBe( 10 );
|
|
224
|
+
} );
|
|
225
|
+
} );
|
|
226
|
+
|
|
227
|
+
describe( 'Advanced cases', () => {
|
|
228
|
+
it( 'should handle complex interleavings', () => {
|
|
229
|
+
const X = [ 1, 2, 3, 1, 2, 3 ];
|
|
230
|
+
const Y = [ 3, 2, 1, 3, 2, 1 ];
|
|
231
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
232
|
+
|
|
233
|
+
// Result should be a valid supersequence.
|
|
234
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
235
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
236
|
+
|
|
237
|
+
// Verify optimal length.
|
|
238
|
+
expect( result.length ).toBe( 9 );
|
|
239
|
+
} );
|
|
240
|
+
|
|
241
|
+
it( 'should handle almost identical arrays with one difference', () => {
|
|
242
|
+
const X = [ 1, 2, 3, 4, 5 ];
|
|
243
|
+
const Y = [ 1, 2, 3, 5, 4 ];
|
|
244
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
245
|
+
|
|
246
|
+
// Result should contain 6 elements (optimal length).
|
|
247
|
+
expect( result.length ).toBe( 6 );
|
|
248
|
+
|
|
249
|
+
// The first 3 elements should be 1,2,3.
|
|
250
|
+
expect( result.slice( 0, 3 ) ).toEqual( [ 1, 2, 3 ] );
|
|
251
|
+
|
|
252
|
+
// Test that it's a valid supersequence of both arrays.
|
|
253
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
254
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
255
|
+
} );
|
|
256
|
+
|
|
257
|
+
it( 'should handle multiple matching possibilities optimally', () => {
|
|
258
|
+
const X = [ 1, 1, 2, 2 ];
|
|
259
|
+
const Y = [ 1, 2, 1, 2 ];
|
|
260
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
261
|
+
|
|
262
|
+
// Result should be a valid supersequence.
|
|
263
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
264
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
265
|
+
|
|
266
|
+
// Verify optimal length.
|
|
267
|
+
expect( result.length ).toBe( 5 );
|
|
268
|
+
} );
|
|
269
|
+
} );
|
|
270
|
+
|
|
271
|
+
describe( 'Custom equality function', () => {
|
|
272
|
+
it( 'should use custom equality function for comparing elements', () => {
|
|
273
|
+
const X = [
|
|
274
|
+
{ id: 1, name: 'a' },
|
|
275
|
+
{ id: 2, name: 'b' },
|
|
276
|
+
];
|
|
277
|
+
const Y = [
|
|
278
|
+
{ id: 1, name: 'c' },
|
|
279
|
+
{ id: 2, name: 'd' },
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
// Custom equality function that only compares 'id' property.
|
|
283
|
+
const isEqual = ( a, b ) => a.id === b.id;
|
|
284
|
+
|
|
285
|
+
const result = shortestCommonSupersequence( X, Y, isEqual );
|
|
286
|
+
|
|
287
|
+
// Should treat objects with same ids as equal.
|
|
288
|
+
expect( result.length ).toBe( 2 );
|
|
289
|
+
expect( result[ 0 ].id ).toBe( 1 );
|
|
290
|
+
expect( result[ 1 ].id ).toBe( 2 );
|
|
291
|
+
|
|
292
|
+
// Should use references from X.
|
|
293
|
+
expect( result[ 0 ] ).toBe( X[ 0 ] );
|
|
294
|
+
expect( result[ 1 ] ).toBe( X[ 1 ] );
|
|
295
|
+
|
|
296
|
+
// Test that it's a valid supersequence of both arrays.
|
|
297
|
+
expect( isSubsequence( X, result, isEqual ) ).toBe( true );
|
|
298
|
+
expect( isSubsequence( Y, result, isEqual ) ).toBe( true );
|
|
299
|
+
} );
|
|
300
|
+
|
|
301
|
+
it( 'should handle case-insensitive comparison', () => {
|
|
302
|
+
const X = [ 'A', 'B', 'C' ];
|
|
303
|
+
const Y = [ 'a', 'b', 'D' ];
|
|
304
|
+
|
|
305
|
+
// Case-insensitive comparison.
|
|
306
|
+
const isEqual = ( a, b ) => a.toLowerCase() === b.toLowerCase();
|
|
307
|
+
|
|
308
|
+
const result = shortestCommonSupersequence( X, Y, isEqual );
|
|
309
|
+
|
|
310
|
+
// Check references are from X when elements are considered equal.
|
|
311
|
+
expect( result[ 0 ] ).toBe( X[ 0 ] ); // 'A' instead of 'a'
|
|
312
|
+
expect( result[ 1 ] ).toBe( X[ 1 ] ); // 'B' instead of 'b'
|
|
313
|
+
|
|
314
|
+
// Verify it contains C and D (which don't match).
|
|
315
|
+
expect( result.includes( 'C' ) ).toBe( true );
|
|
316
|
+
expect( result.includes( 'D' ) ).toBe( true );
|
|
317
|
+
|
|
318
|
+
// Test that it's a valid supersequence of both arrays.
|
|
319
|
+
expect( isSubsequence( X, result, isEqual ) ).toBe( true );
|
|
320
|
+
expect( isSubsequence( Y, result, isEqual ) ).toBe( true );
|
|
321
|
+
|
|
322
|
+
// Check length is correct (4 instead of 6).
|
|
323
|
+
expect( result.length ).toBe( 4 );
|
|
324
|
+
} );
|
|
325
|
+
} );
|
|
326
|
+
|
|
327
|
+
describe( 'Null and undefined handling', () => {
|
|
328
|
+
it( 'should handle arrays with null values', () => {
|
|
329
|
+
const X = [ 1, null, 3 ];
|
|
330
|
+
const Y = [ null, 2, 3 ];
|
|
331
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
332
|
+
|
|
333
|
+
// Should treat null values correctly.
|
|
334
|
+
expect( result ).toEqual( [ 1, null, 2, 3 ] );
|
|
335
|
+
} );
|
|
336
|
+
|
|
337
|
+
it( 'should handle arrays with undefined', () => {
|
|
338
|
+
const X = [ 1, undefined, 3 ];
|
|
339
|
+
const Y = [ 2, undefined, 4 ];
|
|
340
|
+
const result = shortestCommonSupersequence( X, Y );
|
|
341
|
+
|
|
342
|
+
// Test that it's a valid supersequence of both arrays.
|
|
343
|
+
expect( isSubsequence( X, result ) ).toBe( true );
|
|
344
|
+
expect( isSubsequence( Y, result ) ).toBe( true );
|
|
345
|
+
|
|
346
|
+
// Length should be shorter than concatenating the arrays.
|
|
347
|
+
expect( result.length ).toBeLessThan( X.length + Y.length );
|
|
348
|
+
} );
|
|
349
|
+
} );
|
|
350
|
+
|
|
351
|
+
describe( 'Mutation checks', () => {
|
|
352
|
+
it( 'should not modify the input arrays', () => {
|
|
353
|
+
const X = [ 1, 2, 3 ];
|
|
354
|
+
const Y = [ 2, 3, 4 ];
|
|
355
|
+
|
|
356
|
+
// Create copies for comparison.
|
|
357
|
+
const originalX = [ ...X ];
|
|
358
|
+
const originalY = [ ...Y ];
|
|
359
|
+
|
|
360
|
+
shortestCommonSupersequence( X, Y );
|
|
361
|
+
|
|
362
|
+
// Input arrays should remain unchanged.
|
|
363
|
+
expect( X ).toEqual( originalX );
|
|
364
|
+
expect( Y ).toEqual( originalY );
|
|
365
|
+
} );
|
|
366
|
+
} );
|
|
367
|
+
} );
|