From 2bceebaac8c8dd951f79cd813be165ebdf5d994f Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Sat, 19 Nov 2016 16:11:37 -0500 Subject: [PATCH] Test: Add coverage for random team generators --- test/simulator/misc/random-teams.js | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/simulator/misc/random-teams.js diff --git a/test/simulator/misc/random-teams.js b/test/simulator/misc/random-teams.js new file mode 100644 index 0000000000..f02d99ad61 --- /dev/null +++ b/test/simulator/misc/random-teams.js @@ -0,0 +1,82 @@ +'use strict'; + +const common = require('./../../common'); + +let battle; + +const TOTAL_TEAMS = 300; + +function isValidSet(set) { + if (!Tools.getTemplate(set.species || set.name).exists) return false; + if (!Tools.getItem(set.item).exists) return false; + if (!Tools.getAbility(set.ability).exists) return false; + return true; +} + +describe(`Random Team generator`, function () { + afterEach(() => battle.destroy()); + + it(`should successfully create valid teams`, function () { + this.timeout(0); + battle = common.createBattle([[{species: "Mew", ability: 'pressure', moves: ['struggle']}], [{species: "Mew", ability: 'pressure', moves: ['struggle']}]]); + battle.seed = battle.generateSeed(); + + let teamCount = TOTAL_TEAMS; + while (teamCount--) { + let seed = battle.seed.slice(); + let team = null; + try { + team = battle.randomTeam(battle.p1); + if (team.some(set => !isValidSet(set))) throw new Error(`Invalid set`); + } catch (err) { + throw new Error(`Failed to create a valid random team from seed ${seed}`); + } + } + }); +}); + +describe(`Challenge Cup Team generator`, function () { + afterEach(() => battle.destroy()); + + it(`should successfully create valid teams`, function () { + this.timeout(0); + battle = common.createBattle([[{species: "Mew", ability: 'pressure', moves: ['struggle']}], [{species: "Mew", ability: 'pressure', moves: ['struggle']}]]); + battle.seed = battle.generateSeed(); + + let teamCount = TOTAL_TEAMS; + while (teamCount--) { + let seed = battle.seed.slice(); + let team = null; + try { + team = battle.randomCCTeam(battle.p1); + if (team.some(set => !isValidSet(set))) throw new Error(`Invalid set`); + } catch (err) { + err.message += ` (seed ${seed})`; + throw err; + } + } + }); +}); + +describe(`Hackmons Cup Team generator`, function () { + afterEach(() => battle.destroy()); + + it(`should successfully create valid teams`, function () { + this.timeout(0); + battle = common.createBattle([[{species: "Mew", ability: 'pressure', moves: ['struggle']}], [{species: "Mew", ability: 'pressure', moves: ['struggle']}]]); + battle.seed = battle.generateSeed(); + + let teamCount = TOTAL_TEAMS; + while (teamCount--) { + let seed = battle.seed.slice(); + let team = null; + try { + team = battle.randomHCTeam(battle.p1); + if (team.some(set => !isValidSet(set))) throw new Error(`Invalid set`); + } catch (err) { + err.message += ` (seed ${seed})`; + throw err; + } + } + }); +});