X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Futils.test.js;h=b1a91776a61ac63abefb10eea11ee11f19c1b29d;hb=a6d9dccfaf39e185c896747260d668fcb683a8ed;hp=7d4040ce324ec67a8668d68e38ab1a70eb45e165;hpb=aba955e18c656962a79c88816371be2180bbf268;p=poolifier.git diff --git a/tests/utils.test.js b/tests/utils.test.js index 7d4040ce..b1a91776 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,10 +1,16 @@ const { expect } = require('expect') const { isPlainObject, median } = require('../lib/utils') +const { + isKillBehavior, + KillBehaviors +} = require('../lib/worker/worker-options') 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 median() computation', () => { + expect(median([])).toBe(0) + expect(median([0.08])).toBe(0.08) + expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.05) + expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535) }) it('Verify isPlainObject() behavior', () => { @@ -43,4 +49,15 @@ describe('Utils test suite', () => { expect(isPlainObject({})).toBe(true) expect(isPlainObject({ a: 1 })).toBe(true) }) + + it('Verify isKillBehavior() behavior', () => { + expect(isKillBehavior(KillBehaviors.SOFT, KillBehaviors.SOFT)).toBe(true) + expect(isKillBehavior(KillBehaviors.SOFT, KillBehaviors.HARD)).toBe(false) + expect(isKillBehavior(KillBehaviors.HARD, KillBehaviors.HARD)).toBe(true) + expect(isKillBehavior(KillBehaviors.HARD, KillBehaviors.SOFT)).toBe(false) + expect(isKillBehavior(KillBehaviors.SOFT)).toBe(false) + expect(isKillBehavior(KillBehaviors.HARD)).toBe(false) + expect(isKillBehavior(KillBehaviors.HARD, null)).toBe(false) + expect(isKillBehavior(KillBehaviors.SOFT, 'unknown')).toBe(false) + }) })