mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
This will save me a lot of time typing in `/eval`s on localhost to test, and also hopefully catch regressions!
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
/**
|
|
* Tools for testing Random Battles.
|
|
*
|
|
* @author Annika
|
|
*/
|
|
'use strict';
|
|
|
|
/**
|
|
* Unit test helper for Pokemon sets
|
|
*
|
|
* @param {ID} pokemon the ID of the Pokemon whose set is to be tested
|
|
* @param {{format?: string, rounds?: number, isDoubles?: boolean, isLead?: boolean, isDynamax?: boolean}} options
|
|
* @param {(set: RandomTeamsTypes.RandomSet) => void} test a function called on each set
|
|
*/
|
|
function testSet(pokemon, options, test) {
|
|
const generator = Dex.getTeamGenerator(options.format);
|
|
const rounds = options.rounds || 1000;
|
|
|
|
const isDoubles = options.isDoubles || (options.format && options.format.includes('doubles'));
|
|
const isDynamax = options.isDynamax || !(options.format && options.format.includes('nodmax'));
|
|
for (let i = 0; i < rounds; i++) {
|
|
const set = generator.randomSet(pokemon, {}, options.isLead, isDoubles, isDynamax);
|
|
test(set);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Unit test helper for Pokemon teams
|
|
*
|
|
* @param {{format?: string, rounds?: number}} options
|
|
* @param {(team: RandomTeamsTypes.RandomSet[]) => void} test a function called on each team
|
|
*/
|
|
function testTeam(options, test) {
|
|
const generator = Dex.getTeamGenerator(options.format);
|
|
const rounds = options.rounds || 1000;
|
|
|
|
for (let i = 0; i < rounds; i++) {
|
|
const team = generator.randomTeam();
|
|
test(team);
|
|
}
|
|
}
|
|
|
|
exports.testSet = testSet;
|
|
exports.testTeam = testTeam;
|