-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy patharray.spec.ts
39 lines (36 loc) · 1.53 KB
/
array.spec.ts
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
import { isEmptyArray, splitArrayByFirstLetter } from 'utils/array';
describe('isEmptyArray', () => {
it('should return true', () => {
const array: string[] = [];
expect(isEmptyArray(array)).toBe(true);
});
it('should return false', () => {
const array: string[] = ['a', 'b'];
expect(isEmptyArray(array)).toBe(false);
});
});
describe('splitArrayByFirstLetter', () => {
it('should return two empty arrays', () => {
const array: string[] = [];
const results = splitArrayByFirstLetter(array);
expect(results).toEqual([[], []]);
});
it('should return an array of digit starting strings and one empty array', () => {
const array = ['1USMD', '2PMSZ', '0'];
const [digitArray, emptyArray] = splitArrayByFirstLetter(array);
expect(digitArray).toEqual(['0', '1USMD', '2PMSZ']);
expect(emptyArray).toEqual([]);
});
it('should return an empty array and an array of letter starting strings', () => {
const array = ['USMDI', 'C1UM', 'BMDPC'];
const [digitArray, letterArray] = splitArrayByFirstLetter(array);
expect(digitArray).toEqual([]);
expect(letterArray).toEqual(['BMDPC', 'C1UM', 'USMDI']);
});
it('should return an array of digit or special characters starting strings an one of letter starting strings', () => {
const array = ['USMDI', 'C1UM', '3MDPC', '5QSDF', '0POIUY', '%LUNC'];
const [digitArray, letterArray] = splitArrayByFirstLetter(array);
expect(digitArray).toEqual(['%LUNC', '0POIUY', '3MDPC', '5QSDF']);
expect(letterArray).toEqual(['C1UM', 'USMDI']);
});
});