From 818d7446be6e18de5fb19a2e601c0447e51977b4 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Thu, 22 Aug 2024 06:50:51 +0700 Subject: [PATCH] MISC: Rename getRandomArbitrary (#1605) --- src/Infiltration/ui/BackwardGame.tsx | 4 ++-- src/Infiltration/ui/BracketGame.tsx | 4 ++-- src/Infiltration/ui/CheatCodeGame.tsx | 4 ++-- src/Infiltration/ui/WireCuttingGame.tsx | 4 ++-- .../helpers/{getRandomArbitrary.ts => randomInRange.ts} | 2 +- test/jest/Netscript/Bladeburner.test.ts | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) rename src/utils/helpers/{getRandomArbitrary.ts => randomInRange.ts} (79%) diff --git a/src/Infiltration/ui/BackwardGame.tsx b/src/Infiltration/ui/BackwardGame.tsx index 9a2e32765..6f87156ec 100644 --- a/src/Infiltration/ui/BackwardGame.tsx +++ b/src/Infiltration/ui/BackwardGame.tsx @@ -8,7 +8,7 @@ import { interpolate } from "./Difficulty"; import { GameTimer } from "./GameTimer"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; -import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary"; +import { randomInRange } from "../../utils/helpers/randomInRange"; interface Difficulty { [key: string]: number; @@ -67,7 +67,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement { } function makeAnswer(difficulty: Difficulty): string { - const length = getRandomArbitrary(difficulty.min, difficulty.max); + const length = randomInRange(difficulty.min, difficulty.max); let answer = ""; for (let i = 0; i < length; i++) { if (i > 0) answer += " "; diff --git a/src/Infiltration/ui/BracketGame.tsx b/src/Infiltration/ui/BracketGame.tsx index 3866eddfc..ef68d2ffa 100644 --- a/src/Infiltration/ui/BracketGame.tsx +++ b/src/Infiltration/ui/BracketGame.tsx @@ -8,7 +8,7 @@ import { interpolate } from "./Difficulty"; import { GameTimer } from "./GameTimer"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; -import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary"; +import { randomInRange } from "../../utils/helpers/randomInRange"; interface Difficulty { [key: string]: number; @@ -35,7 +35,7 @@ function generateLeftSide(difficulty: Difficulty): string { if (Player.hasAugmentation(AugmentationName.WisdomOfAthena, true)) { options.splice(0, 1); } - const length = getRandomArbitrary(difficulty.min, difficulty.max); + const length = randomInRange(difficulty.min, difficulty.max); for (let i = 0; i < length; i++) { str += options[Math.floor(Math.random() * options.length)]; } diff --git a/src/Infiltration/ui/CheatCodeGame.tsx b/src/Infiltration/ui/CheatCodeGame.tsx index 27378fa34..5d86f4132 100644 --- a/src/Infiltration/ui/CheatCodeGame.tsx +++ b/src/Infiltration/ui/CheatCodeGame.tsx @@ -7,7 +7,7 @@ import { interpolate } from "./Difficulty"; import { GameTimer } from "./GameTimer"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; -import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary"; +import { randomInRange } from "../../utils/helpers/randomInRange"; interface Difficulty { [key: string]: number; @@ -78,7 +78,7 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement { function generateCode(difficulty: Difficulty): Arrow[] { const arrows: Arrow[] = [leftArrowSymbol, rightArrowSymbol, upArrowSymbol, downArrowSymbol]; const code: Arrow[] = []; - for (let i = 0; i < getRandomArbitrary(difficulty.min, difficulty.max); i++) { + for (let i = 0; i < randomInRange(difficulty.min, difficulty.max); i++) { let arrow = arrows[Math.floor(4 * Math.random())]; while (arrow === code[code.length - 1]) arrow = arrows[Math.floor(4 * Math.random())]; code.push(arrow); diff --git a/src/Infiltration/ui/WireCuttingGame.tsx b/src/Infiltration/ui/WireCuttingGame.tsx index 7a556d502..7ab31c98b 100644 --- a/src/Infiltration/ui/WireCuttingGame.tsx +++ b/src/Infiltration/ui/WireCuttingGame.tsx @@ -9,7 +9,7 @@ import { GameTimer } from "./GameTimer"; import { IMinigameProps } from "./IMinigameProps"; import { KeyHandler } from "./KeyHandler"; import { isPositiveInteger } from "../../types"; -import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary"; +import { randomInRange } from "../../utils/helpers/randomInRange"; interface Difficulty { [key: string]: number; @@ -200,7 +200,7 @@ function generateQuestion(wires: Wire[], difficulty: Difficulty): Question[] { function generateWires(difficulty: Difficulty): Wire[] { const wires = []; - const numWires = getRandomArbitrary(difficulty.wiresmin, difficulty.wiresmax); + const numWires = randomInRange(difficulty.wiresmin, difficulty.wiresmax); for (let i = 0; i < numWires; i++) { const wireColors = [colors[Math.floor(Math.random() * colors.length)]]; if (Math.random() < 0.15) { diff --git a/src/utils/helpers/getRandomArbitrary.ts b/src/utils/helpers/randomInRange.ts similarity index 79% rename from src/utils/helpers/getRandomArbitrary.ts rename to src/utils/helpers/randomInRange.ts index 5f18107cc..a51284586 100644 --- a/src/utils/helpers/getRandomArbitrary.ts +++ b/src/utils/helpers/randomInRange.ts @@ -1,5 +1,5 @@ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_number_between_two_values -export function getRandomArbitrary(min: number, max: number): number { +export function randomInRange(min: number, max: number): number { if (min > max) { throw new Error(`Min is greater than max. Min: ${min}. Max: ${max}.`); } diff --git a/test/jest/Netscript/Bladeburner.test.ts b/test/jest/Netscript/Bladeburner.test.ts index 38dcc8784..d34739754 100644 --- a/test/jest/Netscript/Bladeburner.test.ts +++ b/test/jest/Netscript/Bladeburner.test.ts @@ -2,7 +2,7 @@ import { currentNodeMults } from "../../../src/BitNode/BitNodeMultipliers"; import { Skill } from "../../../src/Bladeburner/Skill"; import { BladeburnerSkillName } from "../../../src/Enums"; import { PositiveInteger, isPositiveInteger, isPositiveNumber } from "../../../src/types"; -import { getRandomArbitrary } from "../../../src/utils/helpers/getRandomArbitrary"; +import { randomInRange } from "../../../src/utils/helpers/randomInRange"; import { getRandomIntInclusive } from "../../../src/utils/helpers/getRandomIntInclusive"; const skill = new Skill({ @@ -22,9 +22,9 @@ describe("Test calculateMaxUpgradeCount", function () { for (let i = 0; i < 10; ++i) { skill.baseCost = getRandomIntInclusive(1, 1000); for (let j = 0; j < 10; ++j) { - skill.costInc = getRandomArbitrary(1, 1000); + skill.costInc = randomInRange(1, 1000); for (let k = 0; k < 10; ++k) { - currentNodeMults.BladeburnerSkillCost = getRandomArbitrary(1, 1000); + currentNodeMults.BladeburnerSkillCost = randomInRange(1, 1000); for (let m = 0; m < 1e4; ++m) { const currentLevel = getRandomIntInclusive(0, 1e9); let count = 0; @@ -56,7 +56,7 @@ describe("Test calculateMaxUpgradeCount", function () { // Test 2 ++testCaseCount; - const budget = getRandomArbitrary(1e9, 1e50); + const budget = randomInRange(1e9, 1e50); if (!isPositiveNumber(budget)) { throw new Error(`Invalid budget: ${budget}`); }