Skip to content

Commit

Permalink
Improve seed-passing experience in test API
Browse files Browse the repository at this point in the history
Now, seeds are passed as arrays, rather than needing to pass an entire
PRNG object. In addition, they're now passed in the options object,
instead of as a separate argument.

This is done mostly so the Miracle Eye can be rewritten with a custom
seed, which requires fewer turns and should overall be faster. Which
was in turn done because a Miracle Eye timed out on Travis CI earlier.
Overall, the speed increase is pretty negligible, so this is mostly
just about improving the test API.
  • Loading branch information
Zarel committed Jan 18, 2018
1 parent 3d643cf commit 72d4f73
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
12 changes: 7 additions & 5 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,19 @@ class TestTools {
*
* @param {Object} [options]
* @param {Team[]} [teams]
* @param {PRNG} [prng] A pseudo-random number generator. If not provided, a pseudo-random number
* generator will be generated for the user with a seed that is guaranteed to be the same across
* test executions to help with determinism.
* @returns {Sim.Battle} A battle.
*/
createBattle(options, teams, prng = new PRNG(DEFAULT_SEED)) {
createBattle(options, teams) {
if (Array.isArray(options)) {
teams = options;
options = {};
}
const format = this.getFormat(options || {});
if (!options) options = {};
// If a seed for the pseudo-random number generator is not provided,
// a default seed (guaranteed to be the same across test executions)
// will be used. The default seed is intentionally tuned
let prng = new PRNG(options.seed || DEFAULT_SEED);
const format = this.getFormat(options);
const battle = Sim.construct(
format.id,
undefined,
Expand Down
5 changes: 2 additions & 3 deletions test/simulator/abilities/dancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const assert = require('./../../assert');
const common = require('./../../common');
const PRNG = require('./../../../sim/prng');

let battle;

Expand Down Expand Up @@ -55,7 +54,7 @@ describe('Dancer', function () {
});

it('should not copy a move that failed or was blocked by Protect', function () {
battle = common.createBattle({gameType: 'doubles'}, null, new PRNG([1, 2, 3, 4]));
battle = common.createBattle({gameType: 'doubles', seed: [1, 2, 3, 4]});
const p1 = battle.join('p1', 'Guest 1', 1, [
{species: 'Oricorio', level: 98, ability: 'dancer', item: 'laggingtail', moves: ['dragondance', 'protect', 'teeterdance']},
{species: 'Oricorio', level: 99, ability: 'dancer', moves: ['featherdance']},
Expand Down Expand Up @@ -90,7 +89,7 @@ describe('Dancer', function () {
});

it('should not copy a move that missed', function () {
battle = common.createBattle({gameType: 'singles'}, null, new PRNG([1, 2, 3, 4]));
battle = common.createBattle({gameType: 'singles', seed: [1, 2, 3, 4]});
const p1 = battle.join('p1', 'Guest 1', 1, [{species: 'Oricorio', ability: 'dancer', item: 'choicescarf', moves: ['revelationdance']}]);
const p2 = battle.join('p2', 'Guest 2', 1, [{species: 'Oricorio', ability: 'dancer', item: 'brightpowder', moves: ['dig']}]);
p1.active[0].boostBy({accuracy: -6});
Expand Down
42 changes: 23 additions & 19 deletions test/simulator/moves/miracleeye.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ describe('Miracle Eye', function () {
});

it('should negate Psychic immunities', function () {
battle = common.createBattle();
battle.join('p1', 'Guest 1', 1, [{species: "Smeargle", ability: 'owntempo', moves: ['miracleeye', 'psychic']}]);
battle.join('p2', 'Guest 2', 1, [{species: "Darkrai", ability: 'baddreams', moves: ['nastyplot']}]);
battle.commitDecisions();
battle.choose('p1', 'move 2');
battle.commitDecisions();
battle = common.createBattle({seed: [1, 2, 3, 4]}, [[
{species: "Smeargle", moves: ['miracleeye', 'psychic']},
], [
{species: "Darkrai", moves: ['nastyplot']},
]]);
battle.makeChoices('move miracle eye', 'move nasty plot');
battle.makeChoices('move psychic', 'move nasty plot');
assert.notStrictEqual(battle.p2.active[0].hp, battle.p2.active[0].maxhp);
});

it('should ignore the effect of positive evasion stat stages', function () {
battle = common.createBattle();
battle.join('p1', 'Guest 1', 1, [{species: "Smeargle", ability: 'owntempo', moves: ['avalanche', 'miracleeye']}]);
battle.join('p2', 'Guest 2', 1, [{species: "Forretress", ability: 'sturdy', moves: ['synthesis']}]);
battle.choose('p1', 'move 2');
battle.commitDecisions();
battle = common.createBattle({seed: [1, 2, 3, 4]}, [[
{species: "Smeargle", moves: ['avalanche', 'miracleeye']},
], [
{species: "Forretress", moves: ['synthesis']},
]]);
battle.makeChoices('move miracle eye', 'move synthesis');
battle.boost({evasion: 6}, battle.p2.active[0]);
for (let i = 0; i < 16; i++) {
battle.commitDecisions();
for (let i = 0; i < 3; i++) {
battle.makeChoices('move avalanche', 'move synthesis');
assert.notStrictEqual(battle.p2.active[0].hp, battle.p2.active[0].maxhp);
}
});

it('should not ignore the effect of negative evasion stat stages', function () {
battle = common.createBattle();
battle.join('p1', 'Guest 1', 1, [{species: "Smeargle", ability: 'owntempo', moves: ['zapcannon', 'dynamicpunch', 'miracleeye']}]);
battle.join('p2', 'Guest 2', 1, [{species: "Zapdos", ability: 'owntempo', moves: ['roost']}]);
battle = common.createBattle({seed: [1, 2, 3, 4]}, [[
{species: "Smeargle", moves: ['zapcannon', 'miracleeye']},
], [
{species: "Zapdos", moves: ['roost']},
]]);
battle.choose('p1', 'move 3');
battle.commitDecisions();
battle.makeChoices('move miracle eye', 'move roost');
battle.boost({spe: 6, evasion: -6}, battle.p2.active[0]);
for (let i = 0; i < 16; i++) {
battle.commitDecisions();
for (let i = 0; i < 3; i++) {
battle.makeChoices('move zap cannon', 'move roost');
assert.notStrictEqual(battle.p2.active[0].hp, battle.p2.active[0].maxhp);
}
});
Expand Down

0 comments on commit 72d4f73

Please sign in to comment.