Skip to content

Commit

Permalink
Test: Refactor testTeam and testSet (#10651)
Browse files Browse the repository at this point in the history
Use `setSeed` instead of constructing a new generator where only the seed differs.
  • Loading branch information
larry-the-table-guy authored Nov 8, 2024
1 parent 5d014a8 commit e96e474
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions test/random-battles/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ function testSet(pokemon, options, test) {

const isDoubles = options.isDoubles || (options.format && options.format.includes('doubles'));
const isDynamax = options.isDynamax || !(options.format && options.format.includes('nodmax'));
const generator = Teams.getGenerator(options.format, [0, 0, 0, 0]);
for (let i = 0; i < rounds; i++) {
// If undefined, test lead 1/6 of the time
const isLead = options.isLead === undefined ? i % 6 === 2 : options.isLead;
const generator = Teams.getGenerator(options.format, options.seed || [i, i, i, i]);
generator.setSeed(options.seed || [i, i, i, i]);
const set = generator.randomSet(pokemon, {}, isLead, isDoubles, isDynamax);
test(set);
}
Expand Down Expand Up @@ -107,8 +108,9 @@ function testAlwaysHasMove(pokemon, options, move) {
function testTeam(options, test) {
const rounds = options.rounds || 1000;

const generator = Teams.getGenerator(options.format, [0, 0, 0, 0]);
for (let i = 0; i < rounds; i++) {
const generator = Teams.getGenerator(options.format, options.seed || [i, i, i, i]);
generator.setSeed(options.seed || [i, i, i, i]);
const team = generator.getTeam();
test(team);
}
Expand Down

0 comments on commit e96e474

Please sign in to comment.