Skip to content

Instantly share code, notes, and snippets.

@stungeye
Last active September 9, 2024 16:05
Show Gist options
  • 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 4, year divisible by 100, not divisible by 400 (common year)').toBeFalsy();
expect(isLeap(2000), 'year divisible by 4, year divisible by 100, year divisible by 400 (leap year)').toBeTruthy();
}
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