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