From: Jérôme Benoit Date: Mon, 8 May 2023 20:31:36 +0000 (+0200) Subject: test: add tests for utils helper X-Git-Tag: v2.4.14~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aba955e18c656962a79c88816371be2180bbf268;p=poolifier.git test: add tests for utils helper Signed-off-by: Jérôme Benoit --- diff --git a/tests/utils.test.js b/tests/utils.test.js new file mode 100644 index 000000000..7d4040ce3 --- /dev/null +++ b/tests/utils.test.js @@ -0,0 +1,46 @@ +const { expect } = require('expect') +const { isPlainObject, median } = require('../lib/utils') + +describe('Utils test suite', () => { + it('Verify median computation', () => { + const array = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03] + expect(median(array)).toBe(2.535) + }) + + it('Verify isPlainObject() behavior', () => { + expect(isPlainObject(null)).toBe(false) + expect(isPlainObject(undefined)).toBe(false) + expect(isPlainObject(true)).toBe(false) + expect(isPlainObject(false)).toBe(false) + expect(isPlainObject(0)).toBe(false) + expect(isPlainObject('')).toBe(false) + expect(isPlainObject([])).toBe(false) + expect(isPlainObject(() => {})).toBe(false) + expect(isPlainObject(new Date())).toBe(false) + expect(isPlainObject(new RegExp())).toBe(false) + expect(isPlainObject(new Error())).toBe(false) + expect(isPlainObject(new Map())).toBe(false) + expect(isPlainObject(new Set())).toBe(false) + expect(isPlainObject(new WeakMap())).toBe(false) + expect(isPlainObject(new WeakSet())).toBe(false) + expect(isPlainObject(new Int8Array())).toBe(false) + expect(isPlainObject(new Uint8Array())).toBe(false) + expect(isPlainObject(new Uint8ClampedArray())).toBe(false) + expect(isPlainObject(new Int16Array())).toBe(false) + expect(isPlainObject(new Uint16Array())).toBe(false) + expect(isPlainObject(new Int32Array())).toBe(false) + expect(isPlainObject(new Uint32Array())).toBe(false) + expect(isPlainObject(new Float32Array())).toBe(false) + expect(isPlainObject(new Float64Array())).toBe(false) + expect(isPlainObject(new BigInt64Array())).toBe(false) + expect(isPlainObject(new BigUint64Array())).toBe(false) + expect(isPlainObject(new Promise(() => {}))).toBe(false) + expect(isPlainObject(new WeakRef({}))).toBe(false) + expect(isPlainObject(new FinalizationRegistry(() => {}))).toBe(false) + expect(isPlainObject(new ArrayBuffer())).toBe(false) + expect(isPlainObject(new SharedArrayBuffer())).toBe(false) + expect(isPlainObject(new DataView(new ArrayBuffer()))).toBe(false) + expect(isPlainObject({})).toBe(true) + expect(isPlainObject({ a: 1 })).toBe(true) + }) +})