Commit | Line | Data |
---|---|---|
85cce27f | 1 | import { hoursToMilliseconds, hoursToSeconds } from 'date-fns'; |
f64ca10c | 2 | import { expect } from 'expect'; |
a2111e8d | 3 | |
878e026c | 4 | import { Constants } from '../../src/utils/Constants'; |
9bf0ef23 JB |
5 | import { |
6 | cloneObject, | |
7 | convertToBoolean, | |
8 | convertToDate, | |
9 | convertToFloat, | |
10 | convertToInt, | |
1553f6df | 11 | extractTimeSeriesValues, |
be4c6702 | 12 | formatDurationMilliSeconds, |
8053c842 | 13 | formatDurationSeconds, |
9bf0ef23 JB |
14 | generateUUID, |
15 | getRandomFloat, | |
16 | getRandomInteger, | |
17 | hasOwnProp, | |
80c58041 | 18 | isArraySorted, |
9bf0ef23 JB |
19 | isEmptyArray, |
20 | isEmptyObject, | |
21 | isEmptyString, | |
22 | isIterable, | |
23 | isNotEmptyArray, | |
24 | isNotEmptyString, | |
25 | isNullOrUndefined, | |
26 | isObject, | |
27 | isUndefined, | |
0bd926c1 | 28 | isValidTime, |
9bf0ef23 JB |
29 | roundTo, |
30 | secureRandom, | |
31 | sleep, | |
32 | validateUUID, | |
33 | } from '../../src/utils/Utils'; | |
a2111e8d | 34 | |
878e026c JB |
35 | describe('Utils test suite', () => { |
36 | it('Verify generateUUID()/validateUUID()', () => { | |
9bf0ef23 | 37 | const uuid = generateUUID(); |
878e026c JB |
38 | expect(uuid).toBeDefined(); |
39 | expect(uuid.length).toEqual(36); | |
9bf0ef23 JB |
40 | expect(validateUUID(uuid)).toBe(true); |
41 | expect(validateUUID('abcdef00-0000-4000-0000-000000000000')).toBe(true); | |
42 | expect(validateUUID('')).toBe(false); | |
878e026c | 43 | // Shall invalidate Nil UUID |
9bf0ef23 JB |
44 | expect(validateUUID('00000000-0000-0000-0000-000000000000')).toBe(false); |
45 | expect(validateUUID('987FBC9-4BED-3078-CF07A-9141BA07C9F3')).toBe(false); | |
878e026c | 46 | }); |
8bd02502 | 47 | |
878e026c | 48 | it('Verify sleep()', async () => { |
f204e9b4 | 49 | const start = performance.now(); |
9bf0ef23 | 50 | await sleep(1000); |
0f6058f3 JB |
51 | const stop = performance.now(); |
52 | expect(stop - start).toBeGreaterThanOrEqual(1000); | |
878e026c | 53 | }); |
45999aab | 54 | |
be4c6702 JB |
55 | it('Verify formatDurationMilliSeconds()', () => { |
56 | expect(formatDurationMilliSeconds(0)).toBe(''); | |
57 | expect(formatDurationMilliSeconds(1000)).toBe('1 second'); | |
58 | expect(formatDurationMilliSeconds(hoursToMilliseconds(4380))).toBe('182 days 12 hours'); | |
59 | }); | |
60 | ||
8053c842 JB |
61 | it('Verify formatDurationSeconds()', () => { |
62 | expect(formatDurationSeconds(0)).toBe(''); | |
63 | expect(formatDurationSeconds(1)).toBe('1 second'); | |
64 | expect(formatDurationSeconds(hoursToSeconds(4380))).toBe('182 days 12 hours'); | |
65 | }); | |
66 | ||
0bd926c1 JB |
67 | it('Verify isValidTime()', () => { |
68 | expect(isValidTime(undefined)).toBe(false); | |
69 | expect(isValidTime(null)).toBe(false); | |
70 | expect(isValidTime('')).toBe(false); | |
71 | expect(isValidTime({})).toBe(false); | |
72 | expect(isValidTime([])).toBe(false); | |
73 | expect(isValidTime(new Map())).toBe(false); | |
74 | expect(isValidTime(new Set())).toBe(false); | |
75 | expect(isValidTime(new WeakMap())).toBe(false); | |
76 | expect(isValidTime(new WeakSet())).toBe(false); | |
77 | expect(isValidTime(-1)).toBe(true); | |
78 | expect(isValidTime(0)).toBe(true); | |
79 | expect(isValidTime(1)).toBe(true); | |
80 | expect(isValidTime(-0.5)).toBe(true); | |
81 | expect(isValidTime(0.5)).toBe(true); | |
82 | expect(isValidTime(new Date())).toBe(true); | |
ac8178a4 JB |
83 | }); |
84 | ||
878e026c | 85 | it('Verify convertToDate()', () => { |
9bf0ef23 | 86 | expect(convertToDate(undefined)).toBe(undefined); |
85cce27f JB |
87 | expect(() => convertToDate('')).toThrowError(new Error("Cannot convert to date: ''")); |
88 | expect(() => convertToDate('00:70:61')).toThrowError( | |
89 | new Error("Cannot convert to date: '00:70:61'"), | |
90 | ); | |
9bf0ef23 | 91 | expect(convertToDate(0)).toStrictEqual(new Date('1970-01-01T00:00:00.000Z')); |
85cce27f | 92 | expect(convertToDate(-1)).toStrictEqual(new Date('1969-12-31T23:59:59.999Z')); |
878e026c | 93 | const dateStr = '2020-01-01T00:00:00.000Z'; |
9bf0ef23 | 94 | let date = convertToDate(dateStr); |
878e026c JB |
95 | expect(date).toBeInstanceOf(Date); |
96 | expect(date).toStrictEqual(new Date(dateStr)); | |
9bf0ef23 | 97 | date = convertToDate(new Date(dateStr)); |
878e026c JB |
98 | expect(date).toBeInstanceOf(Date); |
99 | expect(date).toStrictEqual(new Date(dateStr)); | |
100 | }); | |
df645d8f | 101 | |
878e026c | 102 | it('Verify convertToInt()', () => { |
9bf0ef23 JB |
103 | expect(convertToInt(undefined)).toBe(0); |
104 | expect(convertToInt(null)).toBe(0); | |
105 | expect(convertToInt(0)).toBe(0); | |
106 | const randomInteger = getRandomInteger(); | |
107 | expect(convertToInt(randomInteger)).toEqual(randomInteger); | |
108 | expect(convertToInt('-1')).toBe(-1); | |
109 | expect(convertToInt('1')).toBe(1); | |
110 | expect(convertToInt('1.1')).toBe(1); | |
111 | expect(convertToInt('1.9')).toBe(1); | |
112 | expect(convertToInt('1.999')).toBe(1); | |
113 | expect(convertToInt(-1)).toBe(-1); | |
114 | expect(convertToInt(1)).toBe(1); | |
115 | expect(convertToInt(1.1)).toBe(1); | |
116 | expect(convertToInt(1.9)).toBe(1); | |
117 | expect(convertToInt(1.999)).toBe(1); | |
878e026c | 118 | expect(() => { |
9bf0ef23 | 119 | convertToInt('NaN'); |
85cce27f | 120 | }).toThrow("Cannot convert to integer: 'NaN'"); |
878e026c | 121 | }); |
df645d8f | 122 | |
878e026c | 123 | it('Verify convertToFloat()', () => { |
9bf0ef23 JB |
124 | expect(convertToFloat(undefined)).toBe(0); |
125 | expect(convertToFloat(null)).toBe(0); | |
126 | expect(convertToFloat(0)).toBe(0); | |
127 | const randomFloat = getRandomFloat(); | |
128 | expect(convertToFloat(randomFloat)).toEqual(randomFloat); | |
129 | expect(convertToFloat('-1')).toBe(-1); | |
130 | expect(convertToFloat('1')).toBe(1); | |
131 | expect(convertToFloat('1.1')).toBe(1.1); | |
132 | expect(convertToFloat('1.9')).toBe(1.9); | |
133 | expect(convertToFloat('1.999')).toBe(1.999); | |
134 | expect(convertToFloat(-1)).toBe(-1); | |
135 | expect(convertToFloat(1)).toBe(1); | |
136 | expect(convertToFloat(1.1)).toBe(1.1); | |
137 | expect(convertToFloat(1.9)).toBe(1.9); | |
138 | expect(convertToFloat(1.999)).toBe(1.999); | |
878e026c | 139 | expect(() => { |
9bf0ef23 | 140 | convertToFloat('NaN'); |
85cce27f | 141 | }).toThrow("Cannot convert to float: 'NaN'"); |
878e026c | 142 | }); |
df645d8f | 143 | |
878e026c | 144 | it('Verify convertToBoolean()', () => { |
9bf0ef23 JB |
145 | expect(convertToBoolean(undefined)).toBe(false); |
146 | expect(convertToBoolean(null)).toBe(false); | |
147 | expect(convertToBoolean('true')).toBe(true); | |
148 | expect(convertToBoolean('false')).toBe(false); | |
149 | expect(convertToBoolean('TRUE')).toBe(true); | |
150 | expect(convertToBoolean('FALSE')).toBe(false); | |
151 | expect(convertToBoolean('1')).toBe(true); | |
152 | expect(convertToBoolean('0')).toBe(false); | |
153 | expect(convertToBoolean(1)).toBe(true); | |
154 | expect(convertToBoolean(0)).toBe(false); | |
155 | expect(convertToBoolean(true)).toBe(true); | |
156 | expect(convertToBoolean(false)).toBe(false); | |
157 | expect(convertToBoolean('')).toBe(false); | |
158 | expect(convertToBoolean('NoNBoolean')).toBe(false); | |
878e026c | 159 | }); |
df645d8f | 160 | |
878e026c | 161 | it('Verify secureRandom()', () => { |
9bf0ef23 | 162 | const random = secureRandom(); |
878e026c JB |
163 | expect(typeof random === 'number').toBe(true); |
164 | expect(random).toBeGreaterThanOrEqual(0); | |
165 | expect(random).toBeLessThan(1); | |
166 | }); | |
a2111e8d | 167 | |
878e026c | 168 | it('Verify getRandomInteger()', () => { |
9bf0ef23 | 169 | let randomInteger = getRandomInteger(); |
878e026c JB |
170 | expect(Number.isSafeInteger(randomInteger)).toBe(true); |
171 | expect(randomInteger).toBeGreaterThanOrEqual(0); | |
172 | expect(randomInteger).toBeLessThanOrEqual(Constants.MAX_RANDOM_INTEGER); | |
9bf0ef23 JB |
173 | expect(randomInteger).not.toEqual(getRandomInteger()); |
174 | randomInteger = getRandomInteger(0, -Constants.MAX_RANDOM_INTEGER); | |
878e026c JB |
175 | expect(randomInteger).toBeGreaterThanOrEqual(-Constants.MAX_RANDOM_INTEGER); |
176 | expect(randomInteger).toBeLessThanOrEqual(0); | |
9bf0ef23 | 177 | expect(() => getRandomInteger(0, 1)).toThrowError( |
5edd8ba0 | 178 | 'The value of "max" is out of range. It must be greater than the value of "min" (1). Received 1', |
878e026c | 179 | ); |
9bf0ef23 | 180 | expect(() => getRandomInteger(-1)).toThrowError( |
5edd8ba0 | 181 | 'The value of "max" is out of range. It must be greater than the value of "min" (0). Received 0', |
878e026c | 182 | ); |
9bf0ef23 | 183 | expect(() => getRandomInteger(Constants.MAX_RANDOM_INTEGER + 1)).toThrowError( |
878e026c JB |
184 | `The value of "max" is out of range. It must be <= ${ |
185 | Constants.MAX_RANDOM_INTEGER + 1 | |
5edd8ba0 | 186 | }. Received 281_474_976_710_656`, |
878e026c | 187 | ); |
9bf0ef23 | 188 | randomInteger = getRandomInteger(2, 1); |
878e026c JB |
189 | expect(randomInteger).toBeGreaterThanOrEqual(1); |
190 | expect(randomInteger).toBeLessThanOrEqual(2); | |
191 | const max = 2.2, | |
192 | min = 1.1; | |
9bf0ef23 | 193 | randomInteger = getRandomInteger(max, min); |
878e026c JB |
194 | expect(randomInteger).toBeGreaterThanOrEqual(Math.ceil(min)); |
195 | expect(randomInteger).toBeLessThanOrEqual(Math.floor(max)); | |
196 | }); | |
a2111e8d | 197 | |
316d1564 | 198 | it('Verify roundTo()', () => { |
9bf0ef23 JB |
199 | expect(roundTo(0, 2)).toBe(0); |
200 | expect(roundTo(0.5, 0)).toBe(1); | |
201 | expect(roundTo(0.5, 2)).toBe(0.5); | |
202 | expect(roundTo(-0.5, 0)).toBe(-1); | |
203 | expect(roundTo(-0.5, 2)).toBe(-0.5); | |
204 | expect(roundTo(1.005, 0)).toBe(1); | |
205 | expect(roundTo(1.005, 2)).toBe(1.01); | |
206 | expect(roundTo(2.175, 2)).toBe(2.18); | |
207 | expect(roundTo(5.015, 2)).toBe(5.02); | |
208 | expect(roundTo(-1.005, 2)).toBe(-1.01); | |
209 | expect(roundTo(-2.175, 2)).toBe(-2.18); | |
210 | expect(roundTo(-5.015, 2)).toBe(-5.02); | |
316d1564 JB |
211 | }); |
212 | ||
878e026c | 213 | it('Verify getRandomFloat()', () => { |
9bf0ef23 | 214 | let randomFloat = getRandomFloat(); |
878e026c JB |
215 | expect(typeof randomFloat === 'number').toBe(true); |
216 | expect(randomFloat).toBeGreaterThanOrEqual(0); | |
217 | expect(randomFloat).toBeLessThanOrEqual(Number.MAX_VALUE); | |
9bf0ef23 JB |
218 | expect(randomFloat).not.toEqual(getRandomFloat()); |
219 | expect(() => getRandomFloat(0, 1)).toThrowError(new RangeError('Invalid interval')); | |
220 | expect(() => getRandomFloat(Number.MAX_VALUE, -Number.MAX_VALUE)).toThrowError( | |
5edd8ba0 | 221 | new RangeError('Invalid interval'), |
878e026c | 222 | ); |
9bf0ef23 | 223 | randomFloat = getRandomFloat(0, -Number.MAX_VALUE); |
878e026c JB |
224 | expect(randomFloat).toBeGreaterThanOrEqual(-Number.MAX_VALUE); |
225 | expect(randomFloat).toBeLessThanOrEqual(0); | |
226 | }); | |
a2111e8d | 227 | |
1553f6df JB |
228 | it('Verify extractTimeSeriesValues()', () => { |
229 | expect(extractTimeSeriesValues([])).toEqual([]); | |
230 | expect(extractTimeSeriesValues([{ timestamp: Date.now(), value: 1.1 }])).toEqual([1.1]); | |
231 | expect( | |
232 | extractTimeSeriesValues([ | |
233 | { timestamp: Date.now(), value: 1.1 }, | |
234 | { timestamp: Date.now(), value: 2.2 }, | |
235 | ]), | |
236 | ).toEqual([1.1, 2.2]); | |
237 | }); | |
238 | ||
878e026c | 239 | it('Verify isObject()', () => { |
9bf0ef23 JB |
240 | expect(isObject('test')).toBe(false); |
241 | expect(isObject(undefined)).toBe(false); | |
242 | expect(isObject(null)).toBe(false); | |
243 | expect(isObject(0)).toBe(false); | |
244 | expect(isObject([])).toBe(false); | |
245 | expect(isObject([0, 1])).toBe(false); | |
246 | expect(isObject(['0', '1'])).toBe(false); | |
247 | expect(isObject({})).toBe(true); | |
248 | expect(isObject({ 1: 1 })).toBe(true); | |
249 | expect(isObject({ '1': '1' })).toBe(true); | |
250 | expect(isObject(new Map())).toBe(true); | |
251 | expect(isObject(new Set())).toBe(true); | |
252 | expect(isObject(new WeakMap())).toBe(true); | |
253 | expect(isObject(new WeakSet())).toBe(true); | |
878e026c | 254 | }); |
a2111e8d | 255 | |
dd5a1d6c JB |
256 | it('Verify cloneObject()', () => { |
257 | const obj = { 1: 1 }; | |
9bf0ef23 JB |
258 | expect(cloneObject(obj)).toStrictEqual(obj); |
259 | expect(cloneObject(obj) === obj).toBe(false); | |
32f5e42d JB |
260 | const nestedObj = { 1: obj, 2: obj }; |
261 | expect(cloneObject(nestedObj)).toStrictEqual(nestedObj); | |
262 | expect(cloneObject(nestedObj) === nestedObj).toBe(false); | |
dd5a1d6c | 263 | const array = [1, 2]; |
9bf0ef23 JB |
264 | expect(cloneObject(array)).toStrictEqual(array); |
265 | expect(cloneObject(array) === array).toBe(false); | |
32f5e42d JB |
266 | const objArray = [obj, obj]; |
267 | expect(cloneObject(objArray)).toStrictEqual(objArray); | |
268 | expect(cloneObject(objArray) === objArray).toBe(false); | |
dd5a1d6c | 269 | const date = new Date(); |
9bf0ef23 JB |
270 | expect(cloneObject(date)).toStrictEqual(date); |
271 | expect(cloneObject(date) === date).toBe(false); | |
dd5a1d6c | 272 | const map = new Map([['1', '2']]); |
32f5e42d | 273 | expect(cloneObject(map)).toStrictEqual({}); |
dd5a1d6c | 274 | const set = new Set(['1']); |
32f5e42d | 275 | expect(cloneObject(set)).toStrictEqual({}); |
dd5a1d6c JB |
276 | // The URL object seems to have not enumerable properties |
277 | const url = new URL('https://domain.tld'); | |
32f5e42d | 278 | expect(cloneObject(url)).toStrictEqual({}); |
dd5a1d6c | 279 | const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]]); |
32f5e42d | 280 | expect(cloneObject(weakMap)).toStrictEqual({}); |
dd5a1d6c | 281 | const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }]); |
32f5e42d | 282 | expect(cloneObject(weakSet)).toStrictEqual({}); |
dd5a1d6c JB |
283 | }); |
284 | ||
af29b598 | 285 | it('Verify hasOwnProp()', () => { |
9bf0ef23 JB |
286 | expect(hasOwnProp('test', '')).toBe(false); |
287 | expect(hasOwnProp(undefined, '')).toBe(false); | |
288 | expect(hasOwnProp(null, '')).toBe(false); | |
289 | expect(hasOwnProp([], '')).toBe(false); | |
290 | expect(hasOwnProp({}, '')).toBe(false); | |
291 | expect(hasOwnProp({ 1: 1 }, 1)).toBe(true); | |
292 | expect(hasOwnProp({ 1: 1 }, '1')).toBe(true); | |
293 | expect(hasOwnProp({ 1: 1 }, 2)).toBe(false); | |
294 | expect(hasOwnProp({ 1: 1 }, '2')).toBe(false); | |
295 | expect(hasOwnProp({ '1': '1' }, '1')).toBe(true); | |
296 | expect(hasOwnProp({ '1': '1' }, 1)).toBe(true); | |
297 | expect(hasOwnProp({ '1': '1' }, '2')).toBe(false); | |
298 | expect(hasOwnProp({ '1': '1' }, 2)).toBe(false); | |
af29b598 JB |
299 | }); |
300 | ||
878e026c | 301 | it('Verify isIterable()', () => { |
9bf0ef23 JB |
302 | expect(isIterable('')).toBe(true); |
303 | expect(isIterable(' ')).toBe(true); | |
304 | expect(isIterable('test')).toBe(true); | |
305 | expect(isIterable(undefined)).toBe(false); | |
306 | expect(isIterable(null)).toBe(false); | |
307 | expect(isIterable(0)).toBe(false); | |
308 | expect(isIterable([0, 1])).toBe(true); | |
309 | expect(isIterable({ 1: 1 })).toBe(false); | |
310 | expect(isIterable(new Map())).toBe(true); | |
311 | expect(isIterable(new Set())).toBe(true); | |
312 | expect(isIterable(new WeakMap())).toBe(false); | |
313 | expect(isIterable(new WeakSet())).toBe(false); | |
878e026c | 314 | }); |
a2111e8d | 315 | |
878e026c | 316 | it('Verify isEmptyString()', () => { |
9bf0ef23 JB |
317 | expect(isEmptyString('')).toBe(true); |
318 | expect(isEmptyString(' ')).toBe(true); | |
319 | expect(isEmptyString(' ')).toBe(true); | |
320 | expect(isEmptyString('test')).toBe(false); | |
321 | expect(isEmptyString(' test')).toBe(false); | |
322 | expect(isEmptyString('test ')).toBe(false); | |
323 | expect(isEmptyString(undefined)).toBe(true); | |
324 | expect(isEmptyString(null)).toBe(true); | |
325 | expect(isEmptyString(0)).toBe(false); | |
326 | expect(isEmptyString({})).toBe(false); | |
327 | expect(isEmptyString([])).toBe(false); | |
328 | expect(isEmptyString(new Map())).toBe(false); | |
329 | expect(isEmptyString(new Set())).toBe(false); | |
330 | expect(isEmptyString(new WeakMap())).toBe(false); | |
331 | expect(isEmptyString(new WeakSet())).toBe(false); | |
878e026c | 332 | }); |
5a2a53cf | 333 | |
878e026c | 334 | it('Verify isNotEmptyString()', () => { |
9bf0ef23 JB |
335 | expect(isNotEmptyString('')).toBe(false); |
336 | expect(isNotEmptyString(' ')).toBe(false); | |
337 | expect(isNotEmptyString(' ')).toBe(false); | |
338 | expect(isNotEmptyString('test')).toBe(true); | |
339 | expect(isNotEmptyString(' test')).toBe(true); | |
340 | expect(isNotEmptyString('test ')).toBe(true); | |
341 | expect(isNotEmptyString(undefined)).toBe(false); | |
342 | expect(isNotEmptyString(null)).toBe(false); | |
343 | expect(isNotEmptyString(0)).toBe(false); | |
344 | expect(isNotEmptyString({})).toBe(false); | |
345 | expect(isNotEmptyString([])).toBe(false); | |
346 | expect(isNotEmptyString(new Map())).toBe(false); | |
347 | expect(isNotEmptyString(new Set())).toBe(false); | |
348 | expect(isNotEmptyString(new WeakMap())).toBe(false); | |
349 | expect(isNotEmptyString(new WeakSet())).toBe(false); | |
878e026c | 350 | }); |
429f8c9d | 351 | |
878e026c | 352 | it('Verify isUndefined()', () => { |
9bf0ef23 JB |
353 | expect(isUndefined(undefined)).toBe(true); |
354 | expect(isUndefined(null)).toBe(false); | |
355 | expect(isUndefined('')).toBe(false); | |
356 | expect(isUndefined(0)).toBe(false); | |
357 | expect(isUndefined({})).toBe(false); | |
358 | expect(isUndefined([])).toBe(false); | |
359 | expect(isUndefined(new Map())).toBe(false); | |
360 | expect(isUndefined(new Set())).toBe(false); | |
361 | expect(isUndefined(new WeakMap())).toBe(false); | |
362 | expect(isUndefined(new WeakSet())).toBe(false); | |
878e026c | 363 | }); |
a2111e8d | 364 | |
878e026c | 365 | it('Verify isNullOrUndefined()', () => { |
9bf0ef23 JB |
366 | expect(isNullOrUndefined(undefined)).toBe(true); |
367 | expect(isNullOrUndefined(null)).toBe(true); | |
368 | expect(isNullOrUndefined('')).toBe(false); | |
369 | expect(isNullOrUndefined(0)).toBe(false); | |
370 | expect(isNullOrUndefined({})).toBe(false); | |
371 | expect(isNullOrUndefined([])).toBe(false); | |
372 | expect(isNullOrUndefined(new Map())).toBe(false); | |
373 | expect(isNullOrUndefined(new Set())).toBe(false); | |
374 | expect(isNullOrUndefined(new WeakMap())).toBe(false); | |
375 | expect(isNullOrUndefined(new WeakSet())).toBe(false); | |
878e026c | 376 | }); |
53ac516c | 377 | |
878e026c | 378 | it('Verify isEmptyArray()', () => { |
9bf0ef23 JB |
379 | expect(isEmptyArray([])).toBe(true); |
380 | expect(isEmptyArray([1, 2])).toBe(false); | |
381 | expect(isEmptyArray(['1', '2'])).toBe(false); | |
382 | expect(isEmptyArray(undefined)).toBe(false); | |
383 | expect(isEmptyArray(null)).toBe(false); | |
384 | expect(isEmptyArray('')).toBe(false); | |
385 | expect(isEmptyArray('test')).toBe(false); | |
386 | expect(isEmptyArray(0)).toBe(false); | |
387 | expect(isEmptyArray({})).toBe(false); | |
388 | expect(isEmptyArray(new Map())).toBe(false); | |
389 | expect(isEmptyArray(new Set())).toBe(false); | |
390 | expect(isEmptyArray(new WeakMap())).toBe(false); | |
391 | expect(isEmptyArray(new WeakSet())).toBe(false); | |
878e026c | 392 | }); |
a2111e8d | 393 | |
878e026c | 394 | it('Verify isNotEmptyArray()', () => { |
9bf0ef23 JB |
395 | expect(isNotEmptyArray([])).toBe(false); |
396 | expect(isNotEmptyArray([1, 2])).toBe(true); | |
397 | expect(isNotEmptyArray(['1', '2'])).toBe(true); | |
398 | expect(isNotEmptyArray(undefined)).toBe(false); | |
399 | expect(isNotEmptyArray(null)).toBe(false); | |
400 | expect(isNotEmptyArray('')).toBe(false); | |
401 | expect(isNotEmptyArray('test')).toBe(false); | |
402 | expect(isNotEmptyArray(0)).toBe(false); | |
403 | expect(isNotEmptyArray({})).toBe(false); | |
404 | expect(isNotEmptyArray(new Map())).toBe(false); | |
405 | expect(isNotEmptyArray(new Set())).toBe(false); | |
406 | expect(isNotEmptyArray(new WeakMap())).toBe(false); | |
407 | expect(isNotEmptyArray(new WeakSet())).toBe(false); | |
878e026c JB |
408 | }); |
409 | ||
410 | it('Verify isEmptyObject()', () => { | |
9bf0ef23 JB |
411 | expect(isEmptyObject({})).toBe(true); |
412 | expect(isEmptyObject({ 1: 1, 2: 2 })).toBe(false); | |
9bf0ef23 JB |
413 | expect(isEmptyObject(new Map())).toBe(false); |
414 | expect(isEmptyObject(new Set())).toBe(false); | |
415 | expect(isEmptyObject(new WeakMap())).toBe(false); | |
416 | expect(isEmptyObject(new WeakSet())).toBe(false); | |
878e026c | 417 | }); |
80c58041 JB |
418 | |
419 | it('Verify isArraySorted()', () => { | |
420 | expect( | |
421 | isArraySorted([], (a, b) => { | |
422 | return a - b; | |
423 | }), | |
424 | ).toBe(true); | |
425 | expect( | |
426 | isArraySorted([1], (a, b) => { | |
427 | return a - b; | |
428 | }), | |
429 | ).toBe(true); | |
430 | expect(isArraySorted<number>([1, 2, 3, 4, 5], (a, b) => a - b)).toBe(true); | |
431 | expect(isArraySorted<number>([1, 2, 3, 5, 4], (a, b) => a - b)).toBe(false); | |
479200ff | 432 | expect(isArraySorted<number>([2, 1, 3, 4, 5], (a, b) => a - b)).toBe(false); |
80c58041 | 433 | }); |
878e026c | 434 | }); |