X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Futils.test.js;h=0bf5e50ca8a4989099500100ff2b097a96092713;hb=985d0e7986b2cad23bb08ae0561b2a6ff9afdf9e;hp=f62d49c68af0a9a3a187cbf06d7899b7685cc829;hpb=f65efa796405c785a1ab5e646e30fc27418a6151;p=poolifier.git diff --git a/tests/utils.test.js b/tests/utils.test.js index f62d49c6..0bf5e50c 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,11 +1,20 @@ const { expect } = require('expect') -const { isPlainObject, median, availableParallelism } = require('../lib/utils') +const { + availableParallelism, + isPlainObject, + median, + round +} = require('../lib/utils') const { isKillBehavior, KillBehaviors } = require('../lib/worker/worker-options') describe('Utils test suite', () => { + it('Verify availableParallelism() behavior', () => { + expect(typeof availableParallelism() === 'number').toBe(true) + }) + it('Verify median() computation', () => { expect(median([])).toBe(0) expect(median([0.08])).toBe(0.08) @@ -13,6 +22,20 @@ describe('Utils test suite', () => { expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535) }) + it('Verify round() behavior', () => { + expect(round(0)).toBe(0) + expect(round(0.5, 0)).toBe(1) + expect(round(0.5)).toBe(0.5) + expect(round(-0.5, 0)).toBe(-1) + expect(round(-0.5)).toBe(-0.5) + expect(round(1.005)).toBe(1.01) + expect(round(2.175)).toBe(2.18) + expect(round(5.015)).toBe(5.02) + expect(round(-1.005)).toBe(-1.01) + expect(round(-2.175)).toBe(-2.18) + expect(round(-5.015)).toBe(-5.02) + }) + it('Verify isPlainObject() behavior', () => { expect(isPlainObject(null)).toBe(false) expect(isPlainObject(undefined)).toBe(false) @@ -60,8 +83,4 @@ describe('Utils test suite', () => { expect(isKillBehavior(KillBehaviors.HARD, null)).toBe(false) expect(isKillBehavior(KillBehaviors.SOFT, 'unknown')).toBe(false) }) - - it('Verify availableParallelism() behavior', () => { - expect(typeof availableParallelism() === 'number').toBe(true) - }) })