Created
May 26, 2014 15:13
-
-
Save fgalassi/66dab10bd70801a1ff58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var expect = require("chai").expect | |
var gameOrig = "../game" | |
var gameGood = "../game.good" | |
var capturingConsole = function(action) { | |
var log = console.log | |
var logs = [] | |
global.console.log = function(msg) { | |
logs.push(msg) | |
} | |
var result = action() | |
global.console.log = log | |
return logs | |
} | |
var withRandom = function(values, action) { | |
var random = Math.random | |
var idx = 0 | |
global.Math.random = function() { | |
if (idx >= values.length) { idx = 0 } | |
var result = values[idx] | |
idx += 1 | |
return result | |
} | |
var result = action() | |
global.Math.random = random | |
return result | |
} | |
var origLogs, goodLogs | |
var assert = require("assert") | |
var fs = require("fs") | |
var randomArray = function(n) { | |
var vals = [] | |
for (var i = 0; i < n; i++) { | |
vals.push(Math.random()) | |
} | |
return vals | |
} | |
var randomness = randomArray(100) | |
withRandom(randomness, function() { | |
origLogs = capturingConsole(function() { | |
require(gameOrig) | |
}) | |
}) | |
withRandom(randomness, function() { | |
goodLogs = capturingConsole(function() { | |
require(gameGood) | |
}) | |
}) | |
expect(origLogs).to.be.deep.equal(goodLogs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment