{"size": 8259, "ext": "js", "max_stars_repo_path": "tests/interval.test.js", "max_stars_repo_name": "Magomogo/days-interval", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/interval.test.js", "max_issues_repo_name": "Magomogo/days-interval", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/interval.test.js", "max_forks_repo_name": "Magomogo/days-interval", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.7102040816, "max_line_length": 89, "alphanum_fraction": 0.3634822618}
(function () {
    'use strict';

    var assert = require('assert'),

        interval = require('../index');

    describe('interval', function () {

        it('creates a interval', function () {
            assert.deepEqual(
                interval.create('2015-03-01', '2015-05-29'),
                {
                    firstDay: '2015-03-01',
                    lastDay: '2015-05-29'
                }
            );
        });

        describe('intersection', function () {

            it('gives full intersection', function () {
                var i = {
                    firstDay: '2014-10-05',
                    lastDay: '2014-11-12'
                };

                assert.deepEqual(i, interval.intersection(i, i));
            });

            it('gives no intersection', function () {
                assert(interval.intersection({
                    firstDay: '2014-10-05',
                    lastDay: '2014-11-12'
                }, {
                    firstDay: '2014-11-13',
                    lastDay: '2014-11-14'
                }) === undefined);
            });

            it('gives edge intersection', function () {
                assert.deepEqual({
                    firstDay: '2014-10-05',
                    lastDay: '2014-10-10'
                }, interval.intersection({
                    firstDay: '2014-05-05',
                    lastDay: '2014-10-10'
                }, {
                    firstDay: '2014-10-05',
                    lastDay: '2014-11-14'
                }));
            });

            it('gives inside intersection', function () {
                assert.deepEqual({
                    firstDay: '2014-10-05',
                    lastDay: '2014-10-10'
                }, interval.intersection({
                    firstDay: '2014-10-05',
                    lastDay: '2014-10-10'
                }, {
                    firstDay: '2010-01-01',
                    lastDay: '2016-01-01'
                }));
            });
        });

        describe('split', function () {

            it('splits one interval by including splitter inside', function () {
                var outerInterval = {
                    firstDay: '2014-01-01',
                    lastDay: '2014-12-01'
                }, insideInterval = {
                    firstDay: '2014-02-01',
                    lastDay: '2014-03-01'
                };

                assert.deepEqual(
                    interval.split(outerInterval, insideInterval),
                    [
                        {
                            firstDay: '2014-01-01',
                            lastDay: '2014-01-31'
                        },
                        insideInterval,
                        {
                            firstDay: '2014-03-02',
                            lastDay: '2014-12-01'
                        }
                    ]
                );
            });

            it('gives one interval when splitter is outside', function () {
                var baseInterval = {
                    firstDay: '2014-01-01',
                    lastDay: '2014-12-01'
                }, outsideInterval = {
                    firstDay: '2015-02-01',
                    lastDay: '2016-03-01'
                };

                assert.deepEqual(
                    interval.split(baseInterval, outsideInterval),
                    [
                        baseInterval
                    ]
                );
            });

            it('gives two intervals when splitter intersects firstDay', function () {
                var baseInterval = {
                    firstDay: '2014-01-01',
                    lastDay: '2014-12-01'
                }, intersectInterval = {
                    firstDay: '2013-12-01',
                    lastDay: '2014-10-01'
                };

                assert.deepEqual(
                    interval.split(baseInterval, intersectInterval),
                    [
                        {
                            firstDay: '2014-01-01',
                            lastDay: '2014-10-01'
                        },
                        {
                            firstDay: '2014-10-02',
                            lastDay: '2014-12-01'
                        }
                    ]
                );
            });

            it('gives two intervals when splitter intersects lastDay', function () {
                var baseInterval = {
                    firstDay: '2014-01-01',
                    lastDay: '2014-12-01'
                }, intersectInterval = {
                    firstDay: '2014-10-01',
                    lastDay: '2016-10-01'
                };

                assert.deepEqual(
                    interval.split(baseInterval, intersectInterval),
                    [
                        {
                            firstDay: '2014-01-01',
                            lastDay: '2014-09-30'
                        },
                        {
                            firstDay: '2014-10-01',
                            lastDay: '2014-12-01'
                        }
                    ]
                );
            });

        });

        describe('succession', function () {
            it('gives two adjacent intervals', function () {
                var twoAdjacent = [
                    {firstDay: '2014-10-05', lastDay: '2014-10-10'},
                    {firstDay: '2014-10-12', lastDay: '2014-10-14'}
                ];

                assert.deepEqual(twoAdjacent, interval.succession(twoAdjacent));
            });

            it('gives all little pieces of two intersecting intervals', function () {
                assert.deepEqual(
                    [
                        {firstDay: '2014-10-05', lastDay: '2014-10-05'},
                        {firstDay: '2014-10-06', lastDay: '2014-10-10'},
                        {firstDay: '2014-10-11', lastDay: '2014-10-14'}
                    ],
                    interval.succession([
                        {firstDay: '2014-10-05', lastDay: '2014-10-10'},
                        {firstDay: '2014-10-06', lastDay: '2014-10-14'}
                    ])
                );
            });
        });

        describe('adjacent', function () {

            it('gives no intervals from zero days', function () {
                assert.deepEqual(
                    interval.adjacent([]),
                    []
                );
            });

            it('creates single interval from two days', function () {
                assert.deepEqual(
                    interval.adjacent(['2015-03-01', '2015-03-31']),
                    [
                        interval.create('2015-03-01', '2015-03-31')
                    ]
                );
            });

            it('creates two adjacent intervals from three days', function () {
                assert.deepEqual(
                    interval.adjacent(['2015-03-01', '2015-03-31', '2015-05-03']),
                    [
                        interval.create('2015-03-01', '2015-03-30'),
                        interval.create('2015-03-31', '2015-05-03')
                    ]
                );
            });

            it('can correctly handle Infinities', function () {
                assert.deepEqual(
                    interval.adjacent([-Infinity, '2015-03-31', '2015-05-03', Infinity]),
                    [
                        interval.create(-Infinity, '2015-03-30'),
                        interval.create('2015-03-31', '2015-05-02'),
                        interval.create('2015-05-03', Infinity)
                    ]
                );
            });

            it('won`t create interval from one day', function () {
                assert.deepEqual(
                    interval.adjacent(['2015-01-01']),
                    []
                );
            });

            it('creates unique intervals', function () {
                assert.deepEqual(
                    interval.adjacent(['2015-03-01', '2015-03-01', '2015-05-03']),
                    [
                        interval.create('2015-03-01', '2015-05-03')
                    ]
                );
            });
        });
    });

}());
