import { flatten, getItemAtOppositeSideOfArray, getItemsToEitherSideOfArrayIndex, } from './arrays'; describe('flatten', () => { test('Converts an array of arrays into a single array', () => { const initialArray = [ [1, 2, 3], [4, 5, 6], ]; const result = flatten(initialArray); expect(result).toEqual([1, 2, 3, 4, 5, 6]); }); }); describe('getItemsToEitherSide', () => { test('Gets the items to either side of an array index', () => { const initialArray = [ 0, 1, 2, 3, ]; const result = getItemsToEitherSideOfArrayIndex( initialArray, 2, ); expect(result).toEqual([1, 3]); }); // tslint:disable-next-line test('Gets the items to either side of an array index when the index is 0', () => { const initialArray = [ 0, 1, 2, 3, ]; const result = getItemsToEitherSideOfArrayIndex( initialArray, 0, ); expect(result).toEqual([1, 3]); }); // tslint:disable-next-line test('Gets the items to either side of an array index when the index is the last item', () => { const initialArray = [ 0, 1, 2, 3, ]; const result = getItemsToEitherSideOfArrayIndex( initialArray, initialArray.length - 1, ); expect(result).toEqual([0, 2]); }); }); describe('getItemAtOppositeSideOfArray', () => { // tslint:disable-next-line test('Gets the item at the opposite side of the array when the index is 0', () => { const array = [ 0, 1, 2, 3, ]; const result = getItemAtOppositeSideOfArray( array, 0, ); expect(result).toBe(2); }); // tslint:disable-next-line test('Gets the item at the opposite side of the array when the index is the midpoint', () => { const array = [ 0, 1, 2, 3, ]; const result = getItemAtOppositeSideOfArray( array, 2, ); expect(result).toBe(0); }); // tslint:disable-next-line test('Gets the item at the opposite side of the array when the index is the last item', () => { const array = [ 0, 1, 2, 3, ]; const result = getItemAtOppositeSideOfArray( array, 3, ); expect(result).toBe(1); }); });