mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2026-03-02 03:49:24 +00:00
Add Decimal.isDecimal and config reset
This commit is contained in:
@@ -105,5 +105,40 @@ T('clone', function () {
|
||||
t(new D8(1).constructor !== new D9(1).constructor);
|
||||
|
||||
T.assertException(function () { Decimal.clone(null) }, "Decimal.clone(null)");
|
||||
|
||||
// defaults: true
|
||||
|
||||
Decimal.config({
|
||||
precision: 100,
|
||||
rounding: 2,
|
||||
toExpNeg: -100,
|
||||
toExpPos: 200,
|
||||
defaults: true
|
||||
});
|
||||
|
||||
t(Decimal.precision === 100);
|
||||
t(Decimal.rounding === 2);
|
||||
t(Decimal.toExpNeg === -100);
|
||||
t(Decimal.toExpPos === 200);
|
||||
t(Decimal.defaults === undefined);
|
||||
|
||||
D1 = Decimal.clone({ defaults: true });
|
||||
|
||||
t(D1.precision === 20);
|
||||
t(D1.rounding === 4);
|
||||
t(D1.toExpNeg === -7);
|
||||
t(D1.toExpPos === 21);
|
||||
t(D1.defaults === undefined);
|
||||
|
||||
D2 = Decimal.clone({ defaults: true, rounding: 5 });
|
||||
|
||||
t(D2.precision === 20);
|
||||
t(D2.rounding === 5);
|
||||
t(D2.toExpNeg === -7);
|
||||
t(D2.toExpPos === 21);
|
||||
|
||||
D3 = Decimal.clone({ defaults: false });
|
||||
|
||||
t(D3.rounding === 2);
|
||||
});
|
||||
|
||||
|
||||
@@ -338,5 +338,36 @@ T('config', function () {
|
||||
|
||||
t(9, {modulo: void 0});
|
||||
|
||||
// defaults
|
||||
|
||||
t = function (actual) {
|
||||
T.assert(actual);
|
||||
}
|
||||
|
||||
Decimal.config({
|
||||
precision: 100,
|
||||
rounding: 2,
|
||||
toExpNeg: -100,
|
||||
toExpPos: 200,
|
||||
});
|
||||
|
||||
t(Decimal.precision === 100);
|
||||
|
||||
Decimal.config({ defaults: true });
|
||||
|
||||
t(Decimal.precision === 20);
|
||||
t(Decimal.rounding === 4);
|
||||
t(Decimal.toExpNeg === -7);
|
||||
t(Decimal.toExpPos === 21);
|
||||
t(Decimal.defaults === undefined);
|
||||
|
||||
Decimal.rounding = 3;
|
||||
|
||||
Decimal.config({ precision: 50, defaults: true });
|
||||
|
||||
t(Decimal.precision === 50);
|
||||
t(Decimal.rounding === 4);
|
||||
|
||||
// Decimal.set is an alias for Decimal.config
|
||||
T.assertEqual(Decimal.set, Decimal.config);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
T('isFinite, isInteger, isNaN, isNegative, isZero', function () {
|
||||
T('isFinite, isInteger, isNaN, isNegative, isZero, isDecimal', function () {
|
||||
|
||||
function t(actual) {
|
||||
T.assert(actual);
|
||||
@@ -257,4 +257,22 @@ T('isFinite, isInteger, isNaN, isNegative, isZero', function () {
|
||||
t(!new Decimal('0.999999999999999999999').isInteger());
|
||||
t(new Decimal('4e4').isInteger());
|
||||
t(new Decimal('-4e4').isInteger());
|
||||
|
||||
// Decimal.isDecimal
|
||||
|
||||
t(Decimal.isDecimal(new Decimal(1)));
|
||||
t(Decimal.isDecimal(new Decimal('-2.3')));
|
||||
t(Decimal.isDecimal(new Decimal(NaN)));
|
||||
t(Decimal.isDecimal(new Decimal('Infinity')));
|
||||
|
||||
t(!Decimal.isDecimal());
|
||||
t(!Decimal.isDecimal(0));
|
||||
t(!Decimal.isDecimal(1));
|
||||
t(!Decimal.isDecimal('-2.3'));
|
||||
t(!Decimal.isDecimal(NaN));
|
||||
t(!Decimal.isDecimal(Infinity));
|
||||
t(!Decimal.isDecimal(undefined));
|
||||
t(!Decimal.isDecimal({}));
|
||||
t(!Decimal.isDecimal({isDecimal: true}));
|
||||
t(!Decimal.isDecimal(new Number(4)));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user