Skip to content

Instantly share code, notes, and snippets.

@stungeye
Last active June 15, 2021 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stungeye/60252c720aae38fd549a282b809af3ed to your computer and use it in GitHub Desktop.
Save stungeye/60252c720aae38fd549a282b809af3ed to your computer and use it in GitHub Desktop.
Will you, Won't You Starter Code
function passOrFail(predicate, expectation, msg) {
const outcome = (predicate == expectation) ? "PASSED" : "FAILED";
console.log(`${msg}: ${outcome}`);
}
function expect(predicate, msg) {
return {
toBeFalsy: () => passOrFail(predicate, false, msg),
toBeTruthy: () => passOrFail(predicate, true, msg)
}
}
function testSuite() {
expect(shouldIAnswerThePhone(false, false, false), '!morning !mom !asleep (answer)').toBeTruthy();
expect(shouldIAnswerThePhone(false, false, true), '!morning !mom asleep (!answer)').toBeFalsy();
expect(shouldIAnswerThePhone(false, true, false), '!morning mom !asleep (answer)').toBeTruthy();
expect(shouldIAnswerThePhone(false, true, true), '!morning mom asleep (!answer)').toBeFalsy();
expect(shouldIAnswerThePhone(true, false, false), 'morning !mom !asleep (!answer)').toBeFalsy();
expect(shouldIAnswerThePhone(true, false, true), 'morning !mom asleep (!answer)').toBeFalsy();
expect(shouldIAnswerThePhone(true, true, false), 'morning mom !asleep (answer)').toBeTruthy();
expect(shouldIAnswerThePhone(true, true, true), 'morning mom asleep (!answer)').toBeFalsy();
}
function shouldIAnswerThePhone(isMorning, isMom, isAsleep) {
// Return true if you answer the phone, otherwise return false.
// Rules for answering the phone are found in the question text.
};
function setup() {
testSuite();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment