Actually use seedrandom.
The tests are run in a sandboxed environment, and so didn’t have access to the same global Math whose random was being overridden.
This commit is contained in:
Родитель
aee121427d
Коммит
8f919c4fe7
|
@ -26,6 +26,11 @@ module.exports = function() {
|
||||||
return topic;
|
return topic;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
topic.sandbox = function(_) {
|
||||||
|
sandbox = _;
|
||||||
|
return topic;
|
||||||
|
};
|
||||||
|
|
||||||
topic.document = function(_) {
|
topic.document = function(_) {
|
||||||
var document = jsdom.jsdom("<html><head></head><body></body></html>");
|
var document = jsdom.jsdom("<html><head></head><body></body></html>");
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ var suite = vows.describe("d3.random");
|
||||||
|
|
||||||
suite.addBatch({
|
suite.addBatch({
|
||||||
"random": {
|
"random": {
|
||||||
topic: load("math/random").expression("d3.random"),
|
topic: load("math/random").sandbox({Math: Math}).expression("d3.random"),
|
||||||
"(using seedrandom)": {
|
"(using seedrandom)": {
|
||||||
topic: function(random) {
|
topic: function(random) {
|
||||||
_random = Math.random;
|
_random = Math.random;
|
||||||
|
@ -75,14 +75,14 @@ function KSTest(cdf, n) {
|
||||||
// Derivation of this interval is difficult.
|
// Derivation of this interval is difficult.
|
||||||
// @see K-S test in Knuth's AoCP vol.2
|
// @see K-S test in Knuth's AoCP vol.2
|
||||||
assert.inDelta(K_positive, 0.723255, 0.794145);
|
assert.inDelta(K_positive, 0.723255, 0.794145);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logistic approximation to normal CDF around N(mean, stddev).
|
// Logistic approximation to normal CDF around N(mean, stddev).
|
||||||
function normalCDF(mean, stddev) {
|
function normalCDF(mean, stddev) {
|
||||||
return function(x) {
|
return function(x) {
|
||||||
return 1 / (1 + Math.exp(-0.07056 * Math.pow((x-mean)/stddev, 3) - 1.5976 * (x-mean)/stddev));
|
return 1 / (1 + Math.exp(-0.07056 * Math.pow((x-mean)/stddev, 3) - 1.5976 * (x-mean)/stddev));
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// See http://en.wikipedia.org/wiki/Log-normal_distribution#Similar_distributions
|
// See http://en.wikipedia.org/wiki/Log-normal_distribution#Similar_distributions
|
||||||
|
@ -91,7 +91,7 @@ function logNormalCDF(mean, stddev) {
|
||||||
var numerator = Math.exp(mean);
|
var numerator = Math.exp(mean);
|
||||||
return function(x) {
|
return function(x) {
|
||||||
return 1 / (Math.pow(numerator / x, exponent) + 1);
|
return 1 / (Math.pow(numerator / x, exponent) + 1);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function irwinHallCDF(n) {
|
function irwinHallCDF(n) {
|
||||||
|
@ -111,7 +111,7 @@ function irwinHallCDF(n) {
|
||||||
t += Math.pow(-1, k % 2) * binoms[k] * Math.pow(x - k, n);
|
t += Math.pow(-1, k % 2) * binoms[k] * Math.pow(x - k, n);
|
||||||
}
|
}
|
||||||
return t / normalisingFactor;
|
return t / normalisingFactor;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function factorial(n) {
|
function factorial(n) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче