1
0
mirror of https://github.com/MikeMcl/decimal.js.git synced 2024-10-27 20:34:12 +00:00

Mutation tests

This commit is contained in:
Jayson Harshbarger 2016-01-29 11:50:16 +09:00
parent b8b2ed7a2b
commit ec0955c28e
6 changed files with 24 additions and 10 deletions

View File

@ -4,7 +4,9 @@ if (typeof T === 'undefined') require('../setup');
T('absoluteValue'); T('absoluteValue');
function t(expected, value){ function t(expected, value){
T.assertEqual(expected, new Decimal(value).abs().valueOf()); var x = new Decimal(value);
T.assertEqual(expected, x.abs().valueOf());
T.assert(x.eq(value) || x.isNaN());
} }
Decimal.config({ Decimal.config({

View File

@ -6,12 +6,10 @@ if (typeof T === 'undefined') require('../setup');
function t(n, pr, rm, expected) { function t(n, pr, rm, expected) {
Decimal.precision = pr; Decimal.precision = pr;
Decimal.rounding = rm; Decimal.rounding = rm;
T.assertEqual(expected, Decimal.cos(n).valueOf());
T.assertEqual(expected, new Decimal(n).cos().valueOf());
var x = new Decimal(n); var x = new Decimal(n);
x.cos(); T.assertEqual(expected, x.cos().valueOf());
T.assertEqual(new Decimal(n).valueOf(), x.valueOf()); T.assertEqual(expected, Decimal.cos(n).valueOf());
T.assert(x.eq(n) || x.isNaN());
} }
Decimal.config({ Decimal.config({
@ -44,6 +42,7 @@ if (typeof T === 'undefined') require('../setup');
t('0.3834777777', 3, 4, '0.927'); t('0.3834777777', 3, 4, '0.927');
t('16355.3334', 9, 4, '0.979658167'); t('16355.3334', 9, 4, '0.979658167');
t('0.997737586545708065463833973312637902054356957830033', 5, 5, '0.5422'); t('0.997737586545708065463833973312637902054356957830033', 5, 5, '0.5422');
t('-0.997737586545708065463833973312637902054356957830033', 5, 5, '0.5422');
t('7803700', 4, 2, '-0.9032'); t('7803700', 4, 2, '-0.9032');
t('841822094288189413002174891207354317', 5, 2, '-0.86017'); t('841822094288189413002174891207354317', 5, 2, '-0.86017');
t('67942', 8, 3, '-0.33958641'); t('67942', 8, 3, '-0.33958641');

View File

@ -6,8 +6,10 @@ if (typeof T === 'undefined') require('../setup');
function t(n, expected, pr, rm) { function t(n, expected, pr, rm) {
Decimal.precision = pr; Decimal.precision = pr;
Decimal.rounding = rm; Decimal.rounding = rm;
var x = new Decimal(n);
T.assertEqual(expected, x.exp().valueOf());
T.assertEqual(expected, Decimal.exp(n).valueOf()); T.assertEqual(expected, Decimal.exp(n).valueOf());
T.assertEqual(expected, new Decimal(n).exp().valueOf()); T.assert(x.eq(n) || x.isNaN());
} }
Decimal.config({ Decimal.config({

View File

@ -6,8 +6,10 @@ if (typeof T === 'undefined') require('../setup');
function t(n, pr, rm, expected) { function t(n, pr, rm, expected) {
Decimal.precision = pr; Decimal.precision = pr;
Decimal.rounding = rm; Decimal.rounding = rm;
var x = new Decimal(n);
T.assertEqual(expected, x.sin().valueOf());
T.assertEqual(expected, Decimal.sin(n).valueOf()); T.assertEqual(expected, Decimal.sin(n).valueOf());
T.assertEqual(expected, new Decimal(n).sin().valueOf()); T.assert(x.eq(n) || x.isNaN());
} }
Decimal.config({ Decimal.config({
@ -28,6 +30,9 @@ if (typeof T === 'undefined') require('../setup');
t('93332358216', 48, 5, '0.000816283943127306029649893248669685836695194145277'); t('93332358216', 48, 5, '0.000816283943127306029649893248669685836695194145277');
t('766737078569022420173292205068953186848344673451240027655054631094318050', 18, 6, '0.00111135055272494455'); t('766737078569022420173292205068953186848344673451240027655054631094318050', 18, 6, '0.00111135055272494455');
t('-93332358216', 48, 5, '-0.000816283943127306029649893248669685836695194145277');
t('-766737078569022420173292205068953186848344673451240027655054631094318050', 18, 6, '-0.00111135055272494455');
t('0.359136383962093189473162700700590970518456985109181875257764726415814563424613193774806585890478208084275468196568294033', 38, 1, '0.35146584650000000000000000000000000006'); t('0.359136383962093189473162700700590970518456985109181875257764726415814563424613193774806585890478208084275468196568294033', 38, 1, '0.35146584650000000000000000000000000006');
t('3202222222227222222222222222222224222222222222222222222222.222222222222222222222222222', 7, 0, '0.5499568'); t('3202222222227222222222222222222224222222222222222222222222.222222222222222222222222222', 7, 0, '0.5499568');
t('8', 5, 6, '0.98936'); t('8', 5, 6, '0.98936');

View File

@ -6,8 +6,10 @@ if (typeof T === 'undefined') require('../setup');
function t(n, pr, rm, expected) { function t(n, pr, rm, expected) {
Decimal.precision = pr; Decimal.precision = pr;
Decimal.rounding = rm; Decimal.rounding = rm;
var x = new Decimal(n);
T.assertEqual(expected, x.tan().valueOf());
T.assertEqual(expected, Decimal.tan(n).valueOf()); T.assertEqual(expected, Decimal.tan(n).valueOf());
T.assertEqual(expected, new Decimal(n).tan().valueOf()); T.assert(x.eq(n) || x.isNaN());
} }
Decimal.config({ Decimal.config({
@ -26,8 +28,10 @@ if (typeof T === 'undefined') require('../setup');
t('-Infinity', 40, 4, 'NaN'); t('-Infinity', 40, 4, 'NaN');
t('3', 5, 5, '-0.14255'); t('3', 5, 5, '-0.14255');
t('-3', 5, 5, '0.14255');
t('0.8', 7, 6, '1.029639'); t('0.8', 7, 6, '1.029639');
t('539998661123466984649191689138494900416386817996524', 7, 6, '32.04695'); t('539998661123466984649191689138494900416386817996524', 7, 6, '32.04695');
t('-539998661123466984649191689138494900416386817996524', 7, 6, '-32.04695');
t('0.5172293543584894071801901902', 5, 1, '0.56888'); t('0.5172293543584894071801901902', 5, 1, '0.56888');
t('5', 10, 5, '-3.380515006'); t('5', 10, 5, '-3.380515006');
t('0.5283979979897015', 1, 4, '0.6'); t('0.5283979979897015', 1, 4, '0.6');

View File

@ -4,7 +4,9 @@ if (typeof T === 'undefined') require('../setup');
T('times'); T('times');
var t = function (multiplicand, multiplier, expected) { var t = function (multiplicand, multiplier, expected) {
T.assertEqual(expected, new Decimal(multiplicand).times(multiplier).valueOf()); var x = new Decimal(multiplicand);
T.assertEqual(expected, x.times(multiplier).valueOf());
T.assert(x.eq(multiplicand) || x.isNaN());
} }
Decimal.config({ Decimal.config({