Skip to content

Commit

Permalink
create new method for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
polo2ro committed Jan 29, 2016
1 parent 06ea4ab commit 14db3b0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 47 deletions.
25 changes: 1 addition & 24 deletions tests/englandWalesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,7 @@ describe('England and Wales non working days', function() {


describe('have all events every years', function() {
var events = file.getNonWorkingDays();
var y, e, from, to, event, rruleSet, nonworkingdays, tests = [];

for (y=2000; y<2050; y++) {

from = new Date(y, 0, 1);
to = new Date(1+y, 0, 1);

to.setMilliseconds(to.getMilliseconds()-1);

for (e=0; e<events.length; e++) {

event = events[e];

rruleSet = file.getRruleSet(event.getProperty('UID').value);
nonworkingdays = rruleSet.between(from, to, true);

tests.push({
summary: event.getProperty('SUMMARY').value,
y: y,
count: nonworkingdays.length
});
}
}
var tests = file.getYearIntervalTest();

tests.forEach(function(test) {
it(test.summary+' found 1 time in year '+test.y, function() {
Expand Down
24 changes: 1 addition & 23 deletions tests/franceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,8 @@ describe('France non working days', function() {


describe('have all events every years', function() {
var events = file.getNonWorkingDays();
var y, e, from, to, event, rruleSet, nonworkingdays, tests = [];

for (y=2000; y<2050; y++) {

from = new Date(y, 0, 1);
to = new Date(1+y, 0, 1);

to.setMilliseconds(to.getMilliseconds()-1);

for (e=0; e<events.length; e++) {

event = events[e];

rruleSet = file.getRruleSet(event.getProperty('UID').value);
nonworkingdays = rruleSet.between(from, to, true);
var tests = file.getYearIntervalTest();

tests.push({
summary: event.getProperty('SUMMARY').value,
y: y,
count: nonworkingdays.length
});
}
}

tests.forEach(function(test) {
it(test.summary+' found 1 time in year '+test.y, function() {
Expand Down
35 changes: 35 additions & 0 deletions tests/icalFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,39 @@ IcalFile.prototype.getRruleSet = function(uid)
};


/**
* Get a table with a list of events for each years, each test contain the number of events found
* @returns {Array}
*/
IcalFile.prototype.getYearIntervalTest = function()
{
var events = this.getNonWorkingDays();
var y, e, from, to, event, rruleSet, nonworkingdays, tests = [];

for (y=2000; y<2050; y++) {

from = new Date(y, 0, 1);
to = new Date(1+y, 0, 1);

to.setMilliseconds(to.getMilliseconds()-1);

for (e=0; e<events.length; e++) {

event = events[e];

rruleSet = this.getRruleSet(event.getProperty('UID').value);
nonworkingdays = rruleSet.between(from, to, true);

tests.push({
summary: event.getProperty('SUMMARY').value,
y: y,
count: nonworkingdays.length
});
}
}

return tests;
};


module.exports = IcalFile;

0 comments on commit 14db3b0

Please sign in to comment.