1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00
MikeMcl_decimal.js/test/modules/clamp.js
Michael Mclaughlin 220f11c498 v10.3.0
2021-06-22 19:20:14 +01:00

45 lines
1.1 KiB
JavaScript

if (typeof T === 'undefined') require('../setup');
T('clamp', function () {
function t(x, min, max, expected) {
//T.assertEqual(expected, new Decimal(x).clampedTo(min, max).valueOf());
T.assertEqual(expected, new Decimal(x).clamp(min, max).valueOf());
//T.assertEqual(expected, Decimal.clamp(x, min, max).valueOf());
}
t('-0', '0', '0', '-0');
t('-0', '-0', '0', '-0');
t('-0', '0', '-0', '-0');
t('-0', '-0', '-0', '-0');
t('0', '0', '0', '0');
t('0', '-0', '0', '0');
t('0', '0', '-0', '0');
t('0', '-0', '-0', '0');
t(0, 0, 1, '0');
t(-1, 0, 1, '0');
t(-2, 0, 1, '0');
t(1, 0, 1, '1');
t(2, 0, 1, '1');
t(1, 1, 1, '1');
t(-1, 1, 1, '1');
t(-1, -1, 1, '-1');
t(2, 1, 2, '2');
t(3, 1, 2, '2');
t(1, 0, 1, '1');
t(2, 0, 1, '1');
t(Infinity, 0, 1, '1');
t(0, -Infinity, 0, '0');
t(-Infinity, 0, 1, '0');
t(-Infinity, -Infinity, Infinity, '-Infinity');
t(Infinity, -Infinity, Infinity, 'Infinity');
t(0, 1, Infinity, '1');
t(0, NaN, 1, 'NaN');
t(0, 0, NaN, 'NaN');
t(NaN, 0, 1, 'NaN');
});