pokemon-showdown/test/simulator/misc/statuses.js
Dan Pantry 9c65c5b84a add mock for battle tests that can reset the RNG
This enables battles in tests to reset their RNG to what it originally
was when they were created. A number of tests do this already by
breaking encapsulating and modifying the prng variable directly. This
should fix that.

We also remove createBattleWithPRNG and min/maxSeed properties.

Firstly, the tests that were still using the maxSeed property were
setting it to Battle.seed which has no effect since the PRNG class does
not look at this property any more - so these were no-ops.

After removing this property from tests, maxRollSeed was never used, so
I removed it and renamed minRollSeed to DEFAULT_ROLL_SEED (since it's
constant).

The places that were still using minRollSeed also were no-ops or were
using createBattleWithPRNG. Since every single instance was actually
just using the same code, I removed createBattleWithPRNG and made
createBattle default to giving you a seed with DEFAULT_ROLL_SEED and
removed the minRollSeed property too.

This makes tests much simpler and reduces the usage surface of
TestTools; now, you must define your *own* seed if you're making a PRNG
for a test, or you use one that TestTools gives you; you may not use a
public property that TestTools gives you.

We also remove the code that removes a listener in the Battle Engine.
This was rendered obsolete by f6a7c4b (see more info [in the discussion
on github][disc]

[disc]:
https://github.com/Zarel/Pokemon-Showdown/pull/3272#discussion_r102414795
2017-02-22 20:44:20 -05:00

140 lines
4.9 KiB
JavaScript

'use strict';
const assert = require('./../../assert');
const common = require('./../../common');
let battle;
describe('Burn', function () {
afterEach(function () {
battle.destroy();
});
it('should inflict 1/16 of max HP at the end of the turn, rounded down', function () {
battle = common.createBattle([
[{species: 'Machamp', ability: 'noguard', moves: ['bulkup']}],
[{species: 'Sableye', ability: 'prankster', moves: ['willowisp']}],
]);
const target = battle.p1.active[0];
assert.hurtsBy(target, Math.floor(target.maxhp / 16), () => battle.commitDecisions());
});
it('should halve damage from most Physical attacks', function () {
battle = common.createBattle([
[{species: 'Machamp', ability: 'noguard', moves: ['boneclub']}],
[{species: 'Sableye', ability: 'prankster', moves: ['splash', 'willowisp']}],
]);
const target = battle.p2.active[0];
battle.commitDecisions();
const baseDamage = target.maxhp - target.hp;
battle.resetRNG();
battle.p2.chooseMove('willowisp');
assert.hurtsBy(target, battle.modify(baseDamage, 0.5), () => battle.commitDecisions());
});
it('should not halve damage from moves with set damage', function () {
battle = common.createBattle([
[{species: 'Machamp', ability: 'noguard', moves: ['seismictoss']}],
[{species: 'Talonflame', ability: 'galewings', moves: ['willowisp']}],
]);
assert.hurtsBy(battle.p2.active[0], 100, () => battle.commitDecisions());
});
});
describe('Paralysis', function () {
afterEach(function () {
battle.destroy();
});
it('should reduce speed to 50% of its original value', function () {
battle = common.createBattle();
battle.join('p1', 'Guest 1', 1, [{species: 'Vaporeon', ability: 'waterabsorb', moves: ['aquaring']}]);
battle.join('p2', 'Guest 2', 1, [{species: 'Jolteon', ability: 'voltabsorb', moves: ['thunderwave']}]);
let speed = battle.p1.active[0].getStat('spe');
battle.commitDecisions();
assert.strictEqual(battle.p1.active[0].getStat('spe'), battle.modify(speed, 0.5));
});
});
describe('Toxic Poison', function () {
afterEach(function () {
battle.destroy();
});
it('should inflict 1/16 of max HP rounded down, times the number of active turns with the status, at the end of the turn', function () {
battle = common.createBattle([
[{species: 'Chansey', ability: 'naturalcure', moves: ['softboiled']}],
[{species: 'Gengar', ability: 'levitate', moves: ['toxic']}],
]);
const target = battle.p1.active[0];
for (let i = 1; i <= 8; i++) {
battle.commitDecisions();
assert.strictEqual(target.maxhp - target.hp, Math.floor(target.maxhp / 16) * i);
}
});
it('should reset the damage counter when the Pokemon switches out', function () {
battle = common.createBattle([
[{species: 'Chansey', ability: 'serenegrace', moves: ['counter']}, {species: 'Snorlax', ability: 'immunity', moves: ['curse']}],
[{species: 'Crobat', ability: 'infiltrator', moves: ['toxic', 'whirlwind']}],
]);
for (let i = 0; i < 4; i++) {
battle.commitDecisions();
}
let pokemon = battle.p1.active[0];
pokemon.hp = pokemon.maxhp;
battle.p1.chooseSwitch(2).foe.chooseMove('whirlwind');
assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16));
});
});
describe('Burn [Gen 6]', function () {
afterEach(function () {
battle.destroy();
});
it('should inflict 1/8 of max HP at the end of the turn, rounded down', function () {
battle = common.gen(6).createBattle([
[{species: 'Machamp', ability: 'noguard', moves: ['bulkup']}],
[{species: 'Sableye', ability: 'prankster', moves: ['willowisp']}],
]);
const target = battle.p1.active[0];
assert.hurtsBy(target, Math.floor(target.maxhp / 8), () => battle.commitDecisions());
});
});
describe('Paralysis [Gen 6]', function () {
afterEach(function () {
battle.destroy();
});
it('should reduce speed to 25% of its original value', function () {
battle = common.gen(6).createBattle();
battle.join('p1', 'Guest 1', 1, [{species: 'Vaporeon', ability: 'waterabsorb', moves: ['aquaring']}]);
battle.join('p2', 'Guest 2', 1, [{species: 'Jolteon', ability: 'voltabsorb', moves: ['thunderwave']}]);
let speed = battle.p1.active[0].getStat('spe');
battle.commitDecisions();
assert.strictEqual(battle.p1.active[0].getStat('spe'), battle.modify(speed, 0.25));
});
});
describe('Toxic Poison [Gen 1]', function () {
afterEach(function () {
battle.destroy();
});
it('should affect Leech Seed damage counter', function () {
battle = common.gen(1).createBattle([
[{species: 'Venusaur', moves: ['toxic', 'leechseed']}],
[{species: 'Chansey', moves: ['splash']}],
]);
battle.commitDecisions();
let pokemon = battle.p2.active[0];
assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16));
battle.choose('p1', 'move 2');
battle.commitDecisions();
// (1/16) + (2/16) + (3/16) = (6/16)
assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16) * 6);
});
});