Skip to content

Instantly share code, notes, and snippets.

@thoferon
Created January 13, 2020 08:35
Show Gist options
  • Save thoferon/cf3f585271bd791781c5efb021837695 to your computer and use it in GitHub Desktop.
Save thoferon/cf3f585271bd791781c5efb021837695 to your computer and use it in GitHub Desktop.
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