Last active
September 9, 2024 16:05
-
-
Save stungeye/cb50a97885b11fe7d1acb9470d3d1090 to your computer and use it in GitHub Desktop.
Leap Year Testing Code p5js
This file contains hidden or 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
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