From 5ec0088ffce9fafe9cfe19cde0f2ea083c2b19c0 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Thu, 11 Sep 2025 22:35:46 -0500 Subject: [PATCH] Adjust test mocks to use typed arrays --- .../encounters/fun-and-games-encounter.ts | 2 +- test/abilities/beast-boost.test.ts | 6 +- test/battle/battle-order.test.ts | 26 +++--- test/escape-calculations.test.ts | 92 ++++++++----------- test/moves/fusion-flare-bolt.test.ts | 8 +- test/moves/rollout.test.ts | 4 +- .../encounters/part-timer-encounter.test.ts | 4 +- 7 files changed, 63 insertions(+), 79 deletions(-) diff --git a/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts b/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts index f2363ade500..0327eb2908d 100644 --- a/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts +++ b/src/data/mystery-encounters/encounters/fun-and-games-encounter.ts @@ -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); diff --git a/test/abilities/beast-boost.test.ts b/test/abilities/beast-boost.test.ts index aeb4d854b1a..7ec3ac355ff 100644 --- a/test/abilities/beast-boost.test.ts +++ b/test/abilities/beast-boost.test.ts @@ -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); diff --git a/test/battle/battle-order.test.ts b/test/battle/battle-order.test.ts index de13b22df79..382604bffcd 100644 --- a/test/battle/battle-order.test.ts +++ b/test/battle/battle-order.test.ts @@ -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); diff --git a/test/escape-calculations.test.ts b/test/escape-calculations.test.ts index e1e521f4394..062a86c6fa2 100644 --- a/test/escape-calculations.test.ts +++ b/test/escape-calculations.test.ts @@ -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); diff --git a/test/moves/fusion-flare-bolt.test.ts b/test/moves/fusion-flare-bolt.test.ts index f5d556bde48..cce34441d38 100644 --- a/test/moves/fusion-flare-bolt.test.ts +++ b/test/moves/fusion-flare-bolt.test.ts @@ -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 diff --git a/test/moves/rollout.test.ts b/test/moves/rollout.test.ts index 0e01725a188..9e6d8b87e06 100644 --- a/test/moves/rollout.test.ts +++ b/test/moves/rollout.test.ts @@ -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(); diff --git a/test/mystery-encounter/encounters/part-timer-encounter.test.ts b/test/mystery-encounter/encounters/part-timer-encounter.test.ts index 15d2664364c..78369570fa9 100644 --- a/test/mystery-encounter/encounters/part-timer-encounter.test.ts +++ b/test/mystery-encounter/encounters/part-timer-encounter.test.ts @@ -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 });