mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2024-10-27 20:34:12 +00:00
refactor tests
This commit is contained in:
parent
587b9fe82f
commit
caad23d669
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('Decimal');
|
||||
T('Decimal', function () {
|
||||
|
||||
Decimal.config({
|
||||
precision: 40,
|
||||
@ -286,6 +285,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal('--45')}, "'--45'");
|
||||
tx(function () {new Decimal('9.99--')}, "'9.99--'");
|
||||
tx(function () {new Decimal('0 0')}, "'0 0'");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('absoluteValue');
|
||||
T('absoluteValue', function () {
|
||||
|
||||
function t(expected, value){
|
||||
T.assertEqual(expected, new Decimal(value).abs().valueOf());
|
||||
@ -123,6 +122,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('Infinity', '1E9000000000000001');
|
||||
t('Infinity', '-1e+9000000000000001');
|
||||
t('5.5879983320336874473209567979e+287894365', '-5.5879983320336874473209567979e+287894365');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('acos');
|
||||
T('acos', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1002,6 +1001,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.31503731586271512953987', 175, 1, '1.250300355040444140384875969127128388865582776679385514007352971948442243497048855209710989127061157111853695806290441906793238123959427914022156720058162558731327402523044166');
|
||||
t('-0.07853007897317622293045558522251526660194271081717322978', 173, 6, '1.6494073460738196727474653405568328128478576667816496188558018754785734688662650493515246411034101302768235838373499639808407336300758786703980995090099910486541663777946303');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('acosh');
|
||||
T('acosh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1022,6 +1021,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('33510010000000000000000000000000000000000000000000000000000020000000000000.00000000000000000000000000600000000000000000000000000000005000000000000000000070000000000000000000000000000000000000000000000000000050000000006', 74, 4, '169.99111807629879163625974865178022321947192724289646534209273324929519275');
|
||||
t('738.245', 160, 1, '7.297422469676460057258935714571304875282754408306560497316807162261123406168435263072369509041475105737583484684091946392872408276514681369949082374827023560118');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('asin');
|
||||
T('asin', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1022,6 +1021,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.3896123202596462640243469782579072859666092096691018020981352451', 145, 6, '0.4002106120989776668931051758718787991367561875356896388646369850676906617494355205656926402325949310714153999882796007787625156219933889017506432');
|
||||
t('-0.303', 254, 3, '-0.30783907040876792121510536109523187982242884051368525496594226813212357419698266185959575883139074602781263663734367163737121385086938445928188265807214271585884836376698829544634456224901961507384983017559267905307575220542265905880239862946724365803028');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('asinh');
|
||||
T('asinh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1022,6 +1021,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('959363.783043541639323072180147603753657', 86, 3, '14.46717279830797941955692793012557501799148538229744443631547327264748755583447284086');
|
||||
t('-0.00014646860007896', 75, 1, '-0.000146468599555260285150687195543516588439055126517399139386767315063352429473');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('atan');
|
||||
T('atan', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1022,6 +1021,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('3354394611.3881376899877988616872259938319601369880849669', 192, 6, '1.57079632649678023286311994686956477646841465294402178072486209203158561050535190334941645352828522534616019819595242460960399719839223416641338127323237484479240504069592160103902872927414134');
|
||||
t('787999999999999.59599999999999999999599999', 269, 0, '1.570796326794895350195788696715242951799942632473570555828022068752453304518753743626963506458329696080367499278430250428911442467137500277453786256757478954349115317731282586220585062639343019901985681043325797039758633135701387951803927390125479834754313536831194609');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('atan2');
|
||||
T('atan2', function () {
|
||||
|
||||
function t(y, x, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1054,6 +1053,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('67381111111111111111', '2', 235, 5, '1.570796326794896619201639782763211693075565254889511026429926110525705919896593801691189227911950841228275003643935654428367121002853687190621360713931591682143109405062846172592007176046070894191718933231800595180657008817073239215772');
|
||||
t('811522222222222222222222222222222222222422222222222222222222222222282.422222222', '-5222222222416415910444444444444.729788169848249155', 35, 1, '1.5707963267948966192313216916397514');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('atanh');
|
||||
T('atanh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1021,6 +1020,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.0797', 253, 2, '0.07986939995414175208043904996845297385460176169003718353939128767528755481938934497755555209020339850238364350758547886230285042384986659961301325714649732629177151058324339115858308507429728549405136892851728167228522469101443134231829493416267582123405');
|
||||
t('-0.1089752190313487560903960981844967611', 252, 5, '-0.109409701076893642220104058960155361324700274686560960807249771106995187215844080992753719826712933129477615536055983708257302997211720560529849083931589160406353980591055978490033770426423393286285330382391246639425123267777577081284158212108941527682');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('cubeRoot');
|
||||
T('cubeRoot', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -1012,6 +1011,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.957879295825927826142564373360821131270801415966019238713966', 109, 5, '0.9857578905388967230426246816655261862702534477973555994356503867232804550175012371428559636272064749391546019');
|
||||
t('-274794195303195669383690179150393637278', 61, 0, '-6501334600143.956003508608845101493972662138482039189675231797');
|
||||
*/
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('ceil');
|
||||
T('ceil', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, new Decimal(n).ceil().valueOf());
|
||||
@ -69,6 +68,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('9105942082143427451223', '9105942082143427451223');
|
||||
t('276312604693909858428', '276312604693909858427.21965306055697011390137926559');
|
||||
t('1', '0.0000252');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('clone');
|
||||
T('clone', function () {
|
||||
|
||||
function t(expression) {
|
||||
T.assert(expression);
|
||||
@ -106,7 +105,5 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t(new D8(1).constructor !== new D9(1).constructor);
|
||||
|
||||
T.assertException(function () { Decimal.clone(null) }, "Decimal.clone(null)");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('comparedTo');
|
||||
T('comparedTo', function () {
|
||||
|
||||
var N = NaN, I = Infinity;
|
||||
|
||||
@ -1024,6 +1023,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-3.292e-15', '-2.2e-1', 1);
|
||||
t('-9.29480350675e-6', '9.4830355594e+4', -1);
|
||||
t('-2.49267401e-19', '3.3296905e+4', -1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('config');
|
||||
T('config', function () {
|
||||
|
||||
var MAX_DIGITS = 1e9;
|
||||
var EXP_LIMIT = 9e15;
|
||||
@ -342,6 +341,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {Decimal.config({modulo: Infinity})}, "modulo: Infinity");
|
||||
|
||||
t(9, {modulo: void 0});
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('cos');
|
||||
T('cos', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -121,6 +120,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.10859933721171128209598967066', 80, 4, '0.99410888528803407646108267824473898405842663808987770888683180574685964084716924');
|
||||
t('2813920.875088303362819', 33, 2, '-0.866254989781355498995879756871368');
|
||||
t('35999999999999999999999999999999999999999.999999999999999999999999919', 38, 3, '-0.9562598584240982386154988349219959087');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('cosh');
|
||||
T('cosh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -119,6 +118,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.9', 103, 1, '1.433086385448774387841790401624048341627737841305230594247417192533449635356864305114609711796244033432');
|
||||
t('-0.833291445811118155331699076307265315671094768698998', 48, 2, '1.36774796193155903463660933986762434999452033326');
|
||||
t('-0.7', 66, 6, '1.25516900563094301816467474099029711586260477992884178681185039895');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('dividedBy');
|
||||
T('dividedBy', function () {
|
||||
|
||||
Decimal.config({
|
||||
precision: 40,
|
||||
@ -1042,6 +1041,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('4.4513588705101755662795e+635486688804809', '-6.556877492876530213198836587854853e-4323337939', '-6.78883946717959097065518224297035382056172928446181486912391244568509234794436034526869106696e+635491012142747', 93, 4);
|
||||
t('-6.16322132e+994316265', '-4.3969e-2987200797', '1.4017196934203643476085423e+3981517062', 26, 1);
|
||||
t('-8.332e+2033', '-5.24183781e-7534', '1.5895188485429311671129328589432262498789522829589418372332279392e+9567', 65, 2);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('dividedToIntegerBy');
|
||||
T('dividedToIntegerBy', function () {
|
||||
|
||||
function t(dividend, divisor, expected) {
|
||||
T.assertEqual(expected, new Decimal(dividend).divToInt(divisor).valueOf());
|
||||
@ -1016,6 +1015,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('8200969461.781648200152056735094101250', '-6173584.6386638', '-1.328e+3');
|
||||
t('-6162044682.46579949512756133331211291134216377880642', '70883.101619290546467', '-8.6932e+4');
|
||||
t('2.2858509075765580228170996569682255', '7.024E-8', '3.2543435e+7');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('decimalPlaces and precision');
|
||||
T('decimalPlaces and precision', function () {
|
||||
|
||||
function t(n, dp, sd, zs) {
|
||||
T.assertEqual(dp, new Decimal(n).dp());
|
||||
@ -68,6 +67,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal(1).sd(2)}, "new Decimal(1).sd(2)");
|
||||
tx(function () {new Decimal(1).sd('3')}, "new Decimal(1).sd('3')");
|
||||
tx(function () {new Decimal(1).sd({})}, "new Decimal(1).sd({})");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('exp');
|
||||
T('exp', function () {
|
||||
|
||||
function t(n, expected, pr, rm) {
|
||||
Decimal.precision = pr;
|
||||
@ -139,6 +138,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('8.82661445434039879925209590467500361019097244359748402', '6.813181388774733211e+3', 19, 6);
|
||||
t('9.02366224E-9', '1.00000000902366228071324023326175156155718e+0', 43, 6);
|
||||
t('-4.4768686752786086271180252E+574398129049502', '0e+0', 15, 3);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('floor');
|
||||
T('floor', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, new Decimal(n).floor().valueOf());
|
||||
@ -123,6 +122,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-Infinity', '-1e+9000000000000001');
|
||||
t('5.5879983320336874473209567979e+287894365', '5.5879983320336874473209567979e+287894365');
|
||||
t('-5.5879983320336874473209567979e+287894365', '-5.5879983320336874473209567979e+287894365');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('fromJSON');
|
||||
T('fromJSON', function () {
|
||||
|
||||
Decimal.config({
|
||||
precision: Math.random() * 40 + 1 | 0,
|
||||
@ -41,6 +40,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
*/
|
||||
T.assert(r.eq(fromJ));
|
||||
}
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('hypot');
|
||||
T('hypot', function () {
|
||||
|
||||
function t(a, b, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -119,6 +118,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.4519719010451812700381881242155284703426402593258190987', '92346327717009585478189395590602.34545881237122995324639951758026247635570631069180557087', 55, 4, '92346327717009585478189395590602.3454588123712299532464');
|
||||
t('69398002688216703269792743800286307271116693445111111111111111', '-211393667179764005100083390018873694', 100, 0, '69398002688216703269792743800286307271116693445111111433074862.06409526630410784634920186057594444197');
|
||||
t('0.19', '-5288.143883', 42, 3, '5288.14388641329593020355143132324946951485');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -2,8 +2,7 @@
|
||||
// Also tests each Decimal.prototype method against its equivalent Decimal method where applicable.
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('immutability');
|
||||
T('immutability', function () {
|
||||
|
||||
Decimal.config({
|
||||
precision: 20,
|
||||
@ -157,7 +156,7 @@ if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
T.assertEqual(x, y);
|
||||
|
||||
// Omit these hyperbolic methods if a is large, as they are too time-consuming.
|
||||
// Omit hyperbolic methods if a is large, as they are too time-consuming.
|
||||
if (a.abs().lt(1000)) {
|
||||
x = a.hyperbolicCosine();
|
||||
t(a, aa);
|
||||
@ -547,9 +546,7 @@ if (typeof T === 'undefined') require('../setup');
|
||||
Decimal.sign(a);
|
||||
t(a, aa);
|
||||
}
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
/*
|
||||
// All methods tested above except:
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('integer pow');
|
||||
T('integer pow', function () {
|
||||
|
||||
// Highest finite exponent here is 100
|
||||
function t(expected, n, exp) {
|
||||
@ -133,7 +132,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-1.331', '-1.1', 3);
|
||||
t('5.125696', '-2.264', 2);
|
||||
t('6.7266e-7', '6.7266E-7', 1);
|
||||
t('1', '-1', 8);
|
||||
t('4142779.6499215776', '21.06', 5);
|
||||
t('731.1616', '-5.2', 4);
|
||||
t('1', '61818', 0);
|
||||
@ -157,7 +155,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('4.122181458338334221291398681640625e+27', '40042.5', 6);
|
||||
t('5.94467302491009e+21', '1290.0', 7);
|
||||
t('5.6599836943004175019970957e+25', '141437', 5);
|
||||
t('9', '3', 2);
|
||||
t('69.75757441', '1.7', 8);
|
||||
t('1e-42', '0.0000010', 7);
|
||||
|
||||
@ -184,8 +181,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('287803125756.085809269657829376', '18.76', 9);
|
||||
t('4.1069049025e-34', '-2.02655E-17', 2);
|
||||
t('-8', '-2', 3);
|
||||
t('-5.0787635527751e-52', '-5.51E-11', 5);
|
||||
t('-8', '-2', 3);
|
||||
t('1704883919.2576', '203.2', 4);
|
||||
t('22106814.0740608', '11.2', 7);
|
||||
t('3.7481851264119295287828498195966142655968201e+23', '227.71', 10);
|
||||
@ -204,7 +199,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('2206809.987903620081317314341735861401', '4.309', 10);
|
||||
t('6.1917364224e-80', '-1.2E-8', 10);
|
||||
t('64', '-2', 6);
|
||||
t('-1', '-1', 7);
|
||||
t('-39.8778220049', '-2.09', 5);
|
||||
t('892496818.033068251283537321', '-31.029', 6);
|
||||
t('1.1289646949223432899980166202016362758071452681629968849e+25', '320.087', 10);
|
||||
@ -316,7 +310,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('6.192736416792149755132475219493405669399778858602560762871794455317449717448580836229845787580888290473782381059983387805505374173265513677435445890655671110840202944429668728225878544903602239e-270', '0.000319', 77);
|
||||
t('2.321827472731847506187210910989207010589651530892302311791322352855446782760907718473019283821056753242967949096791603718944064726033664384082861996009850744961116407128920163494805886357836270766853975184523023642990429569615539676822828070446559161161124635674389704743948383107212919966543969471039720464085404567773913503635201792672811032312063265454094042341369554833714443413857449688164664657173315113983032808001e+220', '159.83', 100);
|
||||
t('4.953736650985698001275587761883016173298229503362193331584010106486052779761329981195411366329068322677550960044762649449732919438910119549694010717647780952298320287365138145210431380601324547389442337520392258009e+27', '-2.797', 62);
|
||||
t('-338678221586896.02233451034424755534030583977124338116841050703894756829829935320421996887', '-2.47', 37);
|
||||
t('-3.181403788572786716059998378326698266679069780899509454959934125355133265193e-226', '-0.0000057', 43);
|
||||
t('2.2481244795444847556680083178853571141700204725943661497539185751725919215990484669445118877448657555202573745174750533635052209260608084995835891707958259234271442982681066779696130155696868114346639852814575962457281749995256623713554214237458259176913852401064878760784275382146658972801541462348779288776844691139086889351786721e+179', '229.03', 76);
|
||||
t('1.09544203269304121665791452848994634135137143229447033238750572549632571476402641497730897157401184093614916314911584167715115647604065370616785146866296916632437569033863034458711783186506727022529378159297811462454675308057682780534190256280910865229376785975491743196806996272790525705427972427376758443312371576466422700240638756574402393677191376501159420836822933903938571935476091044876631814554274289087939783553959776485376e+31', '-2.0436', 100);
|
||||
@ -383,7 +376,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-4.429293345196932276984549040219058245905488651609667018402382745119170674779904528756935495114384894434070998056621967747005022674509457845620395626349316891933712941619646377506486625368600115937614507993729672492431012578899815005421568e+37', '-32.051870380', 25);
|
||||
t('1.299270565684257922619246441017034698039805547412943905460754496572097300952165266370194652051376805296279609746312644347199238836765289306640625e+56', '-18.85', 44);
|
||||
t('1.566108714385843340192620380546546555641735293434509574033302065853656477829384746549085411912657151882140111651595251043453318950397645765893613409097202898027341727466585518405768283017471302953847629952837298920882176e+24', '41.0192888808596', 15);
|
||||
t('2.61958676888190130160363553014940478261307337527924200329289138176e+65', '-1866', 20);
|
||||
t('3.23590932372253866812859949454563891250217856922745576253641197253435665205998361592799809e+89', '2474977', 14);
|
||||
t('-9.7368504802272205153595678239454304952368475046930119079817985916928e+67', '-12', 63);
|
||||
t('3.44552147465294110719732986332367243247925798357929806000836849e+62', '-7', 74);
|
||||
@ -562,9 +554,7 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal('12.345').pow(new Date)}, ".pow(new Date)");
|
||||
tx(function () {new Decimal('12.345').pow(new RegExp)}, ".pow(new RegExp)");
|
||||
tx(function () {new Decimal('12.345').pow(function (){})}, ".pow(function (){})");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
/*
|
||||
Notes:
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('isFinite, isInteger, isNaN, isNegative, isZero');
|
||||
T('isFinite, isInteger, isNaN, isNegative, isZero', function () {
|
||||
|
||||
function t(actual) {
|
||||
T.assert(actual);
|
||||
@ -258,6 +257,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t(!new Decimal('0.999999999999999999999').isInteger());
|
||||
t(new Decimal('4e4').isInteger());
|
||||
t(new Decimal('-4e4').isInteger());
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('ln');
|
||||
T('ln', function () {
|
||||
|
||||
function t(n, expected, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -536,6 +535,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('9.9102170675767525486462268743104768E+722282888', '2e+9', 1, 5);
|
||||
t('88.7213950103796184597368396487398', '4.4855e+0', 5, 1);
|
||||
t('8.245971550E+8358202', '1.92454734391578027453548100134030572e+7', 36, 2);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('log');
|
||||
T('log', function () {
|
||||
|
||||
function t(n, base, expected, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -274,6 +273,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('16205.492', 2, '13.984195201', 11, 3);
|
||||
t('17578.3501161869916711', 2, '14.101512046680555', 18, 3);
|
||||
t('5661.58', 2, '12.466989012642603919950322048', 29, 1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('log10');
|
||||
T('log10', function () {
|
||||
|
||||
function t(n, expected, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -518,6 +517,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('8.01844860599820804155768000879876725329864650214532E+436946856', '4.36946856904090349951357241211271e+8', 33, 2);
|
||||
t('5.5574947893333547365232067522673911E+7059', '7.05974487906417987536846332910957964e+3', 36, 5);
|
||||
t('9.552816484569040E+6270', '6.2709801314347641e+3', 17, 0);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('log2');
|
||||
T('log2', function () {
|
||||
|
||||
function t(n, expected, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -173,6 +172,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('6.999992707421e-9095', '-3.02101286695814990981946878100430318253824323913669024362543485421644529066733767002654624094e+4', 93, 6);
|
||||
t('6.573152030373740763721111111111111111111111111111111111111111111111056e-77071', '-2.56021603615710387e+5', 18, 1);
|
||||
t('7.000003608682e589878', '1.959535108111633331253094708685915889078e+6', 40, 2);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('min and max');
|
||||
T('min and max', function () {
|
||||
|
||||
function t(min, max, arr) {
|
||||
T.assertEqual(new Decimal(max).valueOf(), Decimal.max.apply(Decimal, arr).valueOf());
|
||||
@ -73,6 +72,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t(0, 1, [1, '1e-9000000000000001', 1e-200]);
|
||||
t(-0, 1, [1, '-1e-9000000000000001', 1e-200]);
|
||||
t(-3, 3, [1, '2', 3, '-1', -2, '-3']);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('minus');
|
||||
T('minus', function () {
|
||||
|
||||
var t = function (minuend, subtrahend, expected) {
|
||||
T.assertEqual(expected, new Decimal(minuend).minus(subtrahend).valueOf());
|
||||
@ -1045,6 +1044,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-6.1868661228611360547121138333173109576855395466826784e-9251', '-3.3407355564230790311536623458601152993159e-206708339', '-6.18686612286113605471211383331731095768553954668267839999999999999999999e-9251', 72, 2);
|
||||
t('-8.2894772800817807e-795566101', '-882094911847133130492689954681328382693767501748865135497984118817292143479942556093392300518133.40', '8.820949118471331304926899546813283826937675017488651354979841188172921434799425560933923005181334e+95', 97, 2);
|
||||
t('-3.71e-54', '8.1409094135303963371158960125104271236131e-52265', '-3.710000000000000000000000000000000000000000000000000000000000001e-54', 64, 3);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('modulo');
|
||||
T('modulo', function () {
|
||||
|
||||
var t = function (a, b, expected, sd, rm) {
|
||||
T.assertEqual(expected, new Decimal(a).mod(b).valueOf());
|
||||
@ -1074,6 +1073,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-6.00559063113006083268308811806162403396832594e+7303', '-526206391770735839309548148095066062264265607373.735063960260', '-2.5090125586506678664e+47', 20, 6);
|
||||
t('-2.2567835144492993286994200e+573', '3.86e+19', '-2.72e+19', 56, 0);
|
||||
t('45.40437334953326105840633843242', '8.165685418205048453423994094023522482e+91', '4.540437334953326105840633843242e+1', 55, 6);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('negated');
|
||||
T('negated', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, new Decimal(n).neg().valueOf());
|
||||
@ -221,6 +220,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-2.9e+0', '2.9e+0');
|
||||
t('-1.764e+3', '1.764e+3');
|
||||
t('9.3418332730097368870513138581415704704611459349313e+49', '-9.3418332730097368870513138581415704704611459349313e+49');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('plus');
|
||||
T('plus', function () {
|
||||
|
||||
var t = function (addendA, addendB, expected) {
|
||||
T.assertEqual(expected, new Decimal(addendA).plus(addendB).valueOf());
|
||||
@ -1041,6 +1040,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-3.60348795228017780049569753533186294E+499', '8.80786821E+82223318', '8.80786821e+82223318', 28, 0);
|
||||
t('-9.8967145096522848735804634E+98677519', '-8.39861E+5784323495519916', '-8.39e+5784323495519916', 3, 1);
|
||||
t('-5.54480709948277E-718373854', '-7.119627881088288640389987E-896127305535', '-5.54480709948277e-718373854', 56, 6);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('pow');
|
||||
T('pow', function () {
|
||||
|
||||
t = function (base, exp, expected, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -127,6 +126,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('908948247.896330216349750387912923575076135766138', '11.38907521122213262858256836', '1.0702278292293091784680297675223031e+102', 35, 3);
|
||||
t('4.485925762349120387154391E+47', '1677945.16766265206929939', '8.53959030215133943e+79957194', 18, 5);
|
||||
t('2.8448989811706207675566E+89', '2.368592228588521845032068137267440272102614', '7.58940197453762187722508511706932e+211', 33, 5);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('pow against sqrt');
|
||||
T('pow against sqrt', function () {
|
||||
|
||||
Decimal.config({
|
||||
toExpNeg: -7,
|
||||
@ -36,7 +35,5 @@ if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
T.assertEqual(p.valueOf(), s.valueOf());
|
||||
}
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('random');
|
||||
T('random', function () {
|
||||
var i, sd, maxDigits;
|
||||
|
||||
function tx(fn, msg) {
|
||||
T.assertException(fn, msg);
|
||||
}
|
||||
|
||||
var i, sd, maxDigits = 100;
|
||||
maxDigits = 100;
|
||||
|
||||
for (i = 0; i < 996; i++) {
|
||||
Decimal.crypto = Math.random() > 0.5;
|
||||
sd = Math.random() * maxDigits + 1 | 0;
|
||||
|
||||
if (Math.random() > 0.5) {
|
||||
@ -27,6 +26,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () { Decimal.random('-Infinity') }, "'-Infinity'");
|
||||
tx(function () { Decimal.random(NaN) }, 'NaN');
|
||||
tx(function () { Decimal.random(null) }, 'null');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('round');
|
||||
T('round', function () {
|
||||
|
||||
function t(expected, n, rm) {
|
||||
Decimal.rounding = rm;
|
||||
@ -521,6 +520,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('42601873172232953', '42601873172232953.30659313764825104206642999', 3);
|
||||
t('1.8171003585956362231021760046143097114054128693433487680606690918875530579038e+76', '1.81710035859563622310217600461430971140541286934334876806066909188755305790370439773413227239119191673971090333e+76', 2);
|
||||
t('3.71331955392433687189949e+23', '3.7133195539243368718994912855e+23', 6);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('sign');
|
||||
T('sign', function () {
|
||||
|
||||
function t(n, expected) {
|
||||
T.assertEqual(expected, Decimal.sign(n));
|
||||
@ -25,6 +24,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-1', -1);
|
||||
t('9.99', 1);
|
||||
t('-9.99', -1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('sin');
|
||||
T('sin', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -120,6 +119,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('22011131111011111.111111611113111111111151111111', 143, 2, '0.82582504036277799386306063085803210583251158969990606609364360685569588545519071481543672724620118406694191888115120286393881609546697317692404');
|
||||
t('996270725099515169352424536636186062915113219400094989.8763797268889422850038402633796294758036260533902551191769915343780424028900449342752548782035', 46, 2, '0.6613706114081017074779805460666900787572253475');
|
||||
t('0.780360750628373', 37, 5, '0.7035358359376557390803090830882458906');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('sinh');
|
||||
T('sinh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -119,6 +118,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.3531311134837489181774304448792305788668900001541312879645273208393370689493465894263207269785178211563373399080451907494623164005742217451839584169072958609799133150259273', 104, 0, '0.36051634575023901465038196038262241500129988486533222911437937013660152976667815350655235742420924031229');
|
||||
t('0.04434967092552732411292905', 99, 2, '0.0443642108672289452509083305837598955470962269229557910757510910026528522969230426477915847556546583');
|
||||
t('-0.20001290733229792426683137634566153903', 21, 4, '-0.201349168898446405328');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('sqrt');
|
||||
T('sqrt', function () {
|
||||
|
||||
function t(expected, n, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -541,6 +540,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('2.7450159803706115172884307982554068123557452994357916574e+29493402848956', '7.535112732490029474794930517417328483099871453263111571224994801873955541077813E+58986805697912', 56, 1);
|
||||
t('8.450708163926728117884231904577733365414280601e-3356220959', '7.1414468471857852311230634694477427663911004991250862311231174531532437446075636178902521E-6712441917', 46, 2);
|
||||
t('2.21717604626595076e+2233028', '4.91586962013551338731303957E+4466056', 18, 2);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('tan');
|
||||
T('tan', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -119,6 +118,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('6587685840713754402278094276205491723366077405819490595067025408026873250375623638673063957701601231', 107, 3, '0.88106648906135934944047838538886082156746682725824571546159607795133625640190620741982638843180493222615294');
|
||||
t('0.524217411165998018391262237830297491516856805040463896080592290487405064611025001607311512479709354535407130581948832593516281243820812174844723190311545869854968531247730387537943969800839367585396013641826800875467649274673709974876292276089324234102809573076731030535244688816', 76, 3, '0.5781754114340578960371795632804762026798421163023137415437904934165060267084');
|
||||
t('323646192595.4845', 127, 6, '-0.3747612268270038347175054875779625030989108207803221587812055629899198693615407534041949990189331417585285760850333254670480789');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('tanh');
|
||||
T('tanh', function () {
|
||||
|
||||
function t(n, pr, rm, expected) {
|
||||
Decimal.precision = pr;
|
||||
@ -119,7 +118,5 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-0.50752591', 24, 5, '-0.468015268006387507893896');
|
||||
t('-0.54917290836787549931392', 88, 4, '-0.49990006636857985687649939062630289074578706968740926592041362893811220431493732027711');
|
||||
t('0.91999661041886666', 17, 6, '0.72589581132601256');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('times');
|
||||
T('times', function () {
|
||||
|
||||
var t = function (multiplicand, multiplier, expected) {
|
||||
T.assertEqual(expected, new Decimal(multiplicand).times(multiplier).valueOf());
|
||||
@ -1034,6 +1033,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-7.278632E+684731572310999', '-1.70098296173502667080983368271858703080836592E-67129927', '1.23808290167393406470099213577133545572e+684731505181073', 39, 3);
|
||||
t('3.62481321880718463782470515258531161626837808157570536E+135011330', '3.70907770474907003605508735070520261968241E-9929696201', '1.3444713893757440983671783972567382e-9794684870', 35, 6);
|
||||
t('-0.000814586801311722298757051', '-4.6011129412495143332669917195124045818036E-4163600013', '3.74800587328641232642672141632691e-4163600016', 34, 4);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toBinary');
|
||||
T('toBinary', function () {
|
||||
|
||||
var t = function (expected, n, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -357,6 +356,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0b1.10110111p-1', '0.857421875', 9, 4);
|
||||
|
||||
t('0b1.001010101110101p-4', '0b1.001010101110101p-4', 16, 1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toDecimalPlaces');
|
||||
T('toDecimalPlaces', function () {
|
||||
|
||||
function t(expected, n, dp, rm) {
|
||||
T.assertEqual(expected, new Decimal(n).toDP(dp, rm).valueOf());
|
||||
@ -529,6 +528,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal('12.345').toDP(1, '-1e-1')}, ".toDP(1, '-1e-1')");
|
||||
tx(function () {new Decimal('12.345').toDP(1, Infinity)}, ".toDP(1, Infinity)");
|
||||
tx(function () {new Decimal('12.345').toDP(1, '-Infinity')}, ".toDP(1, '-Infinity')");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toExponential');
|
||||
T('toExponential', function () {
|
||||
|
||||
function t(expected, n, dp) {
|
||||
T.assertEqual(expected, new Decimal(n).toExponential(dp));
|
||||
@ -553,6 +552,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal(1.23).toExponential(1, '-1e-1')}, ".toExponential(1, '-1e-1')");
|
||||
tx(function () {new Decimal(1.23).toExponential(1, Infinity)}, ".toExponential(1, Infinity)");
|
||||
tx(function () {new Decimal(1.23).toExponential(1, '-Infinity')}, ".toExponential(1, '-Infinity')");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toFixed');
|
||||
T('toFixed', function () {
|
||||
|
||||
function t(expected, n, dp) {
|
||||
T.assertEqual(expected, new Decimal(n).toFixed(dp));
|
||||
@ -567,6 +566,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('1.00000000000000000000', '1.000000000000000000005', 20);
|
||||
t('-1.00000000000000000', '-1.000000000000000000005', 17);
|
||||
t('-1.00000000000000000001', '-1.000000000000000000005', 20);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toFraction');
|
||||
T('toFraction', function () {
|
||||
|
||||
function t(expected, n, maxDenominator) {
|
||||
T.assertEqual(expected, new Decimal(n).toFraction(maxDenominator).toString());
|
||||
@ -229,6 +228,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal('123.45').toFraction(-23)}, ".toFraction(-23)");
|
||||
tx(function () {new Decimal('123.45').toFraction(Infinity)}, ".toFraction(Infinity)");
|
||||
tx(function () {new Decimal('123.45').toFraction('-Infinity')}, ".toFraction('-Infinity')");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toHex');
|
||||
T('toHex', function () {
|
||||
|
||||
var t = function (expected, n, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -340,6 +339,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0x1.921fb4d12d84ap+1', '3.1415926', 14, 4);
|
||||
t('0x1.5b23a8dd37fc2p-10', '0.001324231321', 14, 4);
|
||||
t('0x1.81016cc52538ap+9', '770.0111319', 14, 4);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toJSON');
|
||||
T('toJSON', function () {
|
||||
|
||||
function t(n, expected) {
|
||||
T.assertEqual(expected, new Decimal(n).toJSON());
|
||||
@ -87,7 +86,5 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0.00000009876543212345678987654321', 'h8J+]nxS}gN-^oN');
|
||||
t('-0.00000009876543212345678987654321', 'N8J+]nxS}gN-^oN');
|
||||
t('1.00000009876543212345678987654321', '-7$yQ@UAPUk2SZ#XQh');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toNearest');
|
||||
T('toNearest', function () {
|
||||
|
||||
function isMinusZero(n) {
|
||||
return n.isZero() && n.isNegative();
|
||||
@ -152,6 +151,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('42840000000000000', '42835000000000001', '1e+13', 2, 1);
|
||||
t('42840000000000000', '42835000000000000.0002', '1e+13', 200, 0);
|
||||
t('42840000000000000', '42835000000000000.0002', '1e+13', 200, 1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toNumber');
|
||||
T('toNumber', function () {
|
||||
|
||||
Decimal.config({
|
||||
precision: 20,
|
||||
@ -75,6 +74,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-9.999999e+9000000000000000', -1 / 0);
|
||||
t('1e-9000000000000000', 0);
|
||||
t('-1e-9000000000000000', -0);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toOctal');
|
||||
T('toOctal', function () {
|
||||
|
||||
var t = function (expected, n, sd, rm) {
|
||||
Decimal.precision = sd;
|
||||
@ -323,6 +322,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('0o1.556p-1', '0.857421875', 40, 4);
|
||||
|
||||
t('0o1.777p-4', '0o1.777p-4', 4, 1);
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toPrecision');
|
||||
T('toPrecision', function () {
|
||||
|
||||
function t(expected, n, sd, rm) {
|
||||
T.assertEqual(expected, new Decimal(n).toPrecision(sd, rm));
|
||||
@ -565,6 +564,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal(1.23).toPrecision(1, '-1e-1')}, ".toPrecision(1, '-1e-1')");
|
||||
tx(function () {new Decimal(1.23).toPrecision(1, Infinity)}, ".toPrecision(1, Infinity)");
|
||||
tx(function () {new Decimal(1.23).toPrecision(1, '-Infinity')}, ".toPrecision(1, '-Infinity')");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toSignificantDigits');
|
||||
T('toSignificantDigits', function () {
|
||||
|
||||
function t(expected, n, sd, rm) {
|
||||
T.assertEqual(expected, new Decimal(n).toSD(sd, rm).valueOf());
|
||||
@ -369,7 +368,6 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('54564000000000000000000000000000000000', '54563203006377285590954695127259934956.72304700', 5, 2);
|
||||
t('937851991874226678.2', '937851991874226678.191965007088457', 19, 0);
|
||||
t('9141378468539383564638997660000', '9141378468539383564638997666387.513564869223', 27, 1);
|
||||
t('5140000000000000000000000', '5143738381911696659148152.2424402227698278853166', 3, 3);
|
||||
t('20497199023806.45608949', '20497199023806.45608949227987004920339939', 22, 5);
|
||||
t('81603182.7', '81603182.616632542195753770061305729184', 9, 2);
|
||||
t('1288222268118280000000000000000000000000', '1288222268118271079758562419926059399472.4003871704903395624929468673346838726', 15, 2);
|
||||
@ -551,6 +549,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
tx(function () {new Decimal('12.345').toSD('-1e-1')}, ".toSD('-1e-1')");
|
||||
tx(function () {new Decimal('12.345').toSD(Infinity)}, ".toSD(Infinity)");
|
||||
tx(function () {new Decimal('12.345').toSD('-Infinity')}, ".toSD('-Infinity')");
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('toString');
|
||||
T('toString', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, new Decimal(n).toString());
|
||||
@ -360,6 +359,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('1.2391599841950849289559651456348e+9', '1239159984.1950849289559651456348');
|
||||
t('1.72220118427662724614289256133342842086e+22', '17222011842766272461428.9256133342842086');
|
||||
t('1.512063585971680294584184272035496e+15', '1512063585971680.294584184272035496');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('trunc');
|
||||
T('trunc', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, Decimal.trunc(n).valueOf());
|
||||
@ -83,12 +82,10 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('4125789711001606948191', '4125789711001606948191.4707575965791242737346836');
|
||||
t('-6935501', '-6935501.294727166142750626019282');
|
||||
t('-1', '-1.518418076611593764852321765899');
|
||||
t('-35416', '-35416');
|
||||
t('6912783515683955988122411164548', '6912783515683955988122411164548.393');
|
||||
t('657', '657.0353902852');
|
||||
t('0', '0.00000000000000000000000017921822306362413915');
|
||||
t('1483059355427939255846407887', '1483059355427939255846407887.011361095342689876');
|
||||
t('0', '0.00000005');
|
||||
t('8551283060956479352', '8551283060956479352.5707396');
|
||||
t('0', '0.000000000000000000000000019904267');
|
||||
t('321978830777554620127500539', '321978830777554620127500539.339278568133088682532238002577');
|
||||
@ -125,6 +122,4 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('-Infinity', '-1e+9000000000000001');
|
||||
t('5.5879983320336874473209567979e+287894365', '5.5879983320336874473209567979e+287894365');
|
||||
t('-5.5879983320336874473209567979e+287894365', '-5.5879983320336874473209567979e+287894365');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
if (typeof T === 'undefined') require('../setup');
|
||||
|
||||
(function () {
|
||||
T('valueOf');
|
||||
T('valueOf', function () {
|
||||
|
||||
function t(expected, n) {
|
||||
T.assertEqual(expected, new Decimal(n).valueOf());
|
||||
@ -62,7 +61,5 @@ if (typeof T === 'undefined') require('../setup');
|
||||
t('4.924353466898191177698653319742594890634579e+37', '49243534668981911776986533197425948906.34579');
|
||||
t('6.85558243926569397328633907445409866949445343654692955e+18', '6855582439265693973.28633907445409866949445343654692955');
|
||||
t('1e+0', '1');
|
||||
|
||||
T.stop();
|
||||
})();
|
||||
});
|
||||
|
||||
|
@ -1,26 +1,27 @@
|
||||
// Adds global: T
|
||||
|
||||
T = (function () {
|
||||
var passed, start, testNumber, write, writer, writeError;
|
||||
var passed, testNumber, write;
|
||||
|
||||
function T(name) {
|
||||
function T(name, tests) {
|
||||
var time;
|
||||
write('\n Testing ' + name + '...');
|
||||
start = +new Date();
|
||||
passed = testNumber = 0;
|
||||
T.result = null;
|
||||
time = new Date();
|
||||
tests();
|
||||
time = new Date() - time;
|
||||
T.result = [passed, testNumber, time];
|
||||
if (passed !== testNumber) write('\n');
|
||||
write(' ' + passed + ' of ' + testNumber + ' tests passed in ' + time + ' ms');
|
||||
}
|
||||
|
||||
if (typeof window != 'undefined') {
|
||||
writer = function (str, className) {
|
||||
document.body.innerHTML += '<div class="' + className + '">' +
|
||||
str.replace('\n', '<br>') + '</div>';
|
||||
write = function (str) {
|
||||
document.body.innerHTML += str.replace(/\n/g, '<br>').replace(/ /g, ' ');
|
||||
};
|
||||
write = function (str) { writer(str, 'pass'); };
|
||||
writeError = function (str) { writer(str, 'fail'); };
|
||||
} else {
|
||||
Decimal = require('../decimal');
|
||||
write = console.log;
|
||||
writeError = console.error;
|
||||
write = process.stdout.write.bind(process.stdout);
|
||||
}
|
||||
|
||||
T.assert = function (actual) {
|
||||
@ -29,21 +30,26 @@ T = (function () {
|
||||
++passed;
|
||||
//write('\n Expected and actual: ' + actual);
|
||||
} else {
|
||||
writeError('\n Test number ' + testNumber + ' failed: assert');
|
||||
writeError(' Expected: true');
|
||||
writeError(' Actual: ' + actual);
|
||||
write(
|
||||
'\n Test number ' + testNumber + ' failed: assert' +
|
||||
'\n Expected: true' +
|
||||
'\n Actual: ' + actual
|
||||
);
|
||||
//process.exit();
|
||||
}
|
||||
};
|
||||
|
||||
T.assertEqual = function (expected, actual) {
|
||||
++testNumber;
|
||||
// If expected and actual are both NaN, consider them equal.
|
||||
if (expected === actual || expected !== expected && actual !== actual) {
|
||||
++passed;
|
||||
} else {
|
||||
writeError('\n Test number ' + testNumber + ' failed: assertEqual');
|
||||
writeError(' Expected: ' + expected);
|
||||
writeError(' Actual: ' + actual);
|
||||
write(
|
||||
'\n Test number ' + testNumber + ' failed: assertEqual' +
|
||||
'\n Expected: ' + expected +
|
||||
'\n Actual: ' + actual
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -52,9 +58,11 @@ T = (function () {
|
||||
if (x.eq(y) || x.isNaN() && y.isNaN()) {
|
||||
++passed;
|
||||
} else {
|
||||
writeError('\n Test number ' + testNumber + ' failed: assertEqualDecimal');
|
||||
writeError(' x: ' + x.valueOf());
|
||||
writeError(' y: ' + y.valueOf());
|
||||
write(
|
||||
'\n Test number ' + testNumber + ' failed: assertEqualDecimal' +
|
||||
'\n x: ' + x.valueOf() +
|
||||
'\n y: ' + y.valueOf()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -66,13 +74,15 @@ T = (function () {
|
||||
if (i === len && i === n.d.length && exponent === n.e && sign === n.s) {
|
||||
++passed;
|
||||
} else {
|
||||
writeError('\n Test number ' + testNumber + ' failed: assertEqualProps');
|
||||
writeError(' Expected digits: ' + digits);
|
||||
writeError(' Expected exponent: ' + exponent);
|
||||
writeError(' Expected sign: ' + sign);
|
||||
writeError(' Actual digits: ' + n.d);
|
||||
writeError(' Actual exponent: ' + n.e);
|
||||
writeError(' Actual sign: ' + n.s);
|
||||
write(
|
||||
'\n Test number ' + testNumber + ' failed: assertEqualProps' +
|
||||
'\n Expected digits: ' + digits +
|
||||
'\n Expected exponent: ' + exponent +
|
||||
'\n Expected sign: ' + sign +
|
||||
'\n Actual digits: ' + n.d +
|
||||
'\n Actual exponent: ' + n.e +
|
||||
'\n Actual sign: ' + n.s
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -87,19 +97,13 @@ T = (function () {
|
||||
if (actual instanceof Error && /DecimalError/.test(actual.message)) {
|
||||
++passed;
|
||||
} else {
|
||||
writeError('\n Test number ' + testNumber + ' failed: assertException');
|
||||
writeError(' Expected: ' + msg + ' to raise a [DecimalError].');
|
||||
writeError(' Actual: ' + (actual || 'no exception'));
|
||||
write(
|
||||
'\n Test number ' + testNumber + ' failed: assertException' +
|
||||
'\n Expected: ' + msg + ' to raise a DecimalError.' +
|
||||
'\n Actual: ' + (actual || 'no exception')
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
T.stop = function () {
|
||||
var duration = +new Date() - start;
|
||||
write('\n ' + passed + ' of ' + testNumber + ' tests passed in ' + duration + ' ms \n');
|
||||
T.result = [passed, testNumber, duration];
|
||||
};
|
||||
|
||||
T.write = write;
|
||||
|
||||
return T;
|
||||
})();
|
||||
|
@ -5,8 +5,6 @@
|
||||
<title>Testing decimal.js</title>
|
||||
<style>
|
||||
body {font-family: monospace; font-size: 12px; line-height: 14px;}
|
||||
.pass { color: black; background-color: white }
|
||||
.fail { color: black; background-color: white }
|
||||
</style>
|
||||
<script src='../decimal.js'></script>
|
||||
<script src='./setup.js'></script>
|
||||
@ -14,10 +12,11 @@
|
||||
<body>
|
||||
<script>
|
||||
var arr,
|
||||
head = document.getElementsByTagName("head")[0],
|
||||
i = 0,
|
||||
passed = 0,
|
||||
total = 0,
|
||||
start = +new Date(),
|
||||
time = new Date(),
|
||||
modules = [
|
||||
'abs',
|
||||
'acos',
|
||||
@ -81,36 +80,32 @@
|
||||
];
|
||||
|
||||
function load() {
|
||||
var head = document.getElementsByTagName("head")[0],
|
||||
script = document.createElement("script");
|
||||
script.src = './modules/' + modules[i] + '.js';
|
||||
if (!modules[i++]) {
|
||||
document.body.innerHTML += '<br>In total, ' + passed + ' of ' + total +
|
||||
' tests passed in ' + ((+new Date() - start) / 1000) + ' secs.<br>';
|
||||
var module = modules[i++];
|
||||
if (!module) {
|
||||
time = new Date() - time;
|
||||
document.body.innerHTML +=
|
||||
'<br><br> In total, ' + passed + ' of ' + total + ' tests passed in ' + (time / 1e3) + ' secs.<br>';
|
||||
document.body.scrollIntoView(false);
|
||||
return;
|
||||
}
|
||||
var script = document.createElement("script");
|
||||
script.src = './modules/' + module + '.js';
|
||||
script.onload = script.onreadystatechange = function () {
|
||||
if (!script.readyState || /loaded|complete/.test(script.readyState)) {
|
||||
if (!T.result) {
|
||||
document.body.innerHTML +=
|
||||
'<br><span style="color: red">Test script failed - see error console.</span>';
|
||||
} else {
|
||||
if (T.result) {
|
||||
passed += T.result[0];
|
||||
total += T.result[1];
|
||||
}
|
||||
head.removeChild(script);
|
||||
count = script = null;
|
||||
//document.body.innerHTML += '<br>';
|
||||
document.body.scrollIntoView(false);
|
||||
setTimeout(load, 0);
|
||||
}
|
||||
|
||||
};
|
||||
head.appendChild(script);
|
||||
}
|
||||
|
||||
document.body.innerHTML += 'Testing decimal.js<br>';
|
||||
document.body.innerHTML += ' Testing decimal.js<br>';
|
||||
load();
|
||||
</script>
|
||||
</body>
|
||||
|
55
test/test.js
55
test/test.js
@ -1,8 +1,8 @@
|
||||
var start = +new Date(),
|
||||
var time = new Date(),
|
||||
passed = 0,
|
||||
total = 0;
|
||||
|
||||
console.log('\n Testing decimal.js\n');
|
||||
console.log('\n Testing decimal.js');
|
||||
|
||||
[
|
||||
'abs',
|
||||
@ -71,52 +71,5 @@ console.log('\n Testing decimal.js\n');
|
||||
total += T.result[1];
|
||||
});
|
||||
|
||||
console.log('\n In total, ' + passed + ' of ' + total + ' tests passed in ' +
|
||||
((+new Date() - start) / 1000) + ' secs.\n');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
time = new Date() - time;
|
||||
console.log('\n\n In total, ' + passed + ' of ' + total + ' tests passed in ' + (time / 1e3) + ' secs.\n');
|
||||
|
Loading…
Reference in New Issue
Block a user