@bitbybit-dev/base 0.19.7 → 0.19.8

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.
Files changed (61) hide show
  1. package/babel.config.cjs +0 -1
  2. package/{index.js → index.ts} +2 -1
  3. package/lib/api/inputs/base-inputs.ts +18 -0
  4. package/lib/api/inputs/{color-inputs.d.ts → color-inputs.ts} +48 -26
  5. package/lib/api/inputs/{lists-inputs.d.ts → lists-inputs.ts} +190 -91
  6. package/lib/api/inputs/{logic-inputs.d.ts → logic-inputs.ts} +46 -24
  7. package/lib/api/inputs/{math-inputs.d.ts → math-inputs.ts} +97 -53
  8. package/lib/api/inputs/{point-inputs.d.ts → point-inputs.ts} +168 -77
  9. package/lib/api/inputs/text-inputs.ts +108 -0
  10. package/lib/api/inputs/{transforms-inputs.d.ts → transforms-inputs.ts} +64 -35
  11. package/lib/api/inputs/{vector-inputs.d.ts → vector-inputs.ts} +104 -48
  12. package/lib/api/services/color.test.ts +86 -0
  13. package/lib/api/services/{color.js → color.ts} +34 -15
  14. package/lib/api/services/{geometry-helper.js → geometry-helper.ts} +43 -31
  15. package/lib/api/services/{index.d.ts → index.ts} +1 -1
  16. package/lib/api/services/lists.test.ts +612 -0
  17. package/lib/api/services/{lists.js → lists.ts} +83 -59
  18. package/lib/api/services/logic.test.ts +187 -0
  19. package/lib/api/services/{logic.js → logic.ts} +32 -24
  20. package/lib/api/services/math.test.ts +622 -0
  21. package/lib/api/services/{math.js → math.ts} +136 -71
  22. package/lib/api/services/{point.js → point.ts} +67 -32
  23. package/lib/api/services/text.test.ts +55 -0
  24. package/lib/api/services/{text.js → text.ts} +17 -7
  25. package/lib/api/services/{transforms.js → transforms.ts} +83 -37
  26. package/lib/api/services/vector.test.ts +360 -0
  27. package/lib/api/services/{vector.js → vector.ts} +80 -42
  28. package/lib/{index.d.ts → index.ts} +1 -0
  29. package/package.json +1 -1
  30. package/tsconfig.bitbybit.json +26 -0
  31. package/tsconfig.json +24 -0
  32. package/babel.config.d.cts +0 -5
  33. package/index.d.ts +0 -1
  34. package/lib/api/index.js +0 -1
  35. package/lib/api/inputs/base-inputs.d.ts +0 -35
  36. package/lib/api/inputs/base-inputs.js +0 -1
  37. package/lib/api/inputs/color-inputs.js +0 -164
  38. package/lib/api/inputs/index.js +0 -9
  39. package/lib/api/inputs/inputs.js +0 -9
  40. package/lib/api/inputs/lists-inputs.js +0 -576
  41. package/lib/api/inputs/logic-inputs.js +0 -111
  42. package/lib/api/inputs/math-inputs.js +0 -391
  43. package/lib/api/inputs/point-inputs.js +0 -521
  44. package/lib/api/inputs/text-inputs.d.ts +0 -83
  45. package/lib/api/inputs/text-inputs.js +0 -120
  46. package/lib/api/inputs/transforms-inputs.js +0 -200
  47. package/lib/api/inputs/vector-inputs.js +0 -304
  48. package/lib/api/services/color.d.ts +0 -114
  49. package/lib/api/services/geometry-helper.d.ts +0 -15
  50. package/lib/api/services/index.js +0 -9
  51. package/lib/api/services/lists.d.ts +0 -287
  52. package/lib/api/services/logic.d.ts +0 -99
  53. package/lib/api/services/math.d.ts +0 -349
  54. package/lib/api/services/point.d.ts +0 -222
  55. package/lib/api/services/text.d.ts +0 -69
  56. package/lib/api/services/transforms.d.ts +0 -122
  57. package/lib/api/services/vector.d.ts +0 -320
  58. package/lib/index.js +0 -1
  59. /package/lib/api/{index.d.ts → index.ts} +0 -0
  60. /package/lib/api/inputs/{index.d.ts → index.ts} +0 -0
  61. /package/lib/api/inputs/{inputs.d.ts → inputs.ts} +0 -0
@@ -0,0 +1,612 @@
1
+ import { Lists } from "./lists";
2
+ import * as Inputs from "../inputs";
3
+
4
+ describe("Lists unit tests", () => {
5
+ let lists: Lists;
6
+
7
+ beforeEach(() => {
8
+ lists = new Lists();
9
+ });
10
+
11
+ it("should get item from the list", () => {
12
+ const result = lists.getItem({ list: [0, 1, 2], index: 1 });
13
+ expect(result).toEqual(1);
14
+ });
15
+
16
+ it("should get item from the list and clone it", () => {
17
+ const result = lists.getItem({ list: [0, 1, 2], index: 1, clone: true });
18
+ expect(result).toEqual(1);
19
+ });
20
+
21
+ it("should get random items with threshold", () => {
22
+ const result = lists.randomGetThreshold({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], threshold: 0.5, clone: false });
23
+ expect(result.length).toBeGreaterThanOrEqual(0);
24
+ });
25
+
26
+ it("should get random items with threshold and clone", () => {
27
+ const result = lists.randomGetThreshold({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], threshold: 0.5, clone: true });
28
+ expect(result.length).toBeGreaterThanOrEqual(0);
29
+ });
30
+
31
+ it("should random remove items with threshold", () => {
32
+ const result = lists.randomRemoveThreshold({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], threshold: 0.5, clone: false });
33
+ expect(result.length).toBeGreaterThanOrEqual(0);
34
+ });
35
+
36
+ it("should random remove items with threshold and clone", () => {
37
+ const result = lists.randomRemoveThreshold({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], threshold: 0.5, clone: true });
38
+ expect(result.length).toBeGreaterThanOrEqual(0);
39
+ });
40
+
41
+ it("should get a sub list", () => {
42
+ const result = lists.getSubList({ list: [0, 1, 2, 3, 4], indexStart: 1, indexEnd: 3 });
43
+ expect(result).toEqual([1, 2]);
44
+ });
45
+
46
+ it("should get a sub list and clone", () => {
47
+ const result = lists.getSubList({ list: [0, 1, 2, 3, 4], indexStart: 1, indexEnd: 3, clone: true });
48
+ expect(result).toEqual([1, 2]);
49
+ });
50
+
51
+ it("should get a sub list with negative indexes", () => {
52
+ const result = lists.getSubList({ list: [0, 1, 2, 3, 4], indexStart: -3, indexEnd: -1 });
53
+ expect(result).toEqual([2, 3]);
54
+ });
55
+
56
+ it("should get out of bound error when getting item from the list", () => {
57
+ expect(() => lists.getItem({ list: [0, 1, 2], index: 3 })).toThrowError("Index out of bounds");
58
+ });
59
+
60
+ it("should get sublist from the list", () => {
61
+ const result = lists.getSubList({ list: [0, 1, 2, 3, 4], indexStart: 1, indexEnd: 3 });
62
+ expect(result).toEqual([1, 2]);
63
+ });
64
+
65
+ it("should get nth item from the list", () => {
66
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 0 });
67
+ expect(result).toEqual([0, 2, 4]);
68
+ });
69
+
70
+ it("should get nth item from the list with offset 1", () => {
71
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 1 });
72
+ expect(result).toEqual([1, 3]);
73
+ });
74
+
75
+ it("should get nth item from the list with offset 2", () => {
76
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 2 });
77
+ expect(result).toEqual([0, 2, 4]);
78
+ });
79
+
80
+ it("should get nth item from the list when nth is 3", () => {
81
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 3, offset: 0 });
82
+ expect(result).toEqual([0, 3, 6, 9]);
83
+ });
84
+
85
+ it("should get nth item from the list when nth is 3 and clone", () => {
86
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 3, offset: 0, clone: true });
87
+ expect(result).toEqual([0, 3, 6, 9]);
88
+ });
89
+
90
+ it("should get all items from the list when nth is 1", () => {
91
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 1, offset: 0 });
92
+ expect(result).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
93
+ });
94
+
95
+ it("should get no items from the list when nth is 0", () => {
96
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 0, offset: 0 });
97
+ expect(result).toEqual([]);
98
+ });
99
+
100
+ it("should get all items from the list when nth is -1", () => {
101
+ const result = lists.getNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: -1, offset: 0 });
102
+ expect(result).toEqual([
103
+ 0, 1, 2, 3, 4,
104
+ 5, 6, 7, 8, 9,
105
+ 10
106
+ ]);
107
+ });
108
+
109
+
110
+ it("should remove nth item from the list", () => {
111
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 2 });
112
+ expect(result).toEqual([1, 3]);
113
+ });
114
+
115
+ it("should remove nth item from the list with offset 1", () => {
116
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 1 });
117
+ expect(result).toEqual([0, 2, 4]);
118
+ });
119
+
120
+ it("should remove nth item from the list with offset 1 and clone", () => {
121
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 1, clone: true });
122
+ expect(result).toEqual([0, 2, 4]);
123
+ });
124
+
125
+ it("should remove nth item from the list with offset 2", () => {
126
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4], nth: 2, offset: 2 });
127
+ expect(result).toEqual([1, 3]);
128
+ });
129
+
130
+ it("should remove nth item from the list when nth is 3", () => {
131
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 3, offset: 0 });
132
+ expect(result).toEqual([1, 2, 4, 5, 7, 8, 10]);
133
+ });
134
+
135
+ it("should remove nth item from the list when nth is 3 with 1 offset", () => {
136
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 3, offset: 1 });
137
+ expect(result).toEqual([0, 1, 3, 4,
138
+ 6, 7, 9, 10]);
139
+ });
140
+
141
+ it("should remove all items from the list when nth is 1", () => {
142
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 1, offset: 0 });
143
+ expect(result).toEqual([]);
144
+ });
145
+
146
+ it("should remove no items from the list when nth is 0", () => {
147
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: 0, offset: 0 });
148
+ expect(result).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
149
+ });
150
+
151
+ it("should remove all items from the list when nth is -1", () => {
152
+ const result = lists.removeNthItem({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nth: -1, offset: 0 });
153
+ expect(result).toEqual([
154
+ ]);
155
+ });
156
+
157
+ it("should reverse the list", () => {
158
+ const result = lists.reverse({ list: [0, 1, 2] });
159
+ expect(result).toEqual([2, 1, 0]);
160
+ });
161
+
162
+ it("should reverse the list and clone", () => {
163
+ const result = lists.reverse({ list: [0, 1, 2], clone: true });
164
+ expect(result).toEqual([2, 1, 0]);
165
+ });
166
+
167
+ it("should flip the list", () => {
168
+ const result = lists.flipLists({ list: [[0, 1, 2], [3, 4, 5]] });
169
+ expect(result).toEqual([[0, 3], [1, 4], [2, 5]]);
170
+ });
171
+
172
+ it("should flip the list", () => {
173
+ const result = lists.flipLists({ list: [[0, 1, 2], [3, 4, 5]] });
174
+ expect(result).toEqual([[0, 3], [1, 4], [2, 5]]);
175
+ });
176
+
177
+ it("should flip the list", () => {
178
+ const result = lists.flipLists({ list: [[[0, 1, 2], [3, 4, 5], [12, 3, 4]], [[3, 2, 2], [33, 3, 4], [12, 2, 3]]] });
179
+ expect(result).toEqual([
180
+ [[0, 1, 2], [3, 2, 2]],
181
+ [[3, 4, 5], [33, 3, 4]],
182
+ [[12, 3, 4], [12, 2, 3]]
183
+ ]);
184
+ });
185
+
186
+ it("should throw when flipping the list with different lengths", () => {
187
+ expect(() => lists.flipLists({ list: [[0, 1, 2], [3, 4]] })).toThrowError("Lists are not of the same length");
188
+ });
189
+
190
+ it("should multiply the item", () => {
191
+ const result = lists.repeat({ item: 1, times: 3 });
192
+ expect(result).toEqual([1, 1, 1]);
193
+ });
194
+
195
+ it("should multiply the item 0 times", () => {
196
+ const result = lists.repeat({ item: 1, times: 0 });
197
+ expect(result).toEqual([]);
198
+ });
199
+
200
+ it("should multiply the item -1 times", () => {
201
+ const result = lists.repeat({ item: 1, times: -1 });
202
+ expect(result).toEqual([]);
203
+ });
204
+
205
+ it("should not flip empty list", () => {
206
+ expect(() => lists.flipLists({ list: [] })).toThrowError("List is empty");
207
+ });
208
+
209
+ it("should add item to the beginning of the list", () => {
210
+ const result = lists.addItemFirstLast({ list: [0, 1, 2], item: 3, position: Inputs.Lists.firstLastEnum.first });
211
+ expect(result).toEqual([3, 0, 1, 2]);
212
+ });
213
+
214
+ it("should add item to the beginning of the list and clone", () => {
215
+ const result = lists.addItemFirstLast({ list: [0, 1, 2], item: 3, position: Inputs.Lists.firstLastEnum.first, clone: true });
216
+ expect(result).toEqual([3, 0, 1, 2]);
217
+ });
218
+
219
+ it("should add item to the endof the list", () => {
220
+ const result = lists.addItemFirstLast({ list: [0, 1, 2], item: 3, position: Inputs.Lists.firstLastEnum.last });
221
+ expect(result).toEqual([0, 1, 2, 3]);
222
+ });
223
+
224
+ it("should add item to list at index", () => {
225
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: 1, item: 3 });
226
+ expect(result).toEqual([0, 3, 1, 2]);
227
+ });
228
+
229
+ it("should add item to list at index and clone", () => {
230
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: 1, item: 3, clone: true });
231
+ expect(result).toEqual([0, 3, 1, 2]);
232
+ });
233
+
234
+
235
+ it("should add item to list at index 0", () => {
236
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: 0, item: 3 });
237
+ expect(result).toEqual([3, 0, 1, 2]);
238
+ });
239
+
240
+ it("should add item to list at index 3", () => {
241
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: 3, item: 3 });
242
+ expect(result).toEqual([0, 1, 2, 3]);
243
+ });
244
+
245
+ it("should not add item to list at index 6", () => {
246
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: 6, item: 3 });
247
+ expect(result).toEqual([0, 1, 2]);
248
+ });
249
+
250
+ it("should add item to provided indexes", () => {
251
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2], indexes: [1, 2], item: 3 });
252
+ expect(result).toEqual([0, 3, 1, 3, 2]);
253
+ });
254
+
255
+ it("should add item to provided indexes on list edges", () => {
256
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2], indexes: [0, 3], item: 3 });
257
+ expect(result).toEqual([3, 0, 1, 2, 3]);
258
+ });
259
+
260
+ it("should add item to provided indexes on list edges and clone", () => {
261
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2], indexes: [0, 3], item: 3, clone: true });
262
+ expect(result).toEqual([3, 0, 1, 2, 3]);
263
+ });
264
+
265
+ it("should add item to provided indexes on list edges and index order should not matter", () => {
266
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2], indexes: [3, 0], item: 3 });
267
+ expect(result).toEqual([3, 0, 1, 2, 3]);
268
+ });
269
+
270
+ it("should add item to provided indexes on list edges", () => {
271
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2, 4, 5, 6], indexes: [0, 3, 5], item: 22 });
272
+ expect(result).toEqual([
273
+ 22, 0, 1, 2, 22,
274
+ 4, 5, 22, 6
275
+ ]);
276
+ });
277
+
278
+ it("should not add item to provided indexes on out of bound index", () => {
279
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2, 4, 5, 6], indexes: [0, 3, 44], item: 22 });
280
+ expect(result).toEqual([
281
+ 22, 0, 1, 2, 22,
282
+ 4, 5, 6
283
+ ]);
284
+ });
285
+
286
+ it("should not add item to provided indexes on out of bound index -2", () => {
287
+ const result = lists.addItemAtIndexes({ list: [0, 1, 2, 4, 5, 6], indexes: [0, 3, -4], item: 22 });
288
+ expect(result).toEqual([
289
+ 22, 0, 1, 2, 22,
290
+ 4, 5, 6
291
+ ]);
292
+ });
293
+
294
+ it("should not add item to list at index -1", () => {
295
+ const result = lists.addItemAtIndex({ list: [0, 1, 2], index: -1, item: 3 });
296
+ expect(result).toEqual([0, 1, 2]);
297
+ });
298
+
299
+ it("should add items to list at indexes", () => {
300
+ const result = lists.addItemsAtIndexes({ list: [0, 1, 2], indexes: [1, 2], items: [3, 4] });
301
+ expect(result).toEqual([0, 3, 1, 4, 2]);
302
+ });
303
+
304
+ it("should add items to list at indexes and clone", () => {
305
+ const result = lists.addItemsAtIndexes({ list: [0, 1, 2], indexes: [1, 2], items: [3, 4], clone: true });
306
+ expect(result).toEqual([0, 3, 1, 4, 2]);
307
+ });
308
+
309
+ it("should add items to list at indexes", () => {
310
+ const result = lists.addItemsAtIndexes({ list: [0, 1, 2], indexes: [0, 3], items: [3, 4] });
311
+ expect(result).toEqual([3, 0, 1, 2, 4]);
312
+ });
313
+
314
+ it("should not add items to list at indexes if the number of items is not the same as indexes", () => {
315
+ expect(() => lists.addItemsAtIndexes({ list: [0, 1, 2], indexes: [0, 3], items: [3, 4, 5] })).toThrowError("Items and indexes must have the same length");
316
+ });
317
+
318
+ it("should not add items to list at indexes if the indexes are not in ascending order", () => {
319
+ expect(() => lists.addItemsAtIndexes({ list: [0, 1, 2], indexes: [3, 0], items: [3, 4] })).toThrowError("Indexes must be in ascending order");
320
+ });
321
+
322
+ it("should remove item from list at index", () => {
323
+ const result = lists.removeItemAtIndex({ list: [0, 1, 2], index: 1 });
324
+ expect(result).toEqual([0, 2]);
325
+ });
326
+
327
+ it("should remove item from list at index and clone", () => {
328
+ const result = lists.removeItemAtIndex({ list: [0, 1, 2], index: 1, clone: true });
329
+ expect(result).toEqual([0, 2]);
330
+ });
331
+
332
+ it("should not remove item from list at out of bounds index", () => {
333
+ const reuslt = lists.removeItemAtIndex({ list: [0, 1, 2], index: 3 });
334
+ expect(reuslt).toEqual([0, 1, 2]);
335
+ });
336
+
337
+ it("should not remove item from list at out of bounds index -1", () => {
338
+ const result = lists.removeItemAtIndex({ list: [0, 1, 2], index: -1 });
339
+ expect(result).toEqual([0, 1, 2]);
340
+ });
341
+
342
+ it("should remove item from list at index 0", () => {
343
+ const result = lists.removeItemAtIndex({ list: [0, 1, 2], index: 0 });
344
+ expect(result).toEqual([1, 2]);
345
+ });
346
+
347
+ it("should remove items at indexes", () => {
348
+ const result = lists.removeItemsAtIndexes({ list: [0, 1, 2, 3, 4], indexes: [1, 3] });
349
+ expect(result).toEqual([0, 2, 4]);
350
+ });
351
+
352
+ it("should remove items at indexes and clone", () => {
353
+ const result = lists.removeItemsAtIndexes({ list: [0, 1, 2, 3, 4], indexes: [1, 3], clone: true });
354
+ expect(result).toEqual([0, 2, 4]);
355
+ });
356
+
357
+ it("should remove all items", () => {
358
+ const result = lists.removeAllItems({ list: [0, 1, 2, 3, 4] });
359
+ expect(result).toEqual([]);
360
+ });
361
+
362
+ it("should create empty list", () => {
363
+ const result = lists.createEmptyList();
364
+ expect(result).toEqual([]);
365
+ });
366
+
367
+ it("should merge elements of lists", () => {
368
+ const result = lists.mergeElementsOfLists({ lists: [[0, 1, 2], [3, 4, 5]], level: 0 });
369
+ expect(result).toEqual([[0, 3], [1, 4], [2, 5]]);
370
+ });
371
+
372
+ it("should merge elements of lists if level does not exist - highest level will be used and additional levels will be created in result", () => {
373
+ const result = lists.mergeElementsOfLists({ lists: [[0, 1, 2], [3, 4, 5]], level: 2 });
374
+ expect(result).toEqual([[[[0, 3], [1, 4], [2, 5]]]]);
375
+ });
376
+
377
+ it("should merge elements of lists to a new structure even if pair is not available in second branch", () => {
378
+ const result = lists.mergeElementsOfLists({ lists: [[0, 1, 2], [3, 4]], level: 0 });
379
+ expect(result).toEqual([[0, 3], [1, 4], [2]]);
380
+ });
381
+
382
+ it("should merge elements of lists to a new structure even if pair is not available in first branch", () => {
383
+ const result = lists.mergeElementsOfLists({ lists: [[0, 2], [3, 4, 5]], level: 0 });
384
+ expect(result).toEqual([[0, 3], [2, 4], [5]]);
385
+ });
386
+
387
+ it("should merge elements of lists to a new structure even if elements do not exist in first branch", () => {
388
+ const result = lists.mergeElementsOfLists({ lists: [[], [3, 4, 5]], level: 0 });
389
+ expect(result).toEqual([[3], [4], [5]]);
390
+ });
391
+
392
+ it("should merge elements of lists on deeper levels by keeping the structure", () => {
393
+ const result = lists.mergeElementsOfLists({ lists: [[[0, 1, 2]], [[3, 4, 5]]], level: 1 });
394
+ expect(result).toEqual([[[0, 3], [1, 4], [2, 5]]]);
395
+ });
396
+
397
+ it("should merge elements of lists on deeper levels by keeping the structure in branches", () => {
398
+ const result = lists.mergeElementsOfLists({ lists: [[[0, 1, 2], ["a", "b", "c"]], [[3, 4, 5], ["d", "e", "f"]], [[6, 7, 8], ["g", "h", "l"]]], level: 1 });
399
+ expect(result).toEqual([
400
+ [
401
+ [0, 3, 6],
402
+ [1, 4, 7],
403
+ [2, 5, 8],
404
+ ["a", "d", "g"],
405
+ ["b", "e", "h"],
406
+ ["c", "f", "l"]
407
+ ]
408
+ ]);
409
+ });
410
+
411
+ it("should merge elements of lists on deeper levels by keeping the structure in branches on lower level", () => {
412
+ const result = lists.mergeElementsOfLists({ lists: [[[0, 1, 2], ["a", "b", "c"]], [[3, 4, 5], ["d", "e", "f"]], [[6, 7, 8], ["g", "h", "l"]]], level: 0 });
413
+ expect(result).toEqual(
414
+ [
415
+ [
416
+ [0, 1, 2], [3, 4, 5], [6, 7, 8]
417
+ ], [
418
+ ["a", "b", "c"], ["d", "e", "f"], ["g", "h", "l"]
419
+ ]
420
+ ]
421
+ );
422
+ });
423
+
424
+ it("should merge elements of lists on deeper levels by keeping the structure on second level", () => {
425
+ const result = lists.mergeElementsOfLists({ lists: [[[[0, 1, 2]]], [[[3, 4, 5]]]], level: 2 });
426
+ expect(result).toEqual([[[[0, 3], [1, 4], [2, 5]]]]);
427
+ });
428
+
429
+ it("should get longest list length", () => {
430
+ const result = lists.getLongestListLength({ lists: [[0, 1, 2], [3, 4, 5], [2, 2], [1], [3, 3, 3, 4, 5]] });
431
+ expect(result).toEqual(5);
432
+ });
433
+
434
+ it("should get longest list length", () => {
435
+ const result = lists.getLongestListLength({ lists: undefined });
436
+ expect(result).toEqual(undefined);
437
+ });
438
+
439
+ it("should group nth and skip remainder", () => {
440
+ const result = lists.groupNth({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nrElements: 3, keepRemainder: false });
441
+ expect(result).toEqual([[0, 1, 2], [3, 4, 5], [6, 7, 8]]);
442
+ });
443
+
444
+ it("should group nth and keep remainder", () => {
445
+ const result = lists.groupNth({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], nrElements: 3, keepRemainder: true });
446
+ expect(result).toEqual([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]]);
447
+ });
448
+
449
+ // TODO this still needs to be implemented
450
+ // it.only('should group nth and keep remainder on certain level', () => {
451
+ // const result = lists.groupNth({ list: [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10]], nrElements: 2, keepRemainder: true });
452
+ // console.log(result);
453
+ // expect(result).toEqual([[[0, 1], [2, 3], [4]], [[5, 6], [7, 8], [9, 10]]]);
454
+ // });
455
+
456
+ it("should find the depth of the deepest level count in the list with one level", () => {
457
+ const result = lists.getListDepth({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } as Inputs.Lists.ListCloneDto<any>);
458
+ expect(result).toBe(1);
459
+ });
460
+
461
+ it("should find the depth of the deepest level count in the empty list with many levels", () => {
462
+ const result = lists.getListDepth({ list: [[], [[]], [[[[[]]]]]] } as Inputs.Lists.ListCloneDto<[]>);
463
+ expect(result).toBe(6);
464
+ });
465
+
466
+ it("should find the depth of the deepest level count in the list", () => {
467
+ const result = lists.getListDepth({ list: [0, 1, 2, [3, 4], 5, 6, 7, 8, 9, 10] } as Inputs.Lists.ListCloneDto<any>);
468
+ expect(result).toBe(2);
469
+ });
470
+
471
+ it("should find the depth of the deepest level count in the list", () => {
472
+ const result = lists.getListDepth({ list: [0, 1, 2, [3, [2], 4], 5, 6, 7, 8, 9, 10] } as Inputs.Lists.ListCloneDto<any>);
473
+ expect(result).toBe(3);
474
+ });
475
+
476
+ it("should get the elements by following the pattern true true false", () => {
477
+ const result = lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: [true, true, false] });
478
+ expect(result).toEqual([0, 1, 3, 4, 6, 7, 9, 10]);
479
+ });
480
+
481
+ it("should get the elements by following the pattern true true false false", () => {
482
+ const result = lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: [true, true, false, false] });
483
+ expect(result).toEqual([0, 1, 4, 5, 8, 9]);
484
+ });
485
+
486
+ it("should get the elements by following the pattern false true true true", () => {
487
+ const result = lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: [false, true, true, true] });
488
+ expect(result).toEqual([1, 2, 3, 5, 6, 7, 9, 10]);
489
+ });
490
+
491
+ it("should get the elements by following the pattern false true true true when list is shorter than pattern", () => {
492
+ const result = lists.getByPattern({ list: [0, 1, 2], pattern: [false, true, true, true] });
493
+ expect(result).toEqual([1, 2]);
494
+ });
495
+
496
+ it("should get the empty list by following the pattern containing single false element", () => {
497
+ const result = lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: [false] });
498
+ expect(result).toEqual([]);
499
+ });
500
+
501
+ it("should not get the elements by following the empty pattern", () => {
502
+ expect(() => lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: [] })).toThrowError("Pattern is empty or does not exist");
503
+ });
504
+
505
+ it("should not get the elements by following the empty pattern", () => {
506
+ expect(() => lists.getByPattern({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pattern: undefined })).toThrowError("Pattern is empty or does not exist");
507
+ });
508
+
509
+ it("should get list length", () => {
510
+ const result = lists.listLength({ list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] });
511
+ expect(result).toBe(11);
512
+ });
513
+
514
+ it("should remove duplicate numbers from the list", () => {
515
+ const result = lists.removeDuplicateNumbers({ list: [1, 2, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10] });
516
+ expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
517
+ });
518
+
519
+ it("should remove duplicate numbers from the list and clone", () => {
520
+ const result = lists.removeDuplicateNumbers({ list: [1, 2, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], clone: true });
521
+ expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
522
+ });
523
+
524
+ it("should remove duplicate numbers from the list with tolerance", () => {
525
+ const result = lists.removeDuplicateNumbersTolerance({ list: [1, 2.00001, 2, 2.01, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], tolerance: 0.0001, clone: false });
526
+ expect(result).toEqual([1, 2.00001, 2.01, 3, 4, 5, 6, 7, 8, 9, 10]);
527
+ });
528
+
529
+ it("should remove duplicate numbers from the list with tolerance and clone", () => {
530
+ const result = lists.removeDuplicateNumbersTolerance({ list: [1, 2.00001, 2, 2.01, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], tolerance: 0.0001, clone: true });
531
+ expect(result).toEqual([1, 2.00001, 2.01, 3, 4, 5, 6, 7, 8, 9, 10]);
532
+ });
533
+
534
+ it("should add item to the list", () => {
535
+ const result = lists.addItem({ list: [0, 1, 2], item: 3 });
536
+ expect(result).toEqual([0, 1, 2, 3]);
537
+ });
538
+
539
+ it("should add item to the list and clone", () => {
540
+ const result = lists.addItem({ list: [0, 1, 2], item: 3, clone: true });
541
+ expect(result).toEqual([0, 1, 2, 3]);
542
+ });
543
+
544
+ it("should prepend item to the list", () => {
545
+ const result = lists.prependItem({ list: [0, 1, 2], item: 3 });
546
+ expect(result).toEqual([3, 0, 1, 2]);
547
+ });
548
+
549
+ it("should prepend item to the list and clone", () => {
550
+ const result = lists.prependItem({ list: [0, 1, 2], item: 3, clone: true });
551
+ expect(result).toEqual([3, 0, 1, 2]);
552
+ });
553
+
554
+ it("should repeat in pattern", () => {
555
+ const result = lists.repeatInPattern({ list: [0, 1, 2], lengthLimit: 7 });
556
+ expect(result.length).toBe(7);
557
+ expect(result).toEqual([0, 1, 2, 0, 1, 2, 0]);
558
+ });
559
+
560
+ it("should repeat in pattern and clone", () => {
561
+ const result = lists.repeatInPattern({ list: [0, 1, 2], lengthLimit: 7, clone: true });
562
+ expect(result.length).toBe(7);
563
+ expect(result).toEqual([0, 1, 2, 0, 1, 2, 0]);
564
+ });
565
+
566
+ it("should sort the numbers in the list ascending", () => {
567
+ const result = lists.sortNumber({ list: [1, 2, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], orderAsc: true });
568
+ expect(result).toEqual([1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10]);
569
+ });
570
+
571
+ it("should sort the numbers in the list ascending and clone", () => {
572
+ const result = lists.sortNumber({ list: [1, 2, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], orderAsc: true, clone: true });
573
+ expect(result).toEqual([1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9, 10]);
574
+ });
575
+
576
+ it("should sort the numbers in the list descending", () => {
577
+ const result = lists.sortNumber({ list: [1, 2, 3, 2, 4, 3, 5, 6, 7, 7, 8, 9, 10], orderAsc: false });
578
+ expect(result).toEqual([10, 9, 8, 7, 7, 6, 5, 4, 3, 3, 2, 2, 1]);
579
+ });
580
+
581
+ it("should sort the texts in the list ascending", () => {
582
+ const result = lists.sortTexts({ list: ["a", "b", "c", "a", "d", "c", "e", "f", "g", "g", "h", "i", "j"], orderAsc: true });
583
+ expect(result).toEqual(["a", "a", "b", "c", "c", "d", "e", "f", "g", "g", "h", "i", "j"]);
584
+ });
585
+
586
+ it("should sort the texts in the list ascending and clone", () => {
587
+ const result = lists.sortTexts({ list: ["a", "b", "c", "a", "d", "c", "e", "f", "g", "g", "h", "i", "j"], orderAsc: true, clone: true });
588
+ expect(result).toEqual(["a", "a", "b", "c", "c", "d", "e", "f", "g", "g", "h", "i", "j"]);
589
+ });
590
+
591
+ it("should sort the texts in the list descending", () => {
592
+ const result = lists.sortTexts({ list: ["a", "b", "c", "a", "d", "c", "e", "f", "g", "g", "h", "i", "j"], orderAsc: false });
593
+ expect(result).toEqual(["j", "i", "h", "g", "g", "f", "e", "d", "c", "c", "b", "a", "a"]);
594
+ });
595
+
596
+ it("should sort by prop value ascending", () => {
597
+ const result = lists.sortByPropValue({ list: [{ prop: 1 }, { prop: 3 }, { prop: 2 }], property: "prop", orderAsc: true });
598
+ expect(result).toEqual([{ prop: 1 }, { prop: 2 }, { prop: 3 }]);
599
+ });
600
+
601
+ it("should sort by prop value ascending and clone", () => {
602
+ const result = lists.sortByPropValue({ list: [{ prop: 1 }, { prop: 3 }, { prop: 2 }], property: "prop", orderAsc: true, clone: true });
603
+ expect(result).toEqual([{ prop: 1 }, { prop: 2 }, { prop: 3 }]);
604
+ });
605
+
606
+ it("should sort by prop value descending", () => {
607
+ const result = lists.sortByPropValue({ list: [{ prop: 1 }, { prop: 3 }, { prop: 2 }], property: "prop", orderAsc: false });
608
+ expect(result).toEqual([{ prop: 3 }, { prop: 2 }, { prop: 1 }]);
609
+ });
610
+
611
+ });
612
+