mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
var assert = require('assert'),
|
|
math = require('../../../index.js'),
|
|
matrix = math.matrix;
|
|
|
|
describe('eye', function() {
|
|
|
|
it('should create an identity matrix of the given size', function() {
|
|
assert.deepEqual(math.eye(), matrix([[1]]));
|
|
assert.deepEqual(math.eye([]), [[1]]);
|
|
assert.deepEqual(math.eye(1), matrix([[1]]));
|
|
assert.deepEqual(math.eye(2), matrix([[1,0],[0,1]]));
|
|
assert.deepEqual(math.eye([2]), [[1,0],[0,1]]);
|
|
assert.deepEqual(math.eye(2,3), matrix([[1,0,0],[0,1,0]]));
|
|
assert.deepEqual(math.eye(3,2), matrix([[1,0],[0,1],[0,0]]));
|
|
assert.deepEqual(math.eye([3,2]), [[1,0],[0,1],[0,0]]);
|
|
assert.deepEqual(math.eye(math.matrix([3,2])), matrix([[1,0],[0,1],[0,0]]));
|
|
assert.deepEqual(math.eye(math.matrix([[3],[2]])), matrix([[1,0],[0,1],[0,0]]));
|
|
assert.deepEqual(math.eye(3,3), matrix([[1,0,0],[0,1,0],[0,0,1]]));
|
|
});
|
|
|
|
// TODO: test option math.options.matrix.default
|
|
|
|
it('should throw an error with an invalid input', function() {
|
|
assert.throws(function () {math.eye(3,3,2);});
|
|
assert.throws(function () {math.eye([3,3,2]);});
|
|
});
|
|
|
|
}); |