mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Adjust test mocks to use typed arrays
This commit is contained in:
parent
1a179cc9cb
commit
5ec0088ffc
@ -220,7 +220,7 @@ async function summonPlayerPokemon() {
|
||||
false,
|
||||
true,
|
||||
);
|
||||
wobbuffet.ivs = [0, 0, 0, 0, 0, 0];
|
||||
wobbuffet.ivs.set([0, 0, 0, 0, 0, 0]);
|
||||
wobbuffet.setNature(Nature.MILD);
|
||||
wobbuffet.setAlpha(0);
|
||||
wobbuffet.setVisible(false);
|
||||
|
@ -38,7 +38,7 @@ describe("Abilities - Beast Boost", () => {
|
||||
|
||||
const playerPokemon = game.field.getPlayerPokemon();
|
||||
// Set the pokemon's highest stat to DEF, so it should be picked by Beast Boost
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue([10000, 100, 1000, 200, 100, 100]);
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue(Uint32Array.of(10000, 100, 1000, 200, 100, 100));
|
||||
console.log(playerPokemon.stats);
|
||||
|
||||
expect(playerPokemon.getStatStage(Stat.DEF)).toBe(0);
|
||||
@ -56,7 +56,7 @@ describe("Abilities - Beast Boost", () => {
|
||||
|
||||
const playerPokemon = game.field.getPlayerPokemon();
|
||||
// If the opponent uses Guard Split, the pokemon's second highest stat (SPATK) should be chosen
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue([10000, 100, 201, 200, 100, 100]);
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue(Uint32Array.of(10000, 100, 201, 200, 100, 100));
|
||||
|
||||
expect(playerPokemon.getStatStage(Stat.SPATK)).toBe(0);
|
||||
|
||||
@ -75,7 +75,7 @@ describe("Abilities - Beast Boost", () => {
|
||||
const playerPokemon = game.field.getPlayerPokemon();
|
||||
|
||||
// Set up tie between SPATK, SPDEF, and SPD, where SPATK should win
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue([10000, 1, 1, 100, 100, 100]);
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue(Uint32Array.of(10000, 1, 1, 100, 100, 100));
|
||||
|
||||
expect(playerPokemon.getStatStage(Stat.SPATK)).toBe(0);
|
||||
|
||||
|
@ -39,8 +39,8 @@ describe("Battle order", () => {
|
||||
const enemyPokemon = game.field.getEnemyPokemon();
|
||||
const enemyStartHp = enemyPokemon.hp;
|
||||
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 50]); // set playerPokemon's speed to 50
|
||||
vi.spyOn(enemyPokemon, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150]); // set enemyPokemon's speed to 150
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 50)); // set playerPokemon's speed to 50
|
||||
vi.spyOn(enemyPokemon, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150)); // set enemyPokemon's speed to 150
|
||||
game.move.select(MoveId.TACKLE);
|
||||
|
||||
await game.phaseInterceptor.to("MoveEndPhase", false);
|
||||
@ -55,8 +55,8 @@ describe("Battle order", () => {
|
||||
const playerStartHp = playerPokemon.hp;
|
||||
const enemyPokemon = game.field.getEnemyPokemon();
|
||||
const enemyStartHp = enemyPokemon.hp;
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150]); // set playerPokemon's speed to 150
|
||||
vi.spyOn(enemyPokemon, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 50]); // set enemyPokemon's speed to 50
|
||||
vi.spyOn(playerPokemon, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150)); // set playerPokemon's speed to 150
|
||||
vi.spyOn(enemyPokemon, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 50)); // set enemyPokemon's speed to 50
|
||||
|
||||
game.move.select(MoveId.TACKLE);
|
||||
|
||||
@ -74,8 +74,8 @@ describe("Battle order", () => {
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
const enemyHps = enemyPokemon.map(p => p.hp);
|
||||
|
||||
playerPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 50])); // set both playerPokemons' speed to 50
|
||||
enemyPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150])); // set both enemyPokemons' speed to 150
|
||||
playerPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 50))); // set both playerPokemons' speed to 50
|
||||
enemyPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150))); // set both enemyPokemons' speed to 150
|
||||
|
||||
game.move.select(MoveId.TACKLE);
|
||||
game.move.select(MoveId.TACKLE, 1);
|
||||
@ -96,9 +96,9 @@ describe("Battle order", () => {
|
||||
|
||||
const playerPokemon = game.scene.getPlayerField();
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
playerPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 100])); //set both playerPokemons' speed to 100
|
||||
vi.spyOn(enemyPokemon[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 100]); // set enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyPokemon[1], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150]); // set enemyPokemon's speed to 150
|
||||
playerPokemon.forEach(p => vi.spyOn(p, "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 100))); //set both playerPokemons' speed to 100
|
||||
vi.spyOn(enemyPokemon[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 100)); // set enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyPokemon[1], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150)); // set enemyPokemon's speed to 150
|
||||
|
||||
game.move.select(MoveId.TACKLE);
|
||||
game.move.select(MoveId.TACKLE, 1);
|
||||
@ -114,10 +114,10 @@ describe("Battle order", () => {
|
||||
|
||||
const playerPokemon = game.scene.getPlayerField();
|
||||
const enemyPokemon = game.scene.getEnemyField();
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 100]); // set one playerPokemon's speed to 100
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150]); // set other playerPokemon's speed to 150
|
||||
vi.spyOn(enemyPokemon[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 100]); // set one enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyPokemon[1], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, 150]); // set other enemyPokemon's speed to 150
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 100)); // set one playerPokemon's speed to 100
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150)); // set other playerPokemon's speed to 150
|
||||
vi.spyOn(enemyPokemon[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 100)); // set one enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyPokemon[1], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, 150)); // set other enemyPokemon's speed to 150
|
||||
|
||||
game.move.select(MoveId.TACKLE);
|
||||
game.move.select(MoveId.TACKLE, 1);
|
||||
|
@ -38,7 +38,7 @@ describe("Escape chance calculations", () => {
|
||||
const enemyField = game.scene.getEnemyField();
|
||||
const enemySpeed = 100;
|
||||
// set enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemySpeed]);
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemySpeed));
|
||||
|
||||
const commandPhase = game.scene.phaseManager.getCurrentPhase() as CommandPhase;
|
||||
commandPhase.handleCommand(Command.RUN, 0);
|
||||
@ -81,14 +81,9 @@ describe("Escape chance calculations", () => {
|
||||
// set the number of escape attempts to the required amount
|
||||
game.scene.currentBattle.escapeAttempts = check.escapeAttempts;
|
||||
// set playerPokemon's speed to a multiple of the enemySpeed
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
check.pokemonSpeedRatio * enemySpeed,
|
||||
]);
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(20, 20, 20, 20, 20, check.pokemonSpeedRatio * enemySpeed),
|
||||
);
|
||||
const chance = phase.calculateEscapeChance(game.scene.currentBattle.escapeAttempts);
|
||||
expect(chance).toBe(check.expectedEscapeChance);
|
||||
}
|
||||
@ -107,9 +102,9 @@ describe("Escape chance calculations", () => {
|
||||
// this is used to find the ratio of the player's first pokemon
|
||||
const playerASpeedPercentage = 0.4;
|
||||
// set enemyAPokemon's speed to 70
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemyASpeed]);
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemyASpeed));
|
||||
// set enemyBPokemon's speed to 30
|
||||
vi.spyOn(enemyField[1], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemyBSpeed]);
|
||||
vi.spyOn(enemyField[1], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemyBSpeed));
|
||||
|
||||
const commandPhase = game.scene.phaseManager.getCurrentPhase() as CommandPhase;
|
||||
commandPhase.handleCommand(Command.RUN, 0);
|
||||
@ -151,23 +146,20 @@ describe("Escape chance calculations", () => {
|
||||
// sets the number of escape attempts to the required amount
|
||||
game.scene.currentBattle.escapeAttempts = check.escapeAttempts;
|
||||
// set the first playerPokemon's speed to a multiple of the enemySpeed
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
Math.floor(check.pokemonSpeedRatio * totalEnemySpeed * playerASpeedPercentage),
|
||||
]);
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
Math.floor(check.pokemonSpeedRatio * totalEnemySpeed * playerASpeedPercentage),
|
||||
),
|
||||
);
|
||||
// set the second playerPokemon's speed to the remaining value of speed
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
check.pokemonSpeedRatio * totalEnemySpeed - playerPokemon[0].stats[5],
|
||||
]);
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(20, 20, 20, 20, 20, check.pokemonSpeedRatio * totalEnemySpeed - playerPokemon[0].stats[5]),
|
||||
);
|
||||
const chance = phase.calculateEscapeChance(game.scene.currentBattle.escapeAttempts);
|
||||
// checks to make sure the escape values are the same
|
||||
expect(chance).toBe(check.expectedEscapeChance);
|
||||
@ -184,7 +176,7 @@ describe("Escape chance calculations", () => {
|
||||
const enemyField = game.scene.getEnemyField()!;
|
||||
const enemySpeed = 100;
|
||||
// set enemyPokemon's speed to 100
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemySpeed]);
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemySpeed));
|
||||
|
||||
const commandPhase = game.scene.phaseManager.getCurrentPhase() as CommandPhase;
|
||||
commandPhase.handleCommand(Command.RUN, 0);
|
||||
@ -241,14 +233,9 @@ describe("Escape chance calculations", () => {
|
||||
// sets the number of escape attempts to the required amount
|
||||
game.scene.currentBattle.escapeAttempts = check.escapeAttempts;
|
||||
// set playerPokemon's speed to a multiple of the enemySpeed
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
check.pokemonSpeedRatio * enemySpeed,
|
||||
]);
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(20, 20, 20, 20, 20, check.pokemonSpeedRatio * enemySpeed),
|
||||
);
|
||||
const chance = phase.calculateEscapeChance(game.scene.currentBattle.escapeAttempts);
|
||||
expect(chance).toBe(check.expectedEscapeChance);
|
||||
}
|
||||
@ -267,9 +254,9 @@ describe("Escape chance calculations", () => {
|
||||
// this is used to find the ratio of the player's first pokemon
|
||||
const playerASpeedPercentage = 0.8;
|
||||
// set enemyAPokemon's speed to 70
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemyASpeed]);
|
||||
vi.spyOn(enemyField[0], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemyASpeed));
|
||||
// set enemyBPokemon's speed to 30
|
||||
vi.spyOn(enemyField[1], "stats", "get").mockReturnValue([20, 20, 20, 20, 20, enemyBSpeed]);
|
||||
vi.spyOn(enemyField[1], "stats", "get").mockReturnValue(Uint32Array.of(20, 20, 20, 20, 20, enemyBSpeed));
|
||||
|
||||
const commandPhase = game.scene.phaseManager.getCurrentPhase() as CommandPhase;
|
||||
commandPhase.handleCommand(Command.RUN, 0);
|
||||
@ -324,23 +311,20 @@ describe("Escape chance calculations", () => {
|
||||
// sets the number of escape attempts to the required amount
|
||||
game.scene.currentBattle.escapeAttempts = check.escapeAttempts;
|
||||
// set the first playerPokemon's speed to a multiple of the enemySpeed
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
Math.floor(check.pokemonSpeedRatio * totalEnemySpeed * playerASpeedPercentage),
|
||||
]);
|
||||
vi.spyOn(playerPokemon[0], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
Math.floor(check.pokemonSpeedRatio * totalEnemySpeed * playerASpeedPercentage),
|
||||
),
|
||||
);
|
||||
// set the second playerPokemon's speed to the remaining value of speed
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue([
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
20,
|
||||
check.pokemonSpeedRatio * totalEnemySpeed - playerPokemon[0].stats[5],
|
||||
]);
|
||||
vi.spyOn(playerPokemon[1], "stats", "get").mockReturnValue(
|
||||
Uint32Array.of(20, 20, 20, 20, 20, check.pokemonSpeedRatio * totalEnemySpeed - playerPokemon[0].stats[5]),
|
||||
);
|
||||
const chance = phase.calculateEscapeChance(game.scene.currentBattle.escapeAttempts);
|
||||
// checks to make sure the escape values are the same
|
||||
expect(chance).toBe(check.expectedEscapeChance);
|
||||
|
@ -166,8 +166,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
|
||||
|
||||
// Mock stats by replacing entries in copy with desired values for specific stats
|
||||
const stats = {
|
||||
enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]],
|
||||
player: [[...party[0].stats], [...party[1].stats]],
|
||||
enemy: [enemyParty[0].stats.slice(), enemyParty[1].stats.slice()],
|
||||
player: [party[0].stats.slice(), party[1].stats.slice()],
|
||||
};
|
||||
|
||||
// Ensure survival by reducing enemy Sp. Atk and boosting party Sp. Def
|
||||
@ -220,8 +220,8 @@ describe("Moves - Fusion Flare and Fusion Bolt", () => {
|
||||
|
||||
// Mock stats by replacing entries in copy with desired values for specific stats
|
||||
const stats = {
|
||||
enemy: [[...enemyParty[0].stats], [...enemyParty[1].stats]],
|
||||
player: [[...party[0].stats], [...party[1].stats]],
|
||||
enemy: [enemyParty[0].stats.slice(), enemyParty[1].stats.slice()],
|
||||
player: [party[0].stats.slice(), party[1].stats.slice()],
|
||||
};
|
||||
|
||||
// Ensure survival by reducing enemy Sp. Atk and boosting party Sp. Def
|
||||
|
@ -45,10 +45,10 @@ describe("Moves - Rollout", () => {
|
||||
await game.classicMode.startBattle();
|
||||
|
||||
const playerPkm = game.field.getPlayerPokemon();
|
||||
vi.spyOn(playerPkm, "stats", "get").mockReturnValue([500000, 1, 1, 1, 1, 1]); // HP, ATK, DEF, SPATK, SPDEF, SPD
|
||||
vi.spyOn(playerPkm, "stats", "get").mockReturnValue(Uint32Array.of(500000, 1, 1, 1, 1, 1)); // HP, ATK, DEF, SPATK, SPDEF, SPD
|
||||
|
||||
const enemyPkm = game.field.getEnemyPokemon();
|
||||
vi.spyOn(enemyPkm, "stats", "get").mockReturnValue([500000, 1, 1, 1, 1, 1]); // HP, ATK, DEF, SPATK, SPDEF, SPD
|
||||
vi.spyOn(enemyPkm, "stats", "get").mockReturnValue(Uint32Array.of(500000, 1, 1, 1, 1, 1)); // HP, ATK, DEF, SPATK, SPDEF, SPD
|
||||
vi.spyOn(enemyPkm, "getHeldItems").mockReturnValue([]); //no berries
|
||||
|
||||
enemyPkm.hp = enemyPkm.getMaxHp();
|
||||
|
@ -122,7 +122,7 @@ describe("Part-Timer - Mystery Encounter", () => {
|
||||
// Override party levels to 50 so stats can be fully reflective
|
||||
scene.getPlayerParty().forEach(p => {
|
||||
p.level = 50;
|
||||
p.ivs = [20, 20, 20, 20, 20, 20];
|
||||
p.ivs = Uint8Array.of(20, 20, 20, 20, 20, 20);
|
||||
p.calculateStats();
|
||||
});
|
||||
await runMysteryEncounterToEnd(game, 1, { pokemonNo: 2 });
|
||||
@ -188,7 +188,7 @@ describe("Part-Timer - Mystery Encounter", () => {
|
||||
// Override party levels to 50 so stats can be fully reflective
|
||||
scene.getPlayerParty().forEach(p => {
|
||||
p.level = 50;
|
||||
p.ivs = [20, 20, 20, 20, 20, 20];
|
||||
p.ivs = Uint8Array.of(20, 20, 20, 20, 20, 20);
|
||||
p.calculateStats();
|
||||
});
|
||||
await runMysteryEncounterToEnd(game, 2, { pokemonNo: 4 });
|
||||
|
Loading…
Reference in New Issue
Block a user