Revision 3a51c0adab63c1e83d66b262ffcb22a19b027b83 authored by Andreas Stuhlmüller on 16 May 2017, 01:45:44 UTC, committed by GitHub on 16 May 2017, 01:45:44 UTC
Minor clean-up in kernel option parsing.
test-util.js
'use strict';
var util = require('../src/util');
function testAlmostEqual(test, x, y, epsilon) {
if (x === y) {
test.equal(x, y);
} else {
test.ok(Math.abs(x - y) < epsilon);
}
}
module.exports = {
testLogSumExp: {
test1: function(test) {
var epsilon = 0.0000000001;
var xs = [-Infinity, -100, -30, -1, 0, 1, 10];
xs.forEach(
function(x) {
testAlmostEqual(test, x, util.logsumexp([x]), epsilon);
xs.forEach(
function(y) {
var targetVal = Math.log(Math.exp(x) + Math.exp(y));
var actualVal = util.logsumexp([x, y]);
testAlmostEqual(test, targetVal, actualVal, epsilon);
});
});
test.done();
}
},
testCpsIterate: {
test1: function(test) {
var result = util.cpsIterate(5, 3,
function(k, val) { return k(val + 2); },
function(finalVal) { return finalVal; });
// Trampoline.
while (typeof result === 'function') { result = result(); }
test.equal(result, 13);
test.done();
}
},
testIsObject: {
test1: function(test) {
test.strictEqual(util.isObject({}), true);
test.done();
},
test2: function(test) {
test.strictEqual(util.isObject([]), false);
test.done();
},
test3: function(test) {
test.strictEqual(util.isObject(function() {}), false);
test.done();
},
test4: function(test) {
test.strictEqual(util.isObject(undefined), false);
test.done();
},
test5: function(test) {
test.strictEqual(util.isObject(null), false);
test.done();
},
test6: function(test) {
var Thing = function() {};
test.strictEqual(util.isObject(new Thing()), false);
test.done();
},
test7: function(test) {
test.strictEqual(util.isObject(0), false);
test.done();
},
test8: function(test) {
test.strictEqual(util.isObject('foo'), false);
test.done();
},
test9: function(test) {
test.strictEqual(util.isObject(true), false);
test.done();
}
}
};
Computing file changes ...