• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (typeof T === 'undefined') require('../setup');
2
3T('clamp', function () {
4
5  function t(x, min, max, expected) {
6    //T.assertEqual(expected, new Decimal(x).clampedTo(min, max).valueOf());
7    T.assertEqual(expected, new Decimal(x).clamp(min, max).valueOf());
8    //T.assertEqual(expected, Decimal.clamp(x, min, max).valueOf());
9  }
10
11  t('-0', '0', '0', '-0');
12  t('-0', '-0', '0', '-0');
13  t('-0', '0', '-0', '-0');
14  t('-0', '-0', '-0', '-0');
15
16  t('0', '0', '0', '0');
17  t('0', '-0', '0', '0');
18  t('0', '0', '-0', '0');
19  t('0', '-0', '-0', '0');
20
21  t(0, 0, 1, '0');
22  t(-1, 0, 1, '0');
23  t(-2, 0, 1, '0');
24  t(1, 0, 1, '1');
25  t(2, 0, 1, '1');
26
27  t(1, 1, 1, '1');
28  t(-1, 1, 1, '1');
29  t(-1, -1, 1, '-1');
30  t(2, 1, 2, '2');
31  t(3, 1, 2, '2');
32  t(1, 0, 1, '1');
33  t(2, 0, 1, '1');
34
35  t(Infinity, 0, 1, '1');
36  t(0, -Infinity, 0, '0');
37  t(-Infinity, 0, 1, '0');
38  t(-Infinity, -Infinity, Infinity, '-Infinity');
39  t(Infinity, -Infinity, Infinity, 'Infinity');
40  t(0, 1, Infinity, '1');
41
42  t(0, NaN, 1, 'NaN');
43  t(0, 0, NaN, 'NaN');
44  t(NaN, 0, 1, 'NaN');
45});