|
// Test isNegative() and isPositive() |
|
let numbers = [0, 0.123456789, 1, 123456789, Infinity]; |
|
numbers = ['A'].concat([...numbers].reverse().map(x => -x), numbers, ['Z']); |
|
for (const [name, fn] of [['isNegative', isNegative], ['isPositive', isPositive]]) { |
|
for (const bool of [false, true]) { |
|
for (const x of numbers) { |
|
console.log(`${name}(${(x === 0 && 1/x < 0) ? '-0' : x}, ${bool}) => ${fn(x, bool)}`); |
|
} |
|
} |
|
} |
|
|
|
// Test sameSign() |
|
for (const {args, result} of [ |
|
{args: ['-2'], result: false}, |
|
{args: ['2'], result: false}, |
|
{args: [-2], result: true}, |
|
{args: [2], result: true}, |
|
{args: [0, 0], result: true}, |
|
{args: [0, -0], result: false}, |
|
{args: [-0, 0], result: false}, |
|
{args: [-0, -0], result: true}, |
|
{args: [0, 0, {}], result: false}, |
|
{args: [{}, 0, 0], result: false}, |
|
{args: [-0, -0, {}], result: false}, |
|
{args: [{}, -0, -0], result: false}, |
|
]) { |
|
console.assert(sameSign(...args) === result, 'Failed for', args); |
|
} |