{"size": 1701, "ext": "js", "max_stars_repo_path": "test/reduce.test.js", "max_stars_repo_name": "yilmazeray/formvalidationtest", "max_stars_repo_stars_event_min_datetime": "2015-10-07T15:33:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T07:55:47.000Z", "max_issues_repo_path": "test/reduce.test.js", "max_issues_repo_name": "yilmazeray/formvalidationtest", "max_issues_repo_issues_event_min_datetime": "2015-10-07T16:58:47.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-13T11:32:29.000Z", "max_forks_repo_path": "test/reduce.test.js", "max_forks_repo_name": "yilmazeray/formvalidationtest", "max_forks_repo_forks_event_min_datetime": "2015-10-13T18:30:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-10T12:03:55.000Z"}
{"max_stars_count": 694, "max_issues_count": 52, "max_forks_count": 62, "avg_line_length": 32.0943396226, "max_line_length": 75, "alphanum_fraction": 0.5026455026}
import {reduce} from '../src/lib/reduce.js';

import expect from 'expect.js';

describe('Library Reduce', () => {
    describe('#reduce(func, index, array)', () => {
        const add = (a, b) => a + b;

        it('should be 15 when array is [1,2,3,4,5]', () => {
            let result = reduce(add, 0, [1, 2, 3, 4, 5]);
            expect(result).to.be(15);
        });

        it('It should be an exception when index is not an array', () => {
            let result = reduce.bind(this, add, 0, null);
            expect(result).to.throwError();
        });

        it('It should be an exception when func is not a function', () => {
            let result = reduce.bind(this, undefined, 0, [1, 2, 3, 4, 5]);
            expect(result).to.throwError();
        });
    });
});

describe('Library Reduce without Array.prototype.reduce', () => {
    const reduceTemp = Array.prototype.reduce;
    before(()=> {
        Array.prototype.reduce = null;
    });
    describe('#reduce(func, index, array)', () => {
        const add = (a, b) => a + b;

        it('should be 15 when array is [1,2,3,4,5]', () => {
            let result = reduce(add, 0, [1, 2, 3, 4, 5]);
            expect(result).to.be(15);
        });

        it('It should be an exception when index is not an array', () => {
            let result = reduce.bind(this, add, 0, null);
            expect(result).to.throwError();
        });

        it('It should be an exception when func is not a function', () => {
            let result = reduce.bind(this, undefined, 0, [1, 2, 3, 4, 5]);
            expect(result).to.throwError();
        });
    });
    after(()=> {
        Array.prototype.reduce = reduceTemp;
    });
});
