test: improve clone() test expectation
[e-mobility-charging-stations-simulator.git] / tests / utils / Utils.test.ts
1 import { describe, it } from 'node:test'
2
3 import { hoursToMilliseconds, hoursToSeconds } from 'date-fns'
4 import { expect } from 'expect'
5
6 import { Constants } from '../../src/utils/Constants.js'
7 import {
8 clone,
9 convertToBoolean,
10 convertToDate,
11 convertToFloat,
12 convertToInt,
13 extractTimeSeriesValues,
14 formatDurationMilliSeconds,
15 formatDurationSeconds,
16 generateUUID,
17 getRandomFloat,
18 getRandomInteger,
19 hasOwnProp,
20 isArraySorted,
21 isAsyncFunction,
22 isEmptyArray,
23 isEmptyObject,
24 isEmptyString,
25 isNotEmptyArray,
26 isNotEmptyString,
27 isObject,
28 isValidDate,
29 max,
30 min,
31 once,
32 roundTo,
33 secureRandom,
34 sleep,
35 validateUUID
36 } from '../../src/utils/Utils.js'
37
38 await describe('Utils test suite', async () => {
39 await it('Verify generateUUID()/validateUUID()', () => {
40 const uuid = generateUUID()
41 expect(uuid).toBeDefined()
42 expect(uuid.length).toEqual(36)
43 expect(validateUUID(uuid)).toBe(true)
44 expect(validateUUID('abcdef00-0000-4000-0000-000000000000')).toBe(true)
45 expect(validateUUID('')).toBe(false)
46 // Shall invalidate Nil UUID
47 expect(validateUUID('00000000-0000-0000-0000-000000000000')).toBe(false)
48 expect(validateUUID('987FBC9-4BED-3078-CF07A-9141BA07C9F3')).toBe(false)
49 })
50
51 await it('Verify sleep()', async () => {
52 const start = performance.now()
53 await sleep(1000)
54 const stop = performance.now()
55 expect(stop - start).toBeGreaterThanOrEqual(1000)
56 })
57
58 await it('Verify formatDurationMilliSeconds()', () => {
59 expect(formatDurationMilliSeconds(0)).toBe('0 seconds')
60 expect(formatDurationMilliSeconds(900)).toBe('0 seconds')
61 expect(formatDurationMilliSeconds(1000)).toBe('1 second')
62 expect(formatDurationMilliSeconds(hoursToMilliseconds(4380))).toBe('182 days 12 hours')
63 })
64
65 await it('Verify formatDurationSeconds()', () => {
66 expect(formatDurationSeconds(0)).toBe('0 seconds')
67 expect(formatDurationSeconds(0.9)).toBe('0 seconds')
68 expect(formatDurationSeconds(1)).toBe('1 second')
69 expect(formatDurationSeconds(hoursToSeconds(4380))).toBe('182 days 12 hours')
70 })
71
72 await it('Verify isValidDate()', () => {
73 expect(isValidDate(undefined)).toBe(false)
74 expect(isValidDate(-1)).toBe(true)
75 expect(isValidDate(0)).toBe(true)
76 expect(isValidDate(1)).toBe(true)
77 expect(isValidDate(-0.5)).toBe(true)
78 expect(isValidDate(0.5)).toBe(true)
79 expect(isValidDate(new Date())).toBe(true)
80 })
81
82 await it('Verify convertToDate()', () => {
83 expect(convertToDate(undefined)).toBe(undefined)
84 expect(convertToDate(null)).toBe(undefined)
85 expect(() => convertToDate('')).toThrow(new Error("Cannot convert to date: ''"))
86 expect(() => convertToDate('00:70:61')).toThrow(new Error("Cannot convert to date: '00:70:61'"))
87 expect(convertToDate(0)).toStrictEqual(new Date('1970-01-01T00:00:00.000Z'))
88 expect(convertToDate(-1)).toStrictEqual(new Date('1969-12-31T23:59:59.999Z'))
89 const dateStr = '2020-01-01T00:00:00.000Z'
90 let date = convertToDate(dateStr)
91 expect(date).toBeInstanceOf(Date)
92 expect(date).toStrictEqual(new Date(dateStr))
93 date = convertToDate(new Date(dateStr))
94 expect(date).toBeInstanceOf(Date)
95 expect(date).toStrictEqual(new Date(dateStr))
96 })
97
98 await it('Verify convertToInt()', () => {
99 expect(convertToInt(undefined)).toBe(0)
100 expect(convertToInt(null)).toBe(0)
101 expect(convertToInt(0)).toBe(0)
102 const randomInteger = getRandomInteger()
103 expect(convertToInt(randomInteger)).toEqual(randomInteger)
104 expect(convertToInt('-1')).toBe(-1)
105 expect(convertToInt('1')).toBe(1)
106 expect(convertToInt('1.1')).toBe(1)
107 expect(convertToInt('1.9')).toBe(1)
108 expect(convertToInt('1.999')).toBe(1)
109 expect(convertToInt(-1)).toBe(-1)
110 expect(convertToInt(1)).toBe(1)
111 expect(convertToInt(1.1)).toBe(1)
112 expect(convertToInt(1.9)).toBe(1)
113 expect(convertToInt(1.999)).toBe(1)
114 expect(() => {
115 convertToInt('NaN')
116 }).toThrow("Cannot convert to integer: 'NaN'")
117 })
118
119 await it('Verify convertToFloat()', () => {
120 expect(convertToFloat(undefined)).toBe(0)
121 expect(convertToFloat(null)).toBe(0)
122 expect(convertToFloat(0)).toBe(0)
123 const randomFloat = getRandomFloat()
124 expect(convertToFloat(randomFloat)).toEqual(randomFloat)
125 expect(convertToFloat('-1')).toBe(-1)
126 expect(convertToFloat('1')).toBe(1)
127 expect(convertToFloat('1.1')).toBe(1.1)
128 expect(convertToFloat('1.9')).toBe(1.9)
129 expect(convertToFloat('1.999')).toBe(1.999)
130 expect(convertToFloat(-1)).toBe(-1)
131 expect(convertToFloat(1)).toBe(1)
132 expect(convertToFloat(1.1)).toBe(1.1)
133 expect(convertToFloat(1.9)).toBe(1.9)
134 expect(convertToFloat(1.999)).toBe(1.999)
135 expect(() => {
136 convertToFloat('NaN')
137 }).toThrow("Cannot convert to float: 'NaN'")
138 })
139
140 await it('Verify convertToBoolean()', () => {
141 expect(convertToBoolean(undefined)).toBe(false)
142 expect(convertToBoolean(null)).toBe(false)
143 expect(convertToBoolean('true')).toBe(true)
144 expect(convertToBoolean('false')).toBe(false)
145 expect(convertToBoolean('TRUE')).toBe(true)
146 expect(convertToBoolean('FALSE')).toBe(false)
147 expect(convertToBoolean('1')).toBe(true)
148 expect(convertToBoolean('0')).toBe(false)
149 expect(convertToBoolean(1)).toBe(true)
150 expect(convertToBoolean(0)).toBe(false)
151 expect(convertToBoolean(true)).toBe(true)
152 expect(convertToBoolean(false)).toBe(false)
153 expect(convertToBoolean('')).toBe(false)
154 expect(convertToBoolean('NoNBoolean')).toBe(false)
155 })
156
157 await it('Verify secureRandom()', () => {
158 const random = secureRandom()
159 expect(typeof random === 'number').toBe(true)
160 expect(random).toBeGreaterThanOrEqual(0)
161 expect(random).toBeLessThan(1)
162 })
163
164 await it('Verify getRandomInteger()', () => {
165 let randomInteger = getRandomInteger()
166 expect(Number.isSafeInteger(randomInteger)).toBe(true)
167 expect(randomInteger).toBeGreaterThanOrEqual(0)
168 expect(randomInteger).toBeLessThanOrEqual(Constants.MAX_RANDOM_INTEGER)
169 expect(randomInteger).not.toEqual(getRandomInteger())
170 randomInteger = getRandomInteger(0, -Constants.MAX_RANDOM_INTEGER)
171 expect(randomInteger).toBeGreaterThanOrEqual(-Constants.MAX_RANDOM_INTEGER)
172 expect(randomInteger).toBeLessThanOrEqual(0)
173 expect(() => getRandomInteger(0, 1)).toThrow(
174 'The value of "max" is out of range. It must be greater than the value of "min" (1). Received 1'
175 )
176 expect(() => getRandomInteger(-1)).toThrow(
177 'The value of "max" is out of range. It must be greater than the value of "min" (0). Received 0'
178 )
179 expect(() => getRandomInteger(Constants.MAX_RANDOM_INTEGER + 1)).toThrow(
180 `The value of "max" is out of range. It must be <= ${
181 Constants.MAX_RANDOM_INTEGER + 1
182 }. Received 281_474_976_710_656`
183 )
184 randomInteger = getRandomInteger(2, 1)
185 expect(randomInteger).toBeGreaterThanOrEqual(1)
186 expect(randomInteger).toBeLessThanOrEqual(2)
187 const maximum = 2.2
188 const minimum = 1.1
189 randomInteger = getRandomInteger(maximum, minimum)
190 expect(randomInteger).toBeLessThanOrEqual(Math.floor(maximum))
191 expect(randomInteger).toBeGreaterThanOrEqual(Math.ceil(minimum))
192 })
193
194 await it('Verify roundTo()', () => {
195 expect(roundTo(0, 2)).toBe(0)
196 expect(roundTo(0.5, 0)).toBe(1)
197 expect(roundTo(0.5, 2)).toBe(0.5)
198 expect(roundTo(-0.5, 0)).toBe(-1)
199 expect(roundTo(-0.5, 2)).toBe(-0.5)
200 expect(roundTo(1.005, 0)).toBe(1)
201 expect(roundTo(1.005, 2)).toBe(1.01)
202 expect(roundTo(2.175, 2)).toBe(2.18)
203 expect(roundTo(5.015, 2)).toBe(5.02)
204 expect(roundTo(-1.005, 2)).toBe(-1.01)
205 expect(roundTo(-2.175, 2)).toBe(-2.18)
206 expect(roundTo(-5.015, 2)).toBe(-5.02)
207 })
208
209 await it('Verify getRandomFloat()', () => {
210 let randomFloat = getRandomFloat()
211 expect(typeof randomFloat === 'number').toBe(true)
212 expect(randomFloat).toBeGreaterThanOrEqual(0)
213 expect(randomFloat).toBeLessThanOrEqual(Number.MAX_VALUE)
214 expect(randomFloat).not.toEqual(getRandomFloat())
215 expect(() => getRandomFloat(0, 1)).toThrow(new RangeError('Invalid interval'))
216 expect(() => getRandomFloat(Number.MAX_VALUE, -Number.MAX_VALUE)).toThrow(
217 new RangeError('Invalid interval')
218 )
219 randomFloat = getRandomFloat(0, -Number.MAX_VALUE)
220 expect(randomFloat).toBeGreaterThanOrEqual(-Number.MAX_VALUE)
221 expect(randomFloat).toBeLessThanOrEqual(0)
222 })
223
224 await it('Verify extractTimeSeriesValues()', () => {
225 expect(extractTimeSeriesValues([])).toEqual([])
226 expect(extractTimeSeriesValues([{ timestamp: Date.now(), value: 1.1 }])).toEqual([1.1])
227 expect(
228 extractTimeSeriesValues([
229 { timestamp: Date.now(), value: 1.1 },
230 { timestamp: Date.now(), value: 2.2 }
231 ])
232 ).toEqual([1.1, 2.2])
233 })
234
235 await it('Verify isObject()', () => {
236 expect(isObject('test')).toBe(false)
237 expect(isObject(undefined)).toBe(false)
238 expect(isObject(null)).toBe(false)
239 expect(isObject(0)).toBe(false)
240 expect(isObject([])).toBe(false)
241 expect(isObject([0, 1])).toBe(false)
242 expect(isObject(['0', '1'])).toBe(false)
243 expect(isObject({})).toBe(true)
244 expect(isObject({ 1: 1 })).toBe(true)
245 expect(isObject({ 1: '1' })).toBe(true)
246 expect(isObject(new Map())).toBe(true)
247 expect(isObject(new Set())).toBe(true)
248 expect(isObject(new WeakMap())).toBe(true)
249 expect(isObject(new WeakSet())).toBe(true)
250 })
251
252 await it('Verify isAsyncFunction()', () => {
253 expect(isAsyncFunction(null)).toBe(false)
254 expect(isAsyncFunction(undefined)).toBe(false)
255 expect(isAsyncFunction(true)).toBe(false)
256 expect(isAsyncFunction(false)).toBe(false)
257 expect(isAsyncFunction(0)).toBe(false)
258 expect(isAsyncFunction('')).toBe(false)
259 expect(isAsyncFunction([])).toBe(false)
260 expect(isAsyncFunction(new Date())).toBe(false)
261 // eslint-disable-next-line prefer-regex-literals
262 expect(isAsyncFunction(new RegExp('[a-z]', 'i'))).toBe(false)
263 expect(isAsyncFunction(new Error())).toBe(false)
264 expect(isAsyncFunction(new Map())).toBe(false)
265 expect(isAsyncFunction(new Set())).toBe(false)
266 expect(isAsyncFunction(new WeakMap())).toBe(false)
267 expect(isAsyncFunction(new WeakSet())).toBe(false)
268 expect(isAsyncFunction(new Int8Array())).toBe(false)
269 expect(isAsyncFunction(new Uint8Array())).toBe(false)
270 expect(isAsyncFunction(new Uint8ClampedArray())).toBe(false)
271 expect(isAsyncFunction(new Int16Array())).toBe(false)
272 expect(isAsyncFunction(new Uint16Array())).toBe(false)
273 expect(isAsyncFunction(new Int32Array())).toBe(false)
274 expect(isAsyncFunction(new Uint32Array())).toBe(false)
275 expect(isAsyncFunction(new Float32Array())).toBe(false)
276 expect(isAsyncFunction(new Float64Array())).toBe(false)
277 expect(isAsyncFunction(new BigInt64Array())).toBe(false)
278 expect(isAsyncFunction(new BigUint64Array())).toBe(false)
279 // eslint-disable-next-line @typescript-eslint/no-empty-function
280 expect(isAsyncFunction(new Promise(() => {}))).toBe(false)
281 expect(isAsyncFunction(new WeakRef({}))).toBe(false)
282 // eslint-disable-next-line @typescript-eslint/no-empty-function
283 expect(isAsyncFunction(new FinalizationRegistry(() => {}))).toBe(false)
284 expect(isAsyncFunction(new ArrayBuffer(16))).toBe(false)
285 expect(isAsyncFunction(new SharedArrayBuffer(16))).toBe(false)
286 expect(isAsyncFunction(new DataView(new ArrayBuffer(16)))).toBe(false)
287 expect(isAsyncFunction({})).toBe(false)
288 expect(isAsyncFunction({ a: 1 })).toBe(false)
289 // eslint-disable-next-line @typescript-eslint/no-empty-function
290 expect(isAsyncFunction(() => {})).toBe(false)
291 // eslint-disable-next-line @typescript-eslint/no-empty-function
292 expect(isAsyncFunction(function () {})).toBe(false)
293 // eslint-disable-next-line @typescript-eslint/no-empty-function
294 expect(isAsyncFunction(function named () {})).toBe(false)
295 // eslint-disable-next-line @typescript-eslint/no-empty-function
296 expect(isAsyncFunction(async () => {})).toBe(true)
297 // eslint-disable-next-line @typescript-eslint/no-empty-function
298 expect(isAsyncFunction(async function () {})).toBe(true)
299 // eslint-disable-next-line @typescript-eslint/no-empty-function
300 expect(isAsyncFunction(async function named () {})).toBe(true)
301 class TestClass {
302 // eslint-disable-next-line @typescript-eslint/no-empty-function
303 public testSync (): void {}
304 // eslint-disable-next-line @typescript-eslint/no-empty-function
305 public async testAsync (): Promise<void> {}
306 // eslint-disable-next-line @typescript-eslint/no-empty-function
307 public testArrowSync = (): void => {}
308 // eslint-disable-next-line @typescript-eslint/no-empty-function
309 public testArrowAsync = async (): Promise<void> => {}
310 // eslint-disable-next-line @typescript-eslint/no-empty-function
311 public static testStaticSync (): void {}
312 // eslint-disable-next-line @typescript-eslint/no-empty-function
313 public static async testStaticAsync (): Promise<void> {}
314 }
315 const testClass = new TestClass()
316 // eslint-disable-next-line @typescript-eslint/unbound-method
317 expect(isAsyncFunction(testClass.testSync)).toBe(false)
318 // eslint-disable-next-line @typescript-eslint/unbound-method
319 expect(isAsyncFunction(testClass.testAsync)).toBe(true)
320 expect(isAsyncFunction(testClass.testArrowSync)).toBe(false)
321 expect(isAsyncFunction(testClass.testArrowAsync)).toBe(true)
322 // eslint-disable-next-line @typescript-eslint/unbound-method
323 expect(isAsyncFunction(TestClass.testStaticSync)).toBe(false)
324 // eslint-disable-next-line @typescript-eslint/unbound-method
325 expect(isAsyncFunction(TestClass.testStaticAsync)).toBe(true)
326 })
327
328 await it('Verify clone()', () => {
329 const obj = { 1: 1 }
330 expect(clone(obj)).toStrictEqual(obj)
331 expect(clone(obj) === obj).toBe(false)
332 const nestedObj = { 1: obj, 2: obj }
333 expect(clone(nestedObj)).toStrictEqual(nestedObj)
334 expect(clone(nestedObj) === nestedObj).toBe(false)
335 const array = [1, 2]
336 expect(clone(array)).toStrictEqual(array)
337 expect(clone(array) === array).toBe(false)
338 const objArray = [obj, obj]
339 expect(clone(objArray)).toStrictEqual(objArray)
340 expect(clone(objArray) === objArray).toBe(false)
341 const date = new Date()
342 expect(clone(date)).toStrictEqual(date)
343 expect(clone(date) === date).toBe(false)
344 // The URL object seems to have not enumerable properties
345 const url = new URL('https://domain.tld')
346 expect(clone(url)).toStrictEqual({})
347 const map = new Map([['1', '2']])
348 expect(clone(map)).toStrictEqual(map)
349 expect(clone(map) === map).toBe(false)
350 const set = new Set(['1'])
351 expect(clone(set)).toStrictEqual(set)
352 expect(clone(set) === set).toBe(false)
353 const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]])
354 expect(() => clone(weakMap)).toThrow(new Error('#<WeakMap> could not be cloned.'))
355 const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }])
356 expect(() => clone(weakSet)).toThrow(new Error('#<WeakSet> could not be cloned.'))
357 })
358
359 await it('Verify hasOwnProp()', () => {
360 expect(hasOwnProp('test', '')).toBe(false)
361 expect(hasOwnProp(undefined, '')).toBe(false)
362 expect(hasOwnProp(null, '')).toBe(false)
363 expect(hasOwnProp([], '')).toBe(false)
364 expect(hasOwnProp({}, '')).toBe(false)
365 expect(hasOwnProp({ 1: 1 }, 1)).toBe(true)
366 expect(hasOwnProp({ 1: 1 }, '1')).toBe(true)
367 expect(hasOwnProp({ 1: 1 }, 2)).toBe(false)
368 expect(hasOwnProp({ 1: 1 }, '2')).toBe(false)
369 expect(hasOwnProp({ 1: '1' }, '1')).toBe(true)
370 expect(hasOwnProp({ 1: '1' }, 1)).toBe(true)
371 expect(hasOwnProp({ 1: '1' }, '2')).toBe(false)
372 expect(hasOwnProp({ 1: '1' }, 2)).toBe(false)
373 })
374
375 await it('Verify isEmptyString()', () => {
376 expect(isEmptyString('')).toBe(true)
377 expect(isEmptyString(' ')).toBe(true)
378 expect(isEmptyString(' ')).toBe(true)
379 expect(isEmptyString('test')).toBe(false)
380 expect(isEmptyString(' test')).toBe(false)
381 expect(isEmptyString('test ')).toBe(false)
382 expect(isEmptyString(undefined)).toBe(true)
383 expect(isEmptyString(null)).toBe(true)
384 expect(isEmptyString(0)).toBe(false)
385 expect(isEmptyString({})).toBe(false)
386 expect(isEmptyString([])).toBe(false)
387 expect(isEmptyString(new Map())).toBe(false)
388 expect(isEmptyString(new Set())).toBe(false)
389 expect(isEmptyString(new WeakMap())).toBe(false)
390 expect(isEmptyString(new WeakSet())).toBe(false)
391 })
392
393 await it('Verify isNotEmptyString()', () => {
394 expect(isNotEmptyString('')).toBe(false)
395 expect(isNotEmptyString(' ')).toBe(false)
396 expect(isNotEmptyString(' ')).toBe(false)
397 expect(isNotEmptyString('test')).toBe(true)
398 expect(isNotEmptyString(' test')).toBe(true)
399 expect(isNotEmptyString('test ')).toBe(true)
400 expect(isNotEmptyString(undefined)).toBe(false)
401 expect(isNotEmptyString(null)).toBe(false)
402 expect(isNotEmptyString(0)).toBe(false)
403 expect(isNotEmptyString({})).toBe(false)
404 expect(isNotEmptyString([])).toBe(false)
405 expect(isNotEmptyString(new Map())).toBe(false)
406 expect(isNotEmptyString(new Set())).toBe(false)
407 expect(isNotEmptyString(new WeakMap())).toBe(false)
408 expect(isNotEmptyString(new WeakSet())).toBe(false)
409 })
410
411 await it('Verify isEmptyArray()', () => {
412 expect(isEmptyArray([])).toBe(true)
413 expect(isEmptyArray([1, 2])).toBe(false)
414 expect(isEmptyArray(['1', '2'])).toBe(false)
415 expect(isEmptyArray(undefined)).toBe(false)
416 expect(isEmptyArray(null)).toBe(false)
417 expect(isEmptyArray('')).toBe(false)
418 expect(isEmptyArray('test')).toBe(false)
419 expect(isEmptyArray(0)).toBe(false)
420 expect(isEmptyArray({})).toBe(false)
421 expect(isEmptyArray(new Map())).toBe(false)
422 expect(isEmptyArray(new Set())).toBe(false)
423 expect(isEmptyArray(new WeakMap())).toBe(false)
424 expect(isEmptyArray(new WeakSet())).toBe(false)
425 })
426
427 await it('Verify isNotEmptyArray()', () => {
428 expect(isNotEmptyArray([])).toBe(false)
429 expect(isNotEmptyArray([1, 2])).toBe(true)
430 expect(isNotEmptyArray(['1', '2'])).toBe(true)
431 expect(isNotEmptyArray(undefined)).toBe(false)
432 expect(isNotEmptyArray(null)).toBe(false)
433 expect(isNotEmptyArray('')).toBe(false)
434 expect(isNotEmptyArray('test')).toBe(false)
435 expect(isNotEmptyArray(0)).toBe(false)
436 expect(isNotEmptyArray({})).toBe(false)
437 expect(isNotEmptyArray(new Map())).toBe(false)
438 expect(isNotEmptyArray(new Set())).toBe(false)
439 expect(isNotEmptyArray(new WeakMap())).toBe(false)
440 expect(isNotEmptyArray(new WeakSet())).toBe(false)
441 })
442
443 await it('Verify isEmptyObject()', () => {
444 expect(isEmptyObject({})).toBe(true)
445 expect(isEmptyObject({ 1: 1, 2: 2 })).toBe(false)
446 expect(isEmptyObject([])).toBe(false)
447 expect(isEmptyObject([1, 2])).toBe(false)
448 expect(isEmptyObject(new Map())).toBe(false)
449 expect(isEmptyObject(new Set())).toBe(false)
450 expect(isEmptyObject(new WeakMap())).toBe(false)
451 expect(isEmptyObject(new WeakSet())).toBe(false)
452 })
453
454 await it('Verify isArraySorted()', () => {
455 expect(
456 isArraySorted([], (a, b) => {
457 return a - b
458 })
459 ).toBe(true)
460 expect(
461 isArraySorted([1], (a, b) => {
462 return a - b
463 })
464 ).toBe(true)
465 expect(isArraySorted<number>([1, 2, 3, 4, 5], (a, b) => a - b)).toBe(true)
466 expect(isArraySorted<number>([1, 2, 3, 5, 4], (a, b) => a - b)).toBe(false)
467 expect(isArraySorted<number>([2, 1, 3, 4, 5], (a, b) => a - b)).toBe(false)
468 })
469
470 await it('Verify once()', () => {
471 let called = 0
472 const fn = (): number => ++called
473 const onceFn = once(fn, this)
474 const result1 = onceFn()
475 expect(called).toBe(1)
476 expect(result1).toBe(1)
477 const result2 = onceFn()
478 expect(called).toBe(1)
479 expect(result2).toBe(1)
480 const result3 = onceFn()
481 expect(called).toBe(1)
482 expect(result3).toBe(1)
483 })
484
485 await it('Verify min()', () => {
486 expect(min()).toBe(Infinity)
487 expect(min(0, 1)).toBe(0)
488 expect(min(1, 0)).toBe(0)
489 expect(min(0, -1)).toBe(-1)
490 expect(min(-1, 0)).toBe(-1)
491 })
492
493 await it('Verify max()', () => {
494 expect(max()).toBe(-Infinity)
495 expect(max(0, 1)).toBe(1)
496 expect(max(1, 0)).toBe(1)
497 expect(max(0, -1)).toBe(0)
498 expect(max(-1, 0)).toBe(0)
499 })
500 })