Skip to content

Commit

Permalink
Test: Correct several format IDs (#10633)
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-the-table-guy authored Oct 29, 2024
1 parent 13ee244 commit 71fe7bd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
9 changes: 6 additions & 3 deletions sim/team-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ export class TeamValidator {
readonly toID: (str: any) => ID;
constructor(format: string | Format, dex = Dex) {
this.format = dex.formats.get(format);
if (this.format.effectType !== 'Format') {
throw new Error(`format should be a 'Format', but was a '${this.format.effectType}'`);
}
this.dex = dex.forFormat(this.format);
this.gen = this.dex.gen;
this.ruleTable = this.dex.formats.getRuleTable(this.format);
Expand Down Expand Up @@ -465,7 +468,7 @@ export class TeamValidator {
}

for (const rule of ruleTable.keys()) {
if ('!+-'.includes(rule.charAt(0))) continue;
if ('!+-*'.includes(rule.charAt(0))) continue;
const subformat = dex.formats.get(rule);
if (subformat.onValidateTeam && ruleTable.has(subformat.id)) {
problems = problems.concat(subformat.onValidateTeam.call(this, team, format, teamHas) || []);
Expand Down Expand Up @@ -615,7 +618,7 @@ export class TeamValidator {
const setSources = this.allSources(species);

for (const [rule] of ruleTable) {
if ('!+-'.includes(rule.charAt(0))) continue;
if ('!+-*'.includes(rule.charAt(0))) continue;
const subformat = dex.formats.get(rule);
if (subformat.onChangeSet && ruleTable.has(subformat.id)) {
problems = problems.concat(subformat.onChangeSet.call(this, set, format, setHas, teamHas) || []);
Expand Down Expand Up @@ -1046,7 +1049,7 @@ export class TeamValidator {
}

for (const [rule] of ruleTable) {
if ('!+-'.includes(rule.charAt(0))) continue;
if ('!+-*'.includes(rule.charAt(0))) continue;
const subformat = dex.formats.get(rule);
if (subformat.onValidateSet && ruleTable.has(subformat.id)) {
problems = problems.concat(subformat.onValidateSet.call(this, set, format, setHas, teamHas) || []);
Expand Down
10 changes: 7 additions & 3 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DEFAULT_SEED = [0x09917, 0x06924, 0x0e1c8, 0x06af0];
class TestTools {
constructor(mod = 'base') {
this.currentMod = mod;
this.dex = Dex.mod(mod);
this.dex = Dex.mod(mod).includeData(); // ensure that gen is initialized

this.modPrefix = this.dex.isBase ? `[gen9] ` : `[${mod}] `;
}
Expand All @@ -42,7 +42,11 @@ class TestTools {
}

getFormat(options) {
if (options.formatid) return Dex.formats.get(options.formatid);
if (options.formatid) {
const format = Dex.formats.get(options.formatid);
if (format.effectType !== 'Format') throw new Error(`Unidentified format: ${options.formatid}`);
return format;
}

const gameType = Dex.toID(options.gameType || 'singles');
const customRules = [
Expand Down Expand Up @@ -73,7 +77,7 @@ class TestTools {
if (format) return format;

format = Dex.formats.get(formatName);
if (!format.exists) throw new Error(`Unidentified format: ${formatName}`);
if (format.effectType !== 'Format') throw new Error(`Unidentified format: ${formatName}`);

formatsCache.set(formatName, format);
return format;
Expand Down
22 changes: 15 additions & 7 deletions test/random-battles/all-gens.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';

const assert = require('../assert');
const common = require('../common');
const {Utils} = require('../../dist/lib');
const {testTeam, assertSetValidity, validateLearnset} = require('./tools');
const {default: Dex} = require('../../dist/sim/dex');
Expand Down Expand Up @@ -152,18 +153,17 @@ describe("New set format (slow)", () => {
filename: "gen9baby/sets",
roles: ["Fast Attacker", "Setup Sweeper", "Wallbreaker", "Tera Blast user", "Bulky Attacker", "Bulky Setup", "Bulky Support", "Fast Support"],
},
"gen9caprandombattle": {
"gen9randombattle@@@+cap": {
filename: "gen9cap/sets",
roles: ["Fast Attacker", "Setup Sweeper", "Wallbreaker", "Tera Blast user", "Bulky Attacker", "Bulky Setup", "Fast Bulky Setup", "Bulky Support", "Fast Support", "AV Pivot"],
},
};
for (const format of Object.keys(formatInfo)) {
const filename = formatInfo[format].filename;
const setsJSON = require(`../../dist/data/random-battles/${filename}.json`);
const mod = filename.split('/')[0];
const genNum = parseInt(mod[3]);
const dex = common.mod(common.getFormat({formatid: format}).mod).dex; // verifies format exists
const genNum = dex.gen;
const rounds = 100;
const dex = Dex.forFormat(format);
it(`${filename}.json should have valid set data`, () => {
const validRoles = formatInfo[format].roles;
for (const [id, sets] of Object.entries(setsJSON)) {
Expand Down Expand Up @@ -304,8 +304,16 @@ describe('Battle Factory and BSS Factory data should be valid (slow)', () => {

for (const type in setsJSON) {
const typeTable = filename.includes('bss-factory-sets') ? setsJSON : setsJSON[type];
const vType = filename.includes('bss-factory-sets') ? `battle${genNum === 8 ? 'stadium' : 'spot'}singles` :
type === 'Mono' ? 'monotype' : type.toLowerCase();
let vType;
if (filename.includes('bss-factory-sets')) {
vType = `battle${genNum === 8 ? 'stadium' : 'spot'}singles`;
} else if (type === 'Mono') {
vType = 'monotype';
} else if (type === 'Uber') {
vType = 'ubers';
} else {
vType = type.toLowerCase();
}
for (const species in typeTable) {
const speciesData = typeTable[species];
for (const set of speciesData.sets) {
Expand Down Expand Up @@ -372,7 +380,7 @@ describe('[Gen 9] BSS Factory data should be valid (slow)', () => {
const genNum = 9;

for (const speciesid in setsJSON) {
const vType = 'battlestadiumsingles';
const vType = 'bssregh';
let totalWeight = 0;
for (const set of setsJSON[speciesid].sets) {
totalWeight += set.weight;
Expand Down
3 changes: 2 additions & 1 deletion test/sim/misc/megaevolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ describe('Mega Evolution', function () {
assertLegalButCantMega('gen9nationaldexag@@@-ndag');

// don't add it where unnecessary
assert.false(Dex.formats.getRuleTable(Dex.formats.get('gen5anythinggoes')).has('megarayquazaclause'));
const format = common.getFormat({formatid: 'gen4anythinggoes'});
assert.false(Dex.formats.getRuleTable(format).has('megarayquazaclause'));
});
});
});
8 changes: 4 additions & 4 deletions test/sim/team-validator/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ describe('Team Validator', function () {
const team = [
{species: 'xerneas', ability: 'fairyaura', moves: ['snore'], ivs: {hp: 0, atk: 0, def: 0, spa: 0}, evs: {hp: 1}},
];
assert.false.legalTeam(team, 'gen8anythinggoes');
assert.false.legalTeam(team, 'gen9anythinggoes');

assert.legalTeam(team, 'gen8purehackmons');
assert.legalTeam(team, 'gen9purehackmons');
});

it('should reject non-existent natures', function () {
Expand Down Expand Up @@ -204,9 +204,9 @@ describe('Team Validator', function () {
const team = [
{species: 'corsola', ability: 'hustle', moves: ['snore', 'snore'], evs: {hp: 1}},
];
assert.false.legalTeam(team, 'gen8anythinggoes');
assert.false.legalTeam(team, 'gen9anythinggoes');

assert.legalTeam(team, 'gen8purehackmons');
assert.legalTeam(team, 'gen9purehackmons');
});

it('should accept VC moves only with Hidden ability and correct IVs', function () {
Expand Down

0 comments on commit 71fe7bd

Please sign in to comment.