mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-23 08:16:16 -05:00
108 lines
2.7 KiB
JavaScript
108 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('./../../common');
|
|
|
|
let battle;
|
|
|
|
const TOTAL_TEAMS = 100;
|
|
const ALL_GENS = [1, 2/*, 3, 4*/, 5, 6, 7];
|
|
|
|
function isValidSet(gen, set) {
|
|
const tools = Tools.mod(`gen${gen}`);
|
|
const template = tools.getTemplate(set.species || set.name);
|
|
if (!template.exists || template.gen > gen) return false;
|
|
if (set.item) {
|
|
const item = tools.getItem(set.item);
|
|
if (!item.exists || item.gen > gen) {
|
|
return false;
|
|
}
|
|
}
|
|
if (set.ability && set.ability !== 'None') {
|
|
const ability = tools.getAbility(set.ability);
|
|
if (!ability.exists || ability.gen > gen) {
|
|
return false;
|
|
}
|
|
} else if (gen >= 3) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
describe(`Random Team generator`, function () {
|
|
afterEach(() => battle.destroy());
|
|
|
|
for (const gen of ALL_GENS) {
|
|
it(`should successfully create valid Gen ${gen} teams`, function () {
|
|
this.timeout(0);
|
|
battle = common.gen(gen).createBattle();
|
|
battle.seed = battle.generateSeed();
|
|
|
|
let teamCount = TOTAL_TEAMS;
|
|
while (teamCount--) {
|
|
let seed = battle.seed.slice();
|
|
let team = null;
|
|
try {
|
|
team = battle.randomTeam(battle.p1);
|
|
let invalidSet = team.find(set => !isValidSet(gen, set));
|
|
if (invalidSet) throw new Error(`Invalid set: ${JSON.stringify(invalidSet)}`);
|
|
} catch (err) {
|
|
err.message += ` (seed ${seed})`;
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
describe(`Challenge Cup Team generator`, function () {
|
|
afterEach(() => battle.destroy());
|
|
|
|
for (const gen of ALL_GENS) {
|
|
it(`should successfully create valid Gen ${gen} teams`, function () {
|
|
this.timeout(0);
|
|
battle = common.gen(gen).createBattle();
|
|
battle.seed = battle.generateSeed();
|
|
|
|
let teamCount = TOTAL_TEAMS;
|
|
while (teamCount--) {
|
|
let seed = battle.seed.slice();
|
|
let team = null;
|
|
try {
|
|
team = battle.randomCCTeam(battle.p1);
|
|
let invalidSet = team.find(set => !isValidSet(gen, set));
|
|
if (invalidSet) throw new Error(`Invalid set: ${JSON.stringify(invalidSet)}`);
|
|
} catch (err) {
|
|
err.message += ` (seed ${seed})`;
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
describe(`Hackmons Cup Team generator`, function () {
|
|
afterEach(() => battle.destroy());
|
|
|
|
for (const gen of ALL_GENS) {
|
|
it(`should successfully create valid Gen ${gen} teams`, function () {
|
|
this.timeout(0);
|
|
battle = common.gen(gen).createBattle();
|
|
battle.seed = battle.generateSeed();
|
|
|
|
let teamCount = TOTAL_TEAMS;
|
|
while (teamCount--) {
|
|
let seed = battle.seed.slice();
|
|
let team = null;
|
|
try {
|
|
team = battle.randomHCTeam(battle.p1);
|
|
let invalidSet = team.find(set => !isValidSet(gen, set));
|
|
if (invalidSet) throw new Error(`Invalid set: ${JSON.stringify(invalidSet)}`);
|
|
} catch (err) {
|
|
err.message += ` (seed ${seed})`;
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|