Welcome to mirror list, hosted at ThFree Co, Russian Federation.

array_utility_spec.js « utils « lib « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b95286ff25469a773482d4d10d26b50f86ed2afd (plain)
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
import * as arrayUtils from '~/lib/utils/array_utility';

describe('array_utility', () => {
  describe('swapArrayItems', () => {
    it.each`
      array              | leftIndex | rightIndex | result
      ${[]}              | ${0}      | ${0}       | ${[]}
      ${[1]}             | ${0}      | ${1}       | ${[1]}
      ${[1, 2]}          | ${0}      | ${0}       | ${[1, 2]}
      ${[1, 2]}          | ${0}      | ${1}       | ${[2, 1]}
      ${[1, 2]}          | ${1}      | ${2}       | ${[1, 2]}
      ${[1, 2]}          | ${2}      | ${1}       | ${[1, 2]}
      ${[1, 2]}          | ${1}      | ${10}      | ${[1, 2]}
      ${[1, 2]}          | ${10}     | ${1}       | ${[1, 2]}
      ${[1, 2]}          | ${1}      | ${-1}      | ${[1, 2]}
      ${[1, 2]}          | ${-1}     | ${1}       | ${[1, 2]}
      ${[1, 2, 3]}       | ${1}      | ${1}       | ${[1, 2, 3]}
      ${[1, 2, 3]}       | ${0}      | ${2}       | ${[3, 2, 1]}
      ${[1, 2, 3, 4]}    | ${0}      | ${2}       | ${[3, 2, 1, 4]}
      ${[1, 2, 3, 4, 5]} | ${0}      | ${4}       | ${[5, 2, 3, 4, 1]}
      ${[1, 2, 3, 4, 5]} | ${1}      | ${2}       | ${[1, 3, 2, 4, 5]}
      ${[1, 2, 3, 4, 5]} | ${2}      | ${1}       | ${[1, 3, 2, 4, 5]}
    `(
      'given $array with index $leftIndex and $rightIndex will return $result',
      ({ array, leftIndex, rightIndex, result }) => {
        const actual = arrayUtils.swapArrayItems(array, leftIndex, rightIndex);
        expect(actual).toEqual(result);
        expect(actual).not.toBe(array);
      },
    );
  });
});