RunKit + npm:

node v10.23.3
version: 1.0.0
endpointsharetweet
const assert = require('assert' ) const isNumber = num => typeof num === 'number' || num instanceof Number const circleArea = r => { if (!isNumber(r)) { throw new Error('Argument should be a number.') } if (r < 0) { throw new Error('Argument should not be negative') } return Math.PI * Math.pow(r, 2) } const err = new Error('Argument should be a number.') assert.equal(circleArea(10), 314.1592653589793) assert.equal(circleArea(Number(2)), 12.566370614359172) assert.equal(circleArea(new Number(3)), 28.274333882308138) assert.equal(circleArea(Infinity), Infinity) assert.notEqual(circleArea(10), 100) assert.throws(() => circleArea(-Infinity), new Error('Argument should not be negative')) assert.throws(() => circleArea(-1), new Error('Argument should not be negative')) assert.throws(() => circleArea(null), err) assert.throws(() => circleArea(undefined), err) assert.throws(() => circleArea(), err) assert.throws(() => circleArea(''), err) assert.throws(() => circleArea('10'), err) assert.throws(() => circleArea('not empty string'), err) assert.throws(() => circleArea(false), err) assert.throws(() => circleArea(true), err) assert.throws(() => circleArea({}), err) assert.throws(() => circleArea({r: 2}), err) assert.throws(() => circleArea([]), err) assert.throws(() => circleArea([1]), err) assert.throws(() => circleArea([1, 2]), err) assert.throws(() => circleArea(() => undefined), err) assert.throws(() => circleArea(/^regex/), err) 'passed'
Created from: https://npm.runkit.com/
Loading…

no comments

    sign in to comment