Fixed #190: imported, wrapped functions not accepting null and undefined as function arguments.

This commit is contained in:
jos 2014-06-11 20:21:41 +02:00
parent 0fea9f0a1b
commit aa80ae8fc8
3 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,12 @@
https://github.com/josdejong/mathjs
## not yet released, version 0.23.1
- Fixed imported, wrapped functions not accepting `null` and `undefined` as
function arguments.
## 2014-06-10, version 0.23.0
- Renamed some functions (everything now has a logical, camel case name):

View File

@ -117,7 +117,8 @@ module.exports = function (math) {
math[name] = function () {
var args = [];
for (var i = 0, len = arguments.length; i < len; i++) {
args[i] = arguments[i].valueOf();
var arg = arguments[i];
args[i] = arg && arg.valueOf();
}
return value.apply(math, args);
};

View File

@ -59,6 +59,26 @@ describe('import', function() {
assert.equal(math.getSizeNotWrapped(math.matrix([1,2,3])), undefined);
});
it('wrapped imported functions should accept undefined and null', function () {
math.import({
isNull: function (obj) {
return obj === null;
}
}, { wrap: true });
assert.equal(math.isNull(null), true);
assert.equal(math.isNull(0), false);
math.import({
isUndefined: function (obj) {
return obj === undefined;
}
}, { wrap: true });
assert.equal(math.isUndefined(undefined), true);
assert.equal(math.isUndefined(0), false);
assert.equal(math.isUndefined(null), false);
});
it('should extend math with numbers', function() {
// extend math.js with numbers.js
// examples copied from https://github.com/sjkaliski/numbers.js/blob/master/examples/statistic.js