Created
January 13, 2020 08:35
-
-
Save thoferon/cf3f585271bd791781c5efb021837695 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
import _ from "underscore" | |
import game from "./sequentialActions.js" | |
function testInterpreter (program, inputs, accOutputs) { | |
switch (program.action) { | |
case "read": | |
const input = inputs[0] | |
const rest = inputs.slice(1) | |
return testInterpreter(program.next(input), rest, accOutputs) | |
case "print": | |
return testInterpreter( | |
program.next(), | |
inputs, | |
accOutputs.concat(program.string) | |
) | |
case "pure": | |
return accOutputs | |
} | |
} | |
const outputs = testInterpreter(game, ["3", "90", "32", "42"], []) | |
const expectedOutputs = [ | |
"Enter a guess", | |
"Higher", | |
"Enter a guess", | |
"Lower", | |
"Enter a guess", | |
"Higher", | |
"Enter a guess", | |
"Congratulations! You found it." | |
] | |
if (_.isEqual(outputs, expectedOutputs)) { | |
console.log("All is well") | |
} else { | |
console.log("Test failure", outputs, expectedOutputs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment