Currently, I am working on crafting a leap year algorithm by utilizing a TDD suite. This marks my initial venture into the realm of TDD.
Displayed below is the code extracted from the spec file.
var Year = require('./leap');
describe('Leap year', function() {
it('is quite uncommon', function() {
var year = new Year(2015);
expect(year.isLeap()).toBe(false);
});
it('is added every 4 years to balance approximately a day', function() {
var year = new Year(2016);
expect(year.isLeap()).toBe(true);
});
it('is omitted every 100 years to eliminate an additional day', function() {
var year = new Year(1900);
expect(year.isLeap()).toBe(false);
});
it('is reintroduced every 400 years to balance an additional day', function() {
var year = new Year(2000);
expect(year.isLeap()).toBe(true);
});
Here's what I have come up with in the leap.js file up to this point
var leapYear = function() {};
leapYear.prototype.isLeap = function(year) {
if (year % 4 != 0) {
return true;
}
}
module.exports = leapYear;
Despite my best efforts, I am encountering the following setbacks:
Failures:
1) Leap year is not very common Message: Expected true to be false. Stacktrace: Error: Expected true to be false. at null.
2) Leap year is skipped every 100 years to remove an extra day Message: Expected true to be false. Stacktrace: Error: Expected true to be false. at null.
Execution Time: 0.014 seconds 4 tests, 4 assertions, 2 failures, 0 skipped
Any suggestions or insights would be greatly appreciated!