From 5976efea2bf0c8f0efb3587ec4be5c786c8261fb Mon Sep 17 00:00:00 2001 From: Kevin Lau Date: Thu, 16 Apr 2015 13:04:19 -0700 Subject: [PATCH] Add Mocha tests for status effects --- test/simulator/misc/statuses.js | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/simulator/misc/statuses.js diff --git a/test/simulator/misc/statuses.js b/test/simulator/misc/statuses.js new file mode 100644 index 0000000000..b6079a6b7b --- /dev/null +++ b/test/simulator/misc/statuses.js @@ -0,0 +1,89 @@ +var assert = require('assert'); +var battle; + +describe('Burn', function () { + afterEach(function () { + battle.destroy(); + }); + + it('should inflict 1/8 of max HP at the end of the turn, rounded down', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: 'Machamp', ability: 'noguard', moves: ['bulkup']}]); + battle.join('p2', 'Guest 2', 1, [{species: 'Sableye', ability: 'prankster', moves: ['willowisp']}]); + battle.commitDecisions(); + var pokemon = battle.p1.active[0]; + assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 8)); + }); + + it('should halve damage from most Physical attacks', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: 'Machamp', ability: 'noguard', moves: ['boneclub']}]); + battle.join('p2', 'Guest 2', 1, [{species: 'Sableye', ability: 'prankster', moves: ['splash', 'willowisp']}]); + battle.seed = [0, 0, 0, 0]; + battle.commitDecisions(); + var pokemon = battle.p2.active[0]; + var damage = pokemon.maxhp - pokemon.hp; + pokemon.hp = pokemon.maxhp; + battle.seed = [0, 0, 0, 0]; + battle.choose('p2', 'move 2'); + battle.commitDecisions(); + assert.strictEqual(pokemon.maxhp - pokemon.hp, battle.modify(damage, 0.5)); + }); + + it('should not halve damage from moves with set damage', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: 'Machamp', ability: 'noguard', moves: ['seismictoss']}]); + battle.join('p2', 'Guest 2', 1, [{species: 'Talonflame', ability: 'galewings', moves: ['willowisp']}]); + battle.commitDecisions(); + assert.strictEqual(battle.p2.active[0].maxhp - battle.p2.active[0].hp, 100); + }); +}); + +describe('Paralysis', function () { + afterEach(function () { + battle.destroy(); + }); + + it('should reduce speed to 25% of its original value', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: 'Vaporeon', ability: 'waterabsorb', moves: ['aquaring']}]); + battle.join('p2', 'Guest 2', 1, [{species: 'Jolteon', ability: 'voltabsorb', moves: ['thunderwave']}]); + var 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', 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 = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [{species: 'Chansey', ability: 'naturalcure', moves: ['softboiled']}]); + battle.join('p2', 'Guest 2', 1, [{species: 'Gengar', ability: 'levitate', moves: ['toxic']}]); + var pokemon = battle.p1.active[0]; + for (var i = 1; i <= 8; i++) { + battle.commitDecisions(); + assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16) * i); + } + }); + + it('should reset the damage counter when the Pokemon switches out', function () { + battle = BattleEngine.Battle.construct(); + battle.join('p1', 'Guest 1', 1, [ + {species: 'Chansey', ability: 'serenegrace', moves: ['counter']}, + {species: 'Snorlax', ability: 'immunity', moves: ['curse']} + ]); + battle.join('p2', 'Guest 2', 1, [{species: 'Crobat', ability: 'infiltrator', moves: ['toxic', 'whirlwind']}]); + for (var i = 0; i < 4; i++) { + battle.commitDecisions(); + } + var pokemon = battle.p1.active[0]; + pokemon.hp = pokemon.maxhp; + battle.choose('p1', 'switch 2'); + battle.choose('p2', 'move 2'); + assert.strictEqual(pokemon.maxhp - pokemon.hp, Math.floor(pokemon.maxhp / 16)); + }); +});