Files
core-js/tests/unit-global/esnext.math.clamp.js

30 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
QUnit.test('Math.clamp', assert => {
const { clamp } = Math;
assert.isFunction(clamp);
assert.name(clamp, 'clamp');
assert.arity(clamp, 3);
assert.looksNative(clamp);
assert.nonEnumerable(Math, 'clamp');
assert.same(clamp(2, 4, 6), 4);
assert.same(clamp(4, 2, 6), 4);
assert.same(clamp(6, 2, 4), 4);
assert.same(clamp(-0, 0, 1), 0, 'If value is -0𝔽 and min is +0𝔽, return +0𝔽.');
assert.same(clamp(0, -0, 1), 0, 'If value is +0𝔽 and min is -0𝔽, return +0𝔽.');
assert.same(clamp(-0, -1, 0), -0, 'If value is -0𝔽 and max is +0𝔽, return -0𝔽.');
assert.same(clamp(0, -1, -0), -0, 'If value is +0𝔽 and max is -0𝔽, return -0𝔽.');
assert.same(clamp(0, -0, -0), -0, 'If min = max return min.');
assert.same(clamp(2, 0, -0), -0, 'min is +0𝔽 and max is -0𝔽');
assert.same(clamp(2, 3, 1), 1, 'min > max');
assert.same(clamp(NaN, 3, 1), NaN, 'If value is NaN, return NaN.');
assert.same(clamp(2, NaN, 1), NaN, 'If min is NaN, return NaN.');
assert.same(clamp(2, 3, NaN), NaN, 'If max is NaN, return NaN.');
assert.throws(() => clamp({ valueOf: () => 2 }, 1, 3), TypeError, 'If value is not a Number, throw a TypeError exception');
assert.throws(() => clamp(2, Object(1), 3), TypeError, 'If min is not a Number, throw a TypeError exception.');
assert.throws(() => clamp(2, 1, Object(3)), TypeError, 'If max is not a Number, throw a TypeError exception.');
});