test: add queue tests
[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)
76845835
JB
7 expect(median([0.08])).toBe(0.08)
8 expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.05)
9 expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535)
aba955e1
JB
10 })
11
12 it('Verify isPlainObject() behavior', () => {
13 expect(isPlainObject(null)).toBe(false)
14 expect(isPlainObject(undefined)).toBe(false)
15 expect(isPlainObject(true)).toBe(false)
16 expect(isPlainObject(false)).toBe(false)
17 expect(isPlainObject(0)).toBe(false)
18 expect(isPlainObject('')).toBe(false)
19 expect(isPlainObject([])).toBe(false)
20 expect(isPlainObject(() => {})).toBe(false)
21 expect(isPlainObject(new Date())).toBe(false)
22 expect(isPlainObject(new RegExp())).toBe(false)
23 expect(isPlainObject(new Error())).toBe(false)
24 expect(isPlainObject(new Map())).toBe(false)
25 expect(isPlainObject(new Set())).toBe(false)
26 expect(isPlainObject(new WeakMap())).toBe(false)
27 expect(isPlainObject(new WeakSet())).toBe(false)
28 expect(isPlainObject(new Int8Array())).toBe(false)
29 expect(isPlainObject(new Uint8Array())).toBe(false)
30 expect(isPlainObject(new Uint8ClampedArray())).toBe(false)
31 expect(isPlainObject(new Int16Array())).toBe(false)
32 expect(isPlainObject(new Uint16Array())).toBe(false)
33 expect(isPlainObject(new Int32Array())).toBe(false)
34 expect(isPlainObject(new Uint32Array())).toBe(false)
35 expect(isPlainObject(new Float32Array())).toBe(false)
36 expect(isPlainObject(new Float64Array())).toBe(false)
37 expect(isPlainObject(new BigInt64Array())).toBe(false)
38 expect(isPlainObject(new BigUint64Array())).toBe(false)
39 expect(isPlainObject(new Promise(() => {}))).toBe(false)
40 expect(isPlainObject(new WeakRef({}))).toBe(false)
41 expect(isPlainObject(new FinalizationRegistry(() => {}))).toBe(false)
42 expect(isPlainObject(new ArrayBuffer())).toBe(false)
43 expect(isPlainObject(new SharedArrayBuffer())).toBe(false)
44 expect(isPlainObject(new DataView(new ArrayBuffer()))).toBe(false)
45 expect(isPlainObject({})).toBe(true)
46 expect(isPlainObject({ a: 1 })).toBe(true)
47 })
48})