perf: optimize median computation implementation
[poolifier.git] / tests / utils.test.js
CommitLineData
aba955e1
JB
1const { expect } = require('expect')
2const { isPlainObject, median } = require('../lib/utils')
3
4describe('Utils test suite', () => {
5 it('Verify median computation', () => {
4a45e8d2 6 expect(median([])).toBe(0)
d27d0733
JB
7 const array0 = [0.08]
8 expect(median(array0)).toBe(0.08)
9 const array1 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]
10 expect(median(array1)).toBe(3.05)
aba955e1
JB
11 })
12
13 it('Verify isPlainObject() behavior', () => {
14 expect(isPlainObject(null)).toBe(false)
15 expect(isPlainObject(undefined)).toBe(false)
16 expect(isPlainObject(true)).toBe(false)
17 expect(isPlainObject(false)).toBe(false)
18 expect(isPlainObject(0)).toBe(false)
19 expect(isPlainObject('')).toBe(false)
20 expect(isPlainObject([])).toBe(false)
21 expect(isPlainObject(() => {})).toBe(false)
22 expect(isPlainObject(new Date())).toBe(false)
23 expect(isPlainObject(new RegExp())).toBe(false)
24 expect(isPlainObject(new Error())).toBe(false)
25 expect(isPlainObject(new Map())).toBe(false)
26 expect(isPlainObject(new Set())).toBe(false)
27 expect(isPlainObject(new WeakMap())).toBe(false)
28 expect(isPlainObject(new WeakSet())).toBe(false)
29 expect(isPlainObject(new Int8Array())).toBe(false)
30 expect(isPlainObject(new Uint8Array())).toBe(false)
31 expect(isPlainObject(new Uint8ClampedArray())).toBe(false)
32 expect(isPlainObject(new Int16Array())).toBe(false)
33 expect(isPlainObject(new Uint16Array())).toBe(false)
34 expect(isPlainObject(new Int32Array())).toBe(false)
35 expect(isPlainObject(new Uint32Array())).toBe(false)
36 expect(isPlainObject(new Float32Array())).toBe(false)
37 expect(isPlainObject(new Float64Array())).toBe(false)
38 expect(isPlainObject(new BigInt64Array())).toBe(false)
39 expect(isPlainObject(new BigUint64Array())).toBe(false)
40 expect(isPlainObject(new Promise(() => {}))).toBe(false)
41 expect(isPlainObject(new WeakRef({}))).toBe(false)
42 expect(isPlainObject(new FinalizationRegistry(() => {}))).toBe(false)
43 expect(isPlainObject(new ArrayBuffer())).toBe(false)
44 expect(isPlainObject(new SharedArrayBuffer())).toBe(false)
45 expect(isPlainObject(new DataView(new ArrayBuffer()))).toBe(false)
46 expect(isPlainObject({})).toBe(true)
47 expect(isPlainObject({ a: 1 })).toBe(true)
48 })
49})