2022-10-17 16:01:02 +03:00

40 lines
1.3 KiB
JavaScript

import { shift } from 'tools/array';
describe('tools/array', () => {
describe('[function] shift', () => {
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
test('should shift array right 3 positions', () => {
const result = shift(arr, 3);
expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]);
});
test('should shift array left 3 positions', () => {
const result = shift(arr, -3);
expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]);
});
test('should shift array right 6 positions', () => {
const result = shift(arr, 15);
expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]);
});
test('should shift array left 6 positions', () => {
const result = shift(arr, -15);
expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]);
});
test('should keep array as is', () => {
const result = shift(arr, 0);
expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
test('should keep array as is', () => {
const result = shift(arr, 9);
expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
});
test('should return empty array', () => {
const result = shift([], 0);
expect(result).toEqual([]);
});
test('should return empty array', () => {
const result = shift([], 0);
expect(result).toEqual([]);
});
});
});