Skip to content
This repository has been archived by the owner on May 27, 2023. It is now read-only.

Commit

Permalink
Added differential test and fixed scalar vector multiplication [#7]
Browse files Browse the repository at this point in the history
  • Loading branch information
aantthony committed Apr 9, 2014
1 parent baf1bd3 commit 29ed829
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/Expression/Vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ _.default = function (x) {
}
return sum;
} else {
// Scalar multiplication:
return Vector(Array.prototype.map.call(this, function (c) {
return c.apply(x);
return c.default(x);
}));
}
};
Expand Down
7 changes: 4 additions & 3 deletions lib/Language/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ var language = module.exports = new Language(parser, {
[['+'], true],
[['-'], L],
[['∫', '∑'], R, 1],
[['*', '%'], R],
[['%']],
[['*']],
[crossProduct, R],
[['@+', '@-', '@±'], R, 1], //unary plus/minus
[['¬'], L, 1],
['default', R, 2], //I changed this to R for 5sin(t)
['∘', R, 2],
['default', 0, 2], //I changed this to R for 5sin(t)
['∘', 0, 2],
[['/']],
[['^']],//e**x
['!', L, 1],
Expand Down
1 change: 1 addition & 0 deletions test/$.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports = module.exports = function (str) {
[/\\implies/g, '⇒'],
[/\\Integer/g, 'ℤ'],
[/\\Rational/g, 'ℚ'],
[/\\nabla/g, '∇'],
[/\\cdot/g, '·'],
[/\\List.Real/g, 'ℝ{*}'],
[/\\Symbol.Real/g, 'ℝ{A}'],
Expand Down
32 changes: 32 additions & 0 deletions test/expression/differential.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var should = require('should'),
sinon = require('sinon'),
$ = require('../$'),
M = require('../../'),
match = require('../match'),
Integer = M.Expression.Integer,
Symbol = M.Expression.Symbol,
Real = Symbol.Real,
List = M.Expression.List;

describe('Differential', function () {
it.skip('should be parsed correctly', function () {

});
describe($('\\nabla'), function () {
var del, x;
beforeEach(function () {
var d = M('d');
x = M('(x,y,z)');
del = d['/'](d.default(x));
});

it($('(x) = 3'), function () {
match(del.default(x), M('3'), 'x');
});
it($('(x.i) = (1,0,0)'), function () {
del.default(x.unbound.x).compile()().join(',').should.equal('1,0,0');
});

});

});
4 changes: 3 additions & 1 deletion test/expression/modulo.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe($('x % y'), function () {
it($('= [glsl] mod(x, 1.2), when y = 1.2'), function () {
var z = new List.Real([x,new Real(1.2)], '%');
var glsl = z.s('x-shader/x-fragment');
glsl.s.should.equal('mod(x,1.2)');
glsl.s.should.equal('mod((x),(1.2))');
// TODO: it should be like this
// glsl.s.should.equal('mod(x,1.2)');
});
});

0 comments on commit 29ed829

Please sign in to comment.