pokemon-showdown/test/server/cg-teams.js
Guangcong Luo 78439b4a02
Update to ESLint 9 (#10926)
ESLint has a whole new config format, so I figure it's a good time to
make the config system saner.

- First, we no longer have separate eslint-no-types configs. Lint
  performance shouldn't be enough of a problem to justify the
  relevant maintenance complexity.

- Second, our base config should work out-of-the-box now. `npx eslint`
  will work as expected, without any CLI flags. You should still use
  `npm run lint` which adds the `--cached` flag for performance.

- Third, whatever updates I did fixed style linting, which apparently
  has been bugged for quite some time, considering all the obvious
  mixed-tabs-and-spaces issues I found in the upgrade.

Also here are some changes to our style rules. In particular:

- Curly brackets (for objects etc) now have spaces inside them. Sorry
  for the huge change. ESLint doesn't support our old style, and most
  projects use Prettier style, so we might as well match them in this way.
  See https://github.com/eslint-stylistic/eslint-stylistic/issues/415

- String + number concatenation is no longer allowed. We now
  consistently use template strings for this.
2025-02-25 20:03:46 -08:00

62 lines
2.4 KiB
JavaScript

'use strict';
const assert = require('assert').strict;
const TeamGenerator = require('../../dist/data/cg-teams').default;
describe('[Gen 9] Computer-Generated Teams', () => {
it.skip('should give all species 4 or fewer moves', () => {
const generator = new TeamGenerator();
const pool = generator.dex.species
.all()
.filter(s => s.exists && !(s.isNonstandard || s.isNonstandard === 'Unobtainable') && !s.nfe);
for (const species of pool) {
const set = generator.makeSet(species, { hazardSetters: {} });
assert(set.moves.length <= 4, `Species ${species.name} has more than 4 moves (set=${JSON.stringify(set)})`);
assert(new Set(set.moves).size === set.moves.length, `Species ${species.name} has duplicate moves (set=${JSON.stringify(set)})`);
}
});
// Skipped since it includes randomness; useful for debugging though
it.skip('should have an accurate weighted picker', () => {
const generator = new TeamGenerator();
const numTrials = 100000;
let error = 0;
let trials = 0;
for (const choices of [
[{ choice: 'a', weight: 1 }, { choice: 'b', weight: 2 }],
[{ choice: 'a', weight: 1 }, { choice: 'b', weight: 1 }],
[{ choice: 'a', weight: 30 }, { choice: 'b', weight: 2000 }, { choice: 'c', weight: 7 }],
// a big test case with lots of different weight values
[
{ choice: 'a', weight: 1345 }, { choice: 'b', weight: 2013 }, { choice: 'c', weight: 3411 }, { choice: 'd', weight: 940 },
{ choice: 'e', weight: 505 }, { choice: 'f', weight: 10148 }, { choice: 'g', weight: 7342 }, { choice: 'h', weight: 8403 },
{ choice: 'i', weight: 9859 }, { choice: 'j', weight: 1042 }, { choice: 'k', weight: 1132 }, { choice: 'l', weight: 1200 },
],
]) {
const results = {};
for (let i = 0; i < numTrials; i++) {
const res = generator.weightedRandomPick(choices.map(x => x.choice), c => choices.find(x => x.choice === c)?.weight || 0);
// console.log(`"${res}"`);
if (!results[res]) results[res] = 0;
results[res]++;
}
let totalWeight = 0;
for (const choice of choices) {
totalWeight += choice.weight;
}
for (const [choice, count] of Object.entries(results)) {
const c = choices.find(x => x.choice === choice);
const expected = (c.weight / totalWeight) * numTrials;
error += Math.abs(count - expected) / expected;
trials++;
}
}
const percentError = (error / trials) * 100;
assert(percentError < 3, `Weighted picker error is too high: ${percentError.toFixed(1)}%`);
});
});