Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Remove repeated JSON.stringifys in assertSetValidity #10627

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions test/random-battles/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function testTeam(options, test) {
function assertSetValidity(format, set) {
const dex = Dex.forFormat(format);
const species = dex.species.get(set.species || set.name);
const setString = JSON.stringify(set);

// According to Random Battles room staff, we should not ensure that HP IVs are valid for
// BSS formats. This is because level 100 Pokémon can be hypertrained
Expand All @@ -132,25 +133,25 @@ function assertSetValidity(format, set) {
.validateStats(set, species, new PokemonSources())
// Suppress errors about mistaken EV quantities
.filter(f => !f.includes(' EVs'));
assert.equal(valid.length, 0, `Invalid stats: ${valid} (set: ${JSON.stringify(set)})`);
assert.equal(valid.length, 0, `Invalid stats: ${valid} (set: ${setString})`);
}

// We check `dex.gen` here because Format#gen is 0 in the current gen, while ModdedDex#gen is never 0.
assert(species.exists, `The species "${species.name}" does not exist. (set: ${JSON.stringify(set)})`);
assert(species.gen <= dex.gen, `The species "${species.name}" is from a newer generation. (set: ${JSON.stringify(set)})`);
assert(species.exists, `The species "${species.name}" does not exist. (set: ${setString})`);
assert(species.gen <= dex.gen, `The species "${species.name}" is from a newer generation. (set: ${setString})`);

if (set.item) {
const item = dex.items.get(set.item);
assert(item.exists, `The item "${item.name}" does not exist. (set: ${JSON.stringify(set)})`);
assert(item.gen <= dex.gen, `The item "${item.name}" is from a newer generation. (set: ${JSON.stringify(set)})`);
assert(item.exists, `The item "${item.name}" does not exist. (set: ${setString})`);
assert(item.gen <= dex.gen, `The item "${item.name}" is from a newer generation. (set: ${setString})`);
}

if (set.ability && set.ability !== 'None') {
const ability = dex.abilities.get(set.ability);
assert(ability.exists, `The ability "${ability.name}" does not exist. (set: ${JSON.stringify(set)})`);
assert(ability.gen <= dex.gen, `The ability "${ability.name}" is from a newer generation. (set: ${JSON.stringify(set)})`);
assert(ability.exists, `The ability "${ability.name}" does not exist. (set: ${setString})`);
assert(ability.gen <= dex.gen, `The ability "${ability.name}" is from a newer generation. (set: ${setString})`);
} else {
assert(dex.gen < 3, `This set does not have an ability, but is intended for use in Gen 3 or later. (set: ${JSON.stringify(set)})`);
assert(dex.gen < 3, `This set does not have an ability, but is intended for use in Gen 3 or later. (set: ${setString})`);
}

// Arceus plate check
Expand All @@ -163,7 +164,7 @@ function assertSetValidity(format, set) {
assert(set.item.endsWith(' Plate'), `${species.name} doesn't have a Plate (got "${set.item}" instead)`);
}

assert(set.moves.filter(m => m.startsWith('hiddenpower')).length <= 1, `This set has multiple Hidden Power moves. (set: ${JSON.stringify(set)})`);
assert(set.moves.filter(m => m.startsWith('hiddenpower')).length <= 1, `This set has multiple Hidden Power moves. (set: ${setString})`);
}

/**
Expand Down
Loading