dimanche 25 décembre 2016

How to Test Random Output?

The code below is used to play a Lottery game.

let Lotto = {
    _nMap: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50
    ],
    _sMap: [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
    ],

    /**
     * @param {Array} shuffleArr
     *
     * @return {Array}
     */
    _shuffleArr(shuffleArr) {
        let rndNr, tmpValue;

        for (let elmNr = shuffleArr.length - 1; elmNr > 0; elmNr--) {
            rndNr = Math.floor(
                Math.random() * (elmNr + 1)
            );

            tmpValue = shuffleArr[rndNr];

            shuffleArr[rndNr] = shuffleArr[elmNr];
            shuffleArr[elmNr] = tmpValue;
        }

        return shuffleArr;
    },

    /**
     * @return {Object}
     */
    getPick() {
        return {
            n: this._shuffleArr(this._nMap).slice(0, 5),
            s: this._shuffleArr(this._sMap).slice(0, 2)
        }
    }
};

Now I want to verify whether the implementation is correct. For example: it should return a unique set of numbers. How do I test this? Run the .getPick() method once and validate the output or ...?




Aucun commentaire:

Enregistrer un commentaire