diff --git a/src/decimaljs-adapter.js b/src/decimaljs-adapter.js index 6a8da27..5ec3079 100644 --- a/src/decimaljs-adapter.js +++ b/src/decimaljs-adapter.js @@ -16,6 +16,12 @@ module.exports = { mod: mod, pow: pow, sqrt: sqrt, + gt: gt, + gte: gte, + lt: lt, + lte: lte, + cmp: cmp, + abs: abs, equals: equals, toString: toString, valueOf: toString, @@ -58,6 +64,30 @@ function sqrt(x) { return x.sqrt(); } +function lt(x, y) { + return x.lt(y); +} + +function lte(x, y) { + return x.lte(y); +} + +function gt(x, y) { + return x.gt(y); +} + +function gte(x, y) { + return x.gte(y); +} + +function cmp(x, y) { + return x.cmp(y); +} + +function abs(x) { + return x.abs(); +} + function equals(x, y) { return x.eq(y); } diff --git a/test/spec.js b/test/spec.js index a6b6b6d..12fe594 100644 --- a/test/spec.js +++ b/test/spec.js @@ -7,6 +7,7 @@ var decimalFactory = require('arbitrary-precision'); var adapter = require('../src/decimaljs-adapter'); var Decimal = decimalFactory(adapter); +var DecimalJs = adapter.getInstance(); describe('arbitrary precision with decimal.js', function() { describe('precision', function() { @@ -61,6 +62,41 @@ describe('arbitrary precision with decimal.js', function() { new Decimal('2').equals(new Decimal('2')).should.be.exactly(true); new Decimal('2').equals(new Decimal('3')).should.be.exactly(false); }); + + it('should have a gt method', function() { + adapter.gt(new Decimal('2'), new Decimal('2')).should.be.exactly(false); + adapter.gt(new Decimal('2'), new Decimal('3')).should.be.exactly(false); + adapter.gt(new Decimal('2'), new Decimal('1')).should.be.exactly(true); + }); + + it('should have a gte method', function() { + adapter.gte(new Decimal('2'), new Decimal('2')).should.be.exactly(true); + adapter.gte(new Decimal('2'), new Decimal('3')).should.be.exactly(false); + adapter.gte(new Decimal('2'), new Decimal('1')).should.be.exactly(true); + }); + + it('should have a lt method', function() { + adapter.lt(new Decimal('2'), new Decimal('2')).should.be.exactly(false); + adapter.lt(new Decimal('2'), new Decimal('3')).should.be.exactly(true); + adapter.lt(new Decimal('2'), new Decimal('1')).should.be.exactly(false); + }); + + it('should have a lte method', function() { + adapter.lte(new Decimal('2'), new Decimal('2')).should.be.exactly(true); + adapter.lte(new Decimal('2'), new Decimal('3')).should.be.exactly(true); + adapter.lte(new Decimal('2'), new Decimal('1')).should.be.exactly(false); + }); + + it('should have a cmp method', function() { + adapter.cmp(new Decimal('2'), new Decimal('2')).valueOf().should.be.exactly(0); + adapter.cmp(new Decimal('2'), new Decimal('3')).valueOf().should.be.exactly(-1); + adapter.cmp(new Decimal('2'), new Decimal('1')).valueOf().should.be.exactly(1); + }); + + it('should have a abs method', function() { + adapter.abs(new DecimalJs('16')).toNumber().should.be.exactly(16); + adapter.abs(new DecimalJs('-5')).toNumber().should.be.exactly(5); + }); }); describe('toString, valueOf and JSON', function() {