Last active
October 20, 2015 17:51
-
-
Save doekman/51aede23278a73ec1b3e to your computer and use it in GitHub Desktop.
To refactor, or not to refactor
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
// Refactor step 7, still don't like it, f*ck it, just use native function | |
function isLeapYear(year) { | |
return new Date(year, 2-1, 29).getDate() == 29; | |
} |
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
// Create a Jasmine fake | |
function describe(testName, tests) { | |
console.clear(); | |
console.info('Name: %s - Start: %s', testName, new Date); | |
expect.nr=0; | |
expect.errors=0; | |
tests(); | |
if (expect.errors == 0) console.info('All %s tests OK', expect.nr); | |
else console.error('%s of %s tests failed', expect.errors, expect.nr); | |
} | |
function expect(x) { | |
return { | |
toBe: function(y) { | |
if (x===y) console.info("- %s: OK", expect.nr++); | |
else console.error("- %s: Error", expect.nr++), expect.errors++; | |
} | |
}; | |
} |
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
// Unit test | |
function unitTests() { | |
describe("leapYear tests", function() { | |
expect(isLeapYear(1900)).toBe(false); | |
expect(isLeapYear(1971)).toBe(false); | |
expect(isLeapYear(1972)).toBe(true); | |
expect(isLeapYear(2000)).toBe(true); | |
expect(isLeapYear(2003)).toBe(false); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment