From cd96b4b1b1b05334aa6b1aba045a5093058eb23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 7 Aug 2015 14:33:16 +0200 Subject: [PATCH] fix(matrix): abs method should return the instance --- src/matrix.js | 1 + test/matrix/abs.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/matrix/abs.js diff --git a/src/matrix.js b/src/matrix.js index 032d3100..b398bd10 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -1465,6 +1465,7 @@ Matrix.prototype.abs = function abs() { this[i][j] = Math.abs(this[i][j]); } } + return this; }; module.exports = Matrix; diff --git a/test/matrix/abs.js b/test/matrix/abs.js new file mode 100644 index 00000000..ca9c6a6b --- /dev/null +++ b/test/matrix/abs.js @@ -0,0 +1,32 @@ +'use strict'; + +var Matrix = require('../..'); + +describe('Matrix#abs', function () { + + var matrix; + + beforeEach(function () { + matrix = new Matrix([ + [0, 1, 2], + [3, -4, -5], + [-6, -7, -8], + [4.39, -0.61, -12.7] + ]); + }); + + it('should convert all elements to absolute value (in-place)', function () { + matrix.abs(); + matrix.should.eql([ + [0, 1, 2], + [3, 4, 5], + [6, 7, 8], + [4.39, 0.61, 12.7] + ]); + }); + + it('should return instance', function () { + matrix.abs().should.equal(matrix); + }); + +});