[79a0317] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var test = require('tape');
|
---|
| 4 | var v = require('es-value-fixtures');
|
---|
| 5 | var forEach = require('for-each');
|
---|
| 6 | var inspect = require('object-inspect');
|
---|
| 7 |
|
---|
| 8 | var abs = require('../abs');
|
---|
| 9 | var floor = require('../floor');
|
---|
| 10 | var isFinite = require('../isFinite');
|
---|
| 11 | var isInteger = require('../isInteger');
|
---|
| 12 | var isNaN = require('../isNaN');
|
---|
| 13 | var isNegativeZero = require('../isNegativeZero');
|
---|
| 14 | var max = require('../max');
|
---|
| 15 | var min = require('../min');
|
---|
| 16 | var mod = require('../mod');
|
---|
| 17 | var pow = require('../pow');
|
---|
| 18 | var round = require('../round');
|
---|
| 19 | var sign = require('../sign');
|
---|
| 20 |
|
---|
| 21 | var maxArrayLength = require('../constants/maxArrayLength');
|
---|
| 22 | var maxSafeInteger = require('../constants/maxSafeInteger');
|
---|
| 23 | var maxValue = require('../constants/maxValue');
|
---|
| 24 |
|
---|
| 25 | test('abs', function (t) {
|
---|
| 26 | t.equal(abs(-1), 1, 'abs(-1) === 1');
|
---|
| 27 | t.equal(abs(+1), 1, 'abs(+1) === 1');
|
---|
| 28 | t.equal(abs(+0), +0, 'abs(+0) === +0');
|
---|
| 29 | t.equal(abs(-0), +0, 'abs(-0) === +0');
|
---|
| 30 |
|
---|
| 31 | t.end();
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | test('floor', function (t) {
|
---|
| 35 | t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
|
---|
| 36 | t.equal(floor(+1.1), 1, 'floor(+1.1) === 1');
|
---|
| 37 | t.equal(floor(+0), +0, 'floor(+0) === +0');
|
---|
| 38 | t.equal(floor(-0), -0, 'floor(-0) === -0');
|
---|
| 39 | t.equal(floor(-Infinity), -Infinity, 'floor(-Infinity) === -Infinity');
|
---|
| 40 | t.equal(floor(Number(Infinity)), Number(Infinity), 'floor(+Infinity) === +Infinity');
|
---|
| 41 | t.equal(floor(NaN), NaN, 'floor(NaN) === NaN');
|
---|
| 42 | t.equal(floor(0), +0, 'floor(0) === +0');
|
---|
| 43 | t.equal(floor(-0), -0, 'floor(-0) === -0');
|
---|
| 44 | t.equal(floor(1), 1, 'floor(1) === 1');
|
---|
| 45 | t.equal(floor(-1), -1, 'floor(-1) === -1');
|
---|
| 46 | t.equal(floor(1.1), 1, 'floor(1.1) === 1');
|
---|
| 47 | t.equal(floor(-1.1), -2, 'floor(-1.1) === -2');
|
---|
| 48 | t.equal(floor(maxValue), maxValue, 'floor(maxValue) === maxValue');
|
---|
| 49 | t.equal(floor(maxSafeInteger), maxSafeInteger, 'floor(maxSafeInteger) === maxSafeInteger');
|
---|
| 50 |
|
---|
| 51 | t.end();
|
---|
| 52 | });
|
---|
| 53 |
|
---|
| 54 | test('isFinite', function (t) {
|
---|
| 55 | t.equal(isFinite(0), true, 'isFinite(+0) === true');
|
---|
| 56 | t.equal(isFinite(-0), true, 'isFinite(-0) === true');
|
---|
| 57 | t.equal(isFinite(1), true, 'isFinite(1) === true');
|
---|
| 58 | t.equal(isFinite(Infinity), false, 'isFinite(Infinity) === false');
|
---|
| 59 | t.equal(isFinite(-Infinity), false, 'isFinite(-Infinity) === false');
|
---|
| 60 | t.equal(isFinite(NaN), false, 'isFinite(NaN) === false');
|
---|
| 61 |
|
---|
| 62 | forEach(v.nonNumbers, function (nonNumber) {
|
---|
| 63 | t.equal(isFinite(nonNumber), false, 'isFinite(' + inspect(nonNumber) + ') === false');
|
---|
| 64 | });
|
---|
| 65 |
|
---|
| 66 | t.end();
|
---|
| 67 | });
|
---|
| 68 |
|
---|
| 69 | test('isInteger', function (t) {
|
---|
| 70 | forEach([].concat(
|
---|
| 71 | // @ts-expect-error TS sucks with concat
|
---|
| 72 | v.nonNumbers,
|
---|
| 73 | v.nonIntegerNumbers
|
---|
| 74 | ), function (nonInteger) {
|
---|
| 75 | t.equal(isInteger(nonInteger), false, 'isInteger(' + inspect(nonInteger) + ') === false');
|
---|
| 76 | });
|
---|
| 77 |
|
---|
| 78 | t.end();
|
---|
| 79 | });
|
---|
| 80 |
|
---|
| 81 | test('isNaN', function (t) {
|
---|
| 82 | forEach([].concat(
|
---|
| 83 | // @ts-expect-error TS sucks with concat
|
---|
| 84 | v.nonNumbers,
|
---|
| 85 | v.infinities,
|
---|
| 86 | v.zeroes,
|
---|
| 87 | v.integerNumbers
|
---|
| 88 | ), function (nonNaN) {
|
---|
| 89 | t.equal(isNaN(nonNaN), false, 'isNaN(' + inspect(nonNaN) + ') === false');
|
---|
| 90 | });
|
---|
| 91 |
|
---|
| 92 | t.equal(isNaN(NaN), true, 'isNaN(NaN) === true');
|
---|
| 93 |
|
---|
| 94 | t.end();
|
---|
| 95 | });
|
---|
| 96 |
|
---|
| 97 | test('isNegativeZero', function (t) {
|
---|
| 98 | t.equal(isNegativeZero(-0), true, 'isNegativeZero(-0) === true');
|
---|
| 99 | t.equal(isNegativeZero(+0), false, 'isNegativeZero(+0) === false');
|
---|
| 100 | t.equal(isNegativeZero(1), false, 'isNegativeZero(1) === false');
|
---|
| 101 | t.equal(isNegativeZero(-1), false, 'isNegativeZero(-1) === false');
|
---|
| 102 | t.equal(isNegativeZero(NaN), false, 'isNegativeZero(NaN) === false');
|
---|
| 103 | t.equal(isNegativeZero(Infinity), false, 'isNegativeZero(Infinity) === false');
|
---|
| 104 | t.equal(isNegativeZero(-Infinity), false, 'isNegativeZero(-Infinity) === false');
|
---|
| 105 |
|
---|
| 106 | forEach(v.nonNumbers, function (nonNumber) {
|
---|
| 107 | t.equal(isNegativeZero(nonNumber), false, 'isNegativeZero(' + inspect(nonNumber) + ') === false');
|
---|
| 108 | });
|
---|
| 109 |
|
---|
| 110 | t.end();
|
---|
| 111 | });
|
---|
| 112 |
|
---|
| 113 | test('max', function (t) {
|
---|
| 114 | t.equal(max(1, 2), 2, 'max(1, 2) === 2');
|
---|
| 115 | t.equal(max(1, 2, 3), 3, 'max(1, 2, 3) === 3');
|
---|
| 116 | t.equal(max(1, 2, 3, 4), 4, 'max(1, 2, 3, 4) === 4');
|
---|
| 117 | t.equal(max(1, 2, 3, 4, 5), 5, 'max(1, 2, 3, 4, 5) === 5');
|
---|
| 118 | t.equal(max(1, 2, 3, 4, 5, 6), 6, 'max(1, 2, 3, 4, 5, 6) === 6');
|
---|
| 119 | t.equal(max(1, 2, 3, 4, 5, 6, 7), 7, 'max(1, 2, 3, 4, 5, 6, 7) === 7');
|
---|
| 120 |
|
---|
| 121 | t.end();
|
---|
| 122 | });
|
---|
| 123 |
|
---|
| 124 | test('min', function (t) {
|
---|
| 125 | t.equal(min(1, 2), 1, 'min(1, 2) === 1');
|
---|
| 126 | t.equal(min(1, 2, 3), 1, 'min(1, 2, 3) === 1');
|
---|
| 127 | t.equal(min(1, 2, 3, 4), 1, 'min(1, 2, 3, 4) === 1');
|
---|
| 128 | t.equal(min(1, 2, 3, 4, 5), 1, 'min(1, 2, 3, 4, 5) === 1');
|
---|
| 129 | t.equal(min(1, 2, 3, 4, 5, 6), 1, 'min(1, 2, 3, 4, 5, 6) === 1');
|
---|
| 130 |
|
---|
| 131 | t.end();
|
---|
| 132 | });
|
---|
| 133 |
|
---|
| 134 | test('mod', function (t) {
|
---|
| 135 | t.equal(mod(1, 2), 1, 'mod(1, 2) === 1');
|
---|
| 136 | t.equal(mod(2, 2), 0, 'mod(2, 2) === 0');
|
---|
| 137 | t.equal(mod(3, 2), 1, 'mod(3, 2) === 1');
|
---|
| 138 | t.equal(mod(4, 2), 0, 'mod(4, 2) === 0');
|
---|
| 139 | t.equal(mod(5, 2), 1, 'mod(5, 2) === 1');
|
---|
| 140 | t.equal(mod(6, 2), 0, 'mod(6, 2) === 0');
|
---|
| 141 | t.equal(mod(7, 2), 1, 'mod(7, 2) === 1');
|
---|
| 142 | t.equal(mod(8, 2), 0, 'mod(8, 2) === 0');
|
---|
| 143 | t.equal(mod(9, 2), 1, 'mod(9, 2) === 1');
|
---|
| 144 | t.equal(mod(10, 2), 0, 'mod(10, 2) === 0');
|
---|
| 145 | t.equal(mod(11, 2), 1, 'mod(11, 2) === 1');
|
---|
| 146 |
|
---|
| 147 | t.end();
|
---|
| 148 | });
|
---|
| 149 |
|
---|
| 150 | test('pow', function (t) {
|
---|
| 151 | t.equal(pow(2, 2), 4, 'pow(2, 2) === 4');
|
---|
| 152 | t.equal(pow(2, 3), 8, 'pow(2, 3) === 8');
|
---|
| 153 | t.equal(pow(2, 4), 16, 'pow(2, 4) === 16');
|
---|
| 154 | t.equal(pow(2, 5), 32, 'pow(2, 5) === 32');
|
---|
| 155 | t.equal(pow(2, 6), 64, 'pow(2, 6) === 64');
|
---|
| 156 | t.equal(pow(2, 7), 128, 'pow(2, 7) === 128');
|
---|
| 157 | t.equal(pow(2, 8), 256, 'pow(2, 8) === 256');
|
---|
| 158 | t.equal(pow(2, 9), 512, 'pow(2, 9) === 512');
|
---|
| 159 | t.equal(pow(2, 10), 1024, 'pow(2, 10) === 1024');
|
---|
| 160 |
|
---|
| 161 | t.end();
|
---|
| 162 | });
|
---|
| 163 |
|
---|
| 164 | test('round', function (t) {
|
---|
| 165 | t.equal(round(1.1), 1, 'round(1.1) === 1');
|
---|
| 166 | t.equal(round(1.5), 2, 'round(1.5) === 2');
|
---|
| 167 | t.equal(round(1.9), 2, 'round(1.9) === 2');
|
---|
| 168 |
|
---|
| 169 | t.end();
|
---|
| 170 | });
|
---|
| 171 |
|
---|
| 172 | test('sign', function (t) {
|
---|
| 173 | t.equal(sign(-1), -1, 'sign(-1) === -1');
|
---|
| 174 | t.equal(sign(+1), +1, 'sign(+1) === +1');
|
---|
| 175 | t.equal(sign(+0), +0, 'sign(+0) === +0');
|
---|
| 176 | t.equal(sign(-0), -0, 'sign(-0) === -0');
|
---|
| 177 | t.equal(sign(NaN), NaN, 'sign(NaN) === NaN');
|
---|
| 178 | t.equal(sign(Infinity), +1, 'sign(Infinity) === +1');
|
---|
| 179 | t.equal(sign(-Infinity), -1, 'sign(-Infinity) === -1');
|
---|
| 180 | t.equal(sign(maxValue), +1, 'sign(maxValue) === +1');
|
---|
| 181 | t.equal(sign(maxSafeInteger), +1, 'sign(maxSafeInteger) === +1');
|
---|
| 182 |
|
---|
| 183 | t.end();
|
---|
| 184 | });
|
---|
| 185 |
|
---|
| 186 | test('constants', function (t) {
|
---|
| 187 | t.equal(typeof maxArrayLength, 'number', 'typeof maxArrayLength === "number"');
|
---|
| 188 | t.equal(typeof maxSafeInteger, 'number', 'typeof maxSafeInteger === "number"');
|
---|
| 189 | t.equal(typeof maxValue, 'number', 'typeof maxValue === "number"');
|
---|
| 190 |
|
---|
| 191 | t.end();
|
---|
| 192 | });
|
---|