<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* globals describe, it, expect, beforeEach, spyOn */

(function() {
    'use strict';

    var cribbageScoring = require('../src/cribbageScoring'),
        cribbageCard = require('../src/cribbageCard.js'),
        jsCombinatorics = require('js-combinatorics');

    describe('pairsPoints method', function() {
        var jsCombinatoricsSpy;

        beforeEach(function() {
            jsCombinatoricsSpy = {
                // jscs:disable jsDoc
                combination: function(cards, subsetSize) {
                    return jsCombinatorics.combination(
                        cards, subsetSize);
                }
            };
            // jscs:enable jsDoc
        });

        it('is defined', function() {
            expect(cribbageScoring.pairsPoints).toBeDefined();
        });

        it('returns 0 for an empty array of cards', function() {
            expect(cribbageScoring.pairsPoints(
                jsCombinatoricsSpy, [])).
            toEqual(0);
        });

        it(
            'calls js-combinatorics.combination() with its cards and subset ' +
            'size 2',
            function() {
                var cards = cribbageCard.parseIndices('A2345');
                spyOn(jsCombinatoricsSpy, 'combination').and.callThrough();
                cribbageScoring.pairsPoints(jsCombinatoricsSpy,
                    cards);
                expect(jsCombinatoricsSpy.combination).toHaveBeenCalledWith(
                    cards, 2);
            });

        it(
            'returns 0 if no js-combinatorics.combination() returned ' +
            'combination is a pair',
            function() {
                var fakeCards = [];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 3
                        }],
                        [{
                            ordinal: 11
                        }, {
                            ordinal: 7
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(0);
            });

        it(
            'returns 2 if one js-combinatorics.combination() returned ' +
            'combination is a pair',
            function() {
                var fakeCards = ['fakeCard1', 'fakeCard2'];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 3
                        }],
                        [{
                            ordinal: 8
                        }, {
                            ordinal: 8
                        }],
                        [{
                            ordinal: 13
                        }, {
                            ordinal: 1
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(2);
            });

        it(
            'returns 8 if four js-combinatorics.combination() returned ' +
            'combinations are pairs',
            function() {
                var fakeCards = ['fakeCard1', 'fakeCard2'];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 6
                        }, {
                            ordinal: 6
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(8);
            });

        it('returns 0 for a known index and an unknown index',
            function() {
                expect(cribbageScoring.pairsPoints(
                    jsCombinatorics, cribbageCard.parseIndices(
                        'AX'))).toEqual(0);
            });

        it('returns 0 for two unknown indices', function() {
            expect(cribbageScoring.pairsPoints(
                jsCombinatorics, cribbageCard.parseIndices(
                    'XY'))).toEqual(0);
        });
    });

    describe('fifteensPoints method', function() {
        it('is defined', function() {
            expect(cribbageScoring.fifteensPoints).toBeDefined();
        });
    });
}());<commit_msg>Add unit test covering fifteensPoints<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* globals describe, it, expect, beforeEach, spyOn */

(function() {
    'use strict';

    var cribbageScoring = require('../src/cribbageScoring'),
        cribbageCard = require('../src/cribbageCard.js'),
        jsCombinatorics = require('js-combinatorics');

    describe('pairsPoints method', function() {
        var jsCombinatoricsSpy;

        beforeEach(function() {
            jsCombinatoricsSpy = {
                // jscs:disable jsDoc
                combination: function(cards, subsetSize) {
                    return jsCombinatorics.combination(
                        cards, subsetSize);
                }
            };
            // jscs:enable jsDoc
        });

        it('is defined', function() {
            expect(cribbageScoring.pairsPoints).toBeDefined();
        });

        it('returns 0 for an empty array of cards', function() {
            expect(cribbageScoring.pairsPoints(
                jsCombinatoricsSpy, [])).
            toEqual(0);
        });

        it(
            'calls js-combinatorics.combination() with its cards and subset ' +
            'size 2',
            function() {
                var cards = cribbageCard.parseIndices('A2345');
                spyOn(jsCombinatoricsSpy, 'combination').and.callThrough();
                cribbageScoring.pairsPoints(jsCombinatoricsSpy,
                    cards);
                expect(jsCombinatoricsSpy.combination).toHaveBeenCalledWith(
                    cards, 2);
            });

        it(
            'returns 0 if no js-combinatorics.combination() returned ' +
            'combination is a pair',
            function() {
                var fakeCards = [];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 3
                        }],
                        [{
                            ordinal: 11
                        }, {
                            ordinal: 7
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(0);
            });

        it(
            'returns 2 if one js-combinatorics.combination() returned ' +
            'combination is a pair',
            function() {
                var fakeCards = ['fakeCard1', 'fakeCard2'];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 3
                        }],
                        [{
                            ordinal: 8
                        }, {
                            ordinal: 8
                        }],
                        [{
                            ordinal: 13
                        }, {
                            ordinal: 1
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(2);
            });

        it(
            'returns 8 if four js-combinatorics.combination() returned ' +
            'combinations are pairs',
            function() {
                var fakeCards = ['fakeCard1', 'fakeCard2'];
                spyOn(jsCombinatoricsSpy, 'combination').and.returnValue(
                    [
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 2
                        }, {
                            ordinal: 2
                        }],
                        [{
                            ordinal: 6
                        }, {
                            ordinal: 6
                        }]
                    ]);
                expect(cribbageScoring.pairsPoints(
                    jsCombinatoricsSpy,
                    fakeCards)).toEqual(8);
            });

        it('returns 0 for a known index and an unknown index',
            function() {
                expect(cribbageScoring.pairsPoints(
                    jsCombinatorics, cribbageCard.parseIndices(
                        'AX'))).toEqual(0);
            });

        it('returns 0 for two unknown indices', function() {
            expect(cribbageScoring.pairsPoints(
                jsCombinatorics, cribbageCard.parseIndices(
                    'XY'))).toEqual(0);
        });
    });

    describe('fifteensPoints method', function() {
        it('is defined', function() {
            expect(cribbageScoring.fifteensPoints).toBeDefined();
        });

        it('returns undefined', function() {
            expect(cribbageScoring.fifteensPoints()).not.toBeDefined();
        });
    });
}());
{'fraction_non_alphanumeric': 0.09512240702672398, 'fraction_numerical': 0.008596524014202953, 'mean_word_length': 0.9385980800579605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715619', 'n_tokens_mistral': 2699, 'n_tokens_neox': 2466, 'n_words': 478}