Permalink
Browse files

fixed rightMultiplication

  • Loading branch information...
1 parent cb90a54 commit 6b6b3105afa0995594632268ea74733a61df4c04 @fibo committed Jan 17, 2013
Showing with 58 additions and 7 deletions.
  1. +6 −2 lib/Real/SquareMatrix.js
  2. +52 −5 test/Real/SquareMatrix.js
@@ -1,7 +1,8 @@
var _ = require('underscore');
-var RealField = require('./Field.js');
+var RealElement = require('./Element.js');
+var RealField = require('./Field.js');
var R = new RealField();
@@ -50,8 +51,11 @@ function RealSquareMatrix(arg) {
var col = matrix.col(j);
var element = R.getZero();
+
for (var k = 0; k < _order; k++) {
- element.add(row[k]).mul(col[k]);
+ var rk = new RealElement(row[k]);
+ var ck = new RealElement(col[k]);
+ element.add(rk.mul(ck));
}
_elements[index(i, j)] = element;
}
@@ -23,27 +23,74 @@ describe('RealSquareMatrix', function () {
});
describe('rightMultiplication()', function () {
- it('', function () {
+ it('implements row by column multiplication at right side', function () {
+ var arg = {};
+ arg.order = 2;
+ arg.elements = [2, 0, 0, 2];
+ var elements;
+
+ var matrix1 = new RealSquareMatrix(arg);
+
+ arg.elements = [-1, 0, 0, -1];
+ var matrix2 = new RealSquareMatrix(arg);
+
+ matrix1.rightMultiplication(matrix2);
+
+ elements = matrix1.getElements();
+ assert.ok(elements[0].eq(-2));
+ assert.ok(elements[1].eq(0));
+ assert.ok(elements[2].eq(0));
+ assert.ok(elements[3].eq(-2));
+
+/*
+TODO
+ arg.elements = [-0.5, 0, 0, -0.5];
+ var matrix3 = new RealSquareMatrix(arg);
+
+ elements = matrix3.getElements();
+ assert.ok(elements[0].eq(1));
+ assert.ok(elements[1].eq(0));
+ assert.ok(elements[2].eq(0));
+ assert.ok(elements[3].eq(1));
+*/
});
});
describe('leftMultiplication()', function () {
- it('', function () {
+ it('implements row by column multiplication at left side', function () {
});
});
describe('mul()', function () {
- it('', function () {
+ it('is an alias of rightMultiplication', function () {
+ var arg = {};
+ arg.order = 2;
+
+ var matrix = new RealSquareMatrix(arg);
+
+ assert.ok(matrix.mul === matrix.rightMultiplication);
});
});
describe('lmul()', function () {
- it('', function () {
+ it('is an alias of leftMultiplication', function () {
+ var arg = {};
+ arg.order = 2;
+
+ var matrix = new RealSquareMatrix(arg);
+
+ assert.ok(matrix.lmul === matrix.leftMultiplication);
});
});
describe('rmul()', function () {
- it('', function () {
+ it('is an alias of rightMultiplication', function () {
+ var arg = {};
+ arg.order = 2;
+
+ var matrix = new RealSquareMatrix(arg);
+
+ assert.ok(matrix.rmul === matrix.rightMultiplication);
});
});
});

0 comments on commit 6b6b310

Please sign in to comment.