Skip to content

Instantly share code, notes, and snippets.

@stungeye
Last active June 15, 2021 18:14
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/cb50a97885b11fe7d1acb9470d3d1090 to your computer and use it in GitHub Desktop.
Save stungeye/cb50a97885b11fe7d1acb9470d3d1090 to your computer and use it in GitHub Desktop.
Leap Year Testing Code p5js
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(isLeap(2015), 'year not divisible by 4 (common year)').toBeFalsy();
expect(isLeap(2016), 'year divisible by 4, not divisible by 100 (leap year)').toBeTruthy();
expect(isLeap(2100), 'year divisible by 100, not divisible by 400 (common year)').toBeFalsy();
expect(isLeap(2000), 'year divisible by 400: leap year').toBeTruthy();
expect(isLeap(1800),'year divisible by 200, not divisible by 400 (common year)').toBeFalsy();
}
function isLeap(year) {
// Return true if year is a leap other, otherwise return false.
};
function setup() {
testSuite();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment