Skip to content

Commit

Permalink
fix(matrix): abs method should return the instance
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Aug 7, 2015
1 parent 02f17fe commit cd96b4b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,7 @@ Matrix.prototype.abs = function abs() {
this[i][j] = Math.abs(this[i][j]);
}
}
return this;
};

module.exports = Matrix;
32 changes: 32 additions & 0 deletions test/matrix/abs.js
Original file line number Diff line number Diff line change
@@ -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);
});

});

0 comments on commit cd96b4b

Please sign in to comment.