-
Notifications
You must be signed in to change notification settings - Fork 597
Expand file tree
/
Copy pathpullAt.spec.ts
More file actions
87 lines (66 loc) · 2.69 KB
/
Copy pathpullAt.spec.ts
File metadata and controls
87 lines (66 loc) · 2.69 KB
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
import { describe, expect, it } from 'vitest';
import { pullAt } from './pullAt';
describe('pullAt', () => {
it('should returns index searched of original array and changed original array', () => {
const array = [0, 1, 2, 3, 4, 5];
const result = pullAt(array, [3, 5]);
expect(array).toStrictEqual([0, 1, 2, 4]);
expect(result).toStrictEqual([3, 5]);
});
it('even if there are duplicate index values must return an array containing duplicate index values', () => {
const array = [0, 1, 2, 3, 4, 5];
const result = pullAt(array, [1, 2, 2, 4]);
expect(array).toStrictEqual([0, 3, 5]);
expect(result).toStrictEqual([1, 2, 2, 4]);
});
it('even if there are not index value must return an array containing undefined value', () => {
const array = [0, 1, 2, 3, 4, 5];
const result = pullAt(array, [0, 3, 5, 6]);
expect(array).toStrictEqual([1, 2, 4]);
expect(result).toStrictEqual([0, 3, 5, undefined]);
});
it('even if there are other instance or type must return an array containing other instance or type values', () => {
const array = [0, { a: 1 }, [2], 3, '4'];
const result = pullAt(array, [1, 2, 4]);
expect(array).toStrictEqual([0, 3]);
expect(result).toStrictEqual([{ a: 1 }, [2], '4']);
});
it('even if index array parameter is empty must return an empty array', () => {
const array = [0, 1, 2, 3, 4, 5];
const result = pullAt(array, []);
expect(array).toStrictEqual([0, 1, 2, 3, 4, 5]);
expect(result).toStrictEqual([]);
});
it('should work with unsorted indexes', () => {
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const actual = pullAt(array, [1, 3, 11, 7, 5, 9]);
expect(array).toEqual([1, 3, 5, 7, 9, 11]);
expect(actual).toEqual([2, 4, 12, 8, 6, 10]);
});
it('should work with a single negative index', () => {
const array = [10, 20, 30, 40, 50];
const result = pullAt(array, [-1]);
expect(array).toEqual([10, 20, 30, 40]);
expect(result).toEqual([50]);
});
it('should work with multiple negative indices', () => {
const array = [10, 20, 30, 40, 50];
const result = pullAt(array, [-1, -2]);
expect(array).toEqual([10, 20, 30]);
expect(result).toEqual([50, 40]);
});
it('should work with mixed positive and negative indices', () => {
const array = [10, 20, 30, 40, 50];
const result = pullAt(array, [0, -1]);
expect(array).toEqual([20, 30, 40]);
expect(result).toEqual([10, 50]);
});
it('should work with objects', () => {
const foo = { foo: 1 };
const bar = { foo: 2 };
const arr = [foo, bar, foo];
const result = pullAt(arr, [2]);
expect(arr).toEqual([foo, bar]);
expect(result).toEqual([foo]);
});
});