-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support all arithmetic operators and Math functions including s…
…tatic versions Closes #7
- Loading branch information
Showing
4 changed files
with
245 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
var Matrix = require('../..'); | ||
|
||
describe('Dynamic methods on matrices', function () { | ||
|
||
var matrix; | ||
|
||
beforeEach(function () { | ||
matrix = new Matrix([ | ||
[0, 1, 2], | ||
[3, -4, -5], | ||
[-6, -7, -8], | ||
[4.39, -0.61, -12.7] | ||
]); | ||
}); | ||
|
||
describe('inplace', function () { | ||
it('should return instance', function () { | ||
matrix.abs().should.equal(matrix); | ||
matrix.sqrt().should.equal(matrix); | ||
}); | ||
it('abs', function () { | ||
matrix.abs(); | ||
matrix.to2DArray().should.eql([ | ||
[0, 1, 2], | ||
[3, 4, 5], | ||
[6, 7, 8], | ||
[4.39, 0.61, 12.7] | ||
]); | ||
}); | ||
it('cbrt', function () { | ||
matrix.fill(27); | ||
matrix.cbrt(); | ||
matrix.to2DArray().should.eql([ | ||
[3, 3, 3], | ||
[3, 3, 3], | ||
[3, 3, 3], | ||
[3, 3, 3] | ||
]); | ||
}); | ||
}); | ||
|
||
describe('static', function () { | ||
it('should return a new Matrix', function () { | ||
Matrix.abs(matrix).should.not.equal(matrix); | ||
var abs1 = Matrix.abs(matrix); | ||
var abs2 = Matrix.abs(matrix); | ||
abs1.should.not.equal(abs2); | ||
}); | ||
it('should accept 2D array input', function () { | ||
var result = Matrix.abs([[-6]]); | ||
result[0][0].should.equal(6); | ||
}); | ||
it('should return a Matrix instance', function () { | ||
var result = Matrix.abs([[-6]]); | ||
result.should.be.instanceOf(Matrix); | ||
}); | ||
it('cbrt', function () { | ||
matrix.fill(27); | ||
Matrix.cbrt(matrix).to2DArray().should.eql([ | ||
[3, 3, 3], | ||
[3, 3, 3], | ||
[3, 3, 3], | ||
[3, 3, 3] | ||
]); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.
521e4fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we allow combination of 2 matrix that has not the same size ? Maybe the checkDimensions should be an options. Could be by default true.
521e4fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we talked about it but I don't want to do it now. It can be supported later