-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.mjs
61 lines (54 loc) · 1.96 KB
/
index.test.mjs
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
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { getArrayWithNegativeIndexes } from './index.js';
describe('getArrayWithNegativeIndexes', () => {
it('should work with 0 index', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[0] === 1);
});
it('should work with positive indexes in range', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[1] === 2);
});
it('should work with positive indexes out of range', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[10] === undefined);
});
it('should work with negative indexes in range', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[-1] === 3);
});
it('should work with negative indexes at the end of range', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[-3] === 1);
});
it('should work with negative indexes out of range', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])[-6] === undefined);
});
it('should work with negative indexes out of range with snake teleport', () => {
assert(
getArrayWithNegativeIndexes([1, 2, 3], { enableSnakeTeleport: true })[
-6
] === 1
);
assert(
getArrayWithNegativeIndexes([1, 2, 3], { enableSnakeTeleport: true })[
-100
] === 3
);
});
it('should return `undefined` with non-integer indexes', () => {
assert(getArrayWithNegativeIndexes([1, 2, 3])['1.5'] === undefined);
assert(getArrayWithNegativeIndexes([1, 2, 3])[1.5] === undefined);
assert(getArrayWithNegativeIndexes([1, 2, 3])['foo'] === undefined);
});
it('should work with positive indexes in range with snake teleport', () => {
assert(
getArrayWithNegativeIndexes([1, 2, 3], {
enableSnakeTeleport: true,
})[2] === 3
);
});
it('should work with positive indexes out of range with snake teleport', () => {
assert(
getArrayWithNegativeIndexes([1, 2, 3], {
enableSnakeTeleport: true,
})[20] === 3
);
});
});