Merge pull request #3308 from phyzical/bugfix/fix-tests

Fix tests
This commit is contained in:
hydroflame 2022-04-06 20:16:55 -04:00 committed by GitHub
commit 371de216ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 710 additions and 358 deletions

@ -119,7 +119,6 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
console.warn(`WorkerScript detected NaN for threadcount for ${workerScript.name} on ${workerScript.hostname}`);
threads = 1;
}
workerScript.dynamicRamUsage += ramCost;
if (workerScript.dynamicRamUsage > 1.01 * workerScript.ramUsage) {
throw makeRuntimeRejectMsg(
@ -521,8 +520,8 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
sprintf: sprintf,
vsprintf: vsprintf,
scan: function (_hostname: unknown = workerScript.hostname): string[] {
const hostname = helper.string("scan", "hostname", _hostname);
updateDynamicRam("scan", getRamCost(Player, "scan"));
const hostname = helper.string("scan", "hostname", _hostname);
const server = safeGetServer(hostname, "scan");
const out = [];
for (let i = 0; i < server.serversOnNetwork.length; i++) {

@ -56,53 +56,56 @@ export function NetscriptBladeburner(
return actionObj;
};
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "bladeburner", funcName));
return {
getContractNames: function (): string[] {
helper.updateDynamicRam("getContractNames", getRamCost(player, "bladeburner", "getContractNames"));
updateRam("getContractNames");
checkBladeburnerAccess("getContractNames");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getContractNamesNetscriptFn();
},
getOperationNames: function (): string[] {
helper.updateDynamicRam("getOperationNames", getRamCost(player, "bladeburner", "getOperationNames"));
updateRam("getOperationNames");
checkBladeburnerAccess("getOperationNames");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getOperationNamesNetscriptFn();
},
getBlackOpNames: function (): string[] {
helper.updateDynamicRam("getBlackOpNames", getRamCost(player, "bladeburner", "getBlackOpNames"));
updateRam("getBlackOpNames");
checkBladeburnerAccess("getBlackOpNames");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getBlackOpNamesNetscriptFn();
},
getBlackOpRank: function (_blackOpName: unknown): number {
updateRam("getBlackOpRank");
const blackOpName = helper.string("getBlackOpRank", "blackOpName", _blackOpName);
helper.updateDynamicRam("getBlackOpRank", getRamCost(player, "bladeburner", "getBlackOpRank"));
checkBladeburnerAccess("getBlackOpRank");
const action: any = getBladeburnerActionObject("getBlackOpRank", "blackops", blackOpName);
return action.reqdRank;
},
getGeneralActionNames: function (): string[] {
helper.updateDynamicRam("getGeneralActionNames", getRamCost(player, "bladeburner", "getGeneralActionNames"));
updateRam("getGeneralActionNames");
checkBladeburnerAccess("getGeneralActionNames");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getGeneralActionNamesNetscriptFn();
},
getSkillNames: function (): string[] {
helper.updateDynamicRam("getSkillNames", getRamCost(player, "bladeburner", "getSkillNames"));
updateRam("getSkillNames");
checkBladeburnerAccess("getSkillNames");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getSkillNamesNetscriptFn();
},
startAction: function (_type: unknown, _name: unknown): boolean {
updateRam("startAction");
const type = helper.string("startAction", "type", _type);
const name = helper.string("startAction", "name", _name);
helper.updateDynamicRam("startAction", getRamCost(player, "bladeburner", "startAction"));
checkBladeburnerAccess("startAction");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -113,23 +116,23 @@ export function NetscriptBladeburner(
}
},
stopBladeburnerAction: function (): void {
helper.updateDynamicRam("stopBladeburnerAction", getRamCost(player, "bladeburner", "stopBladeburnerAction"));
updateRam("stopBladeburnerAction");
checkBladeburnerAccess("stopBladeburnerAction");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.resetAction();
},
getCurrentAction: function (): BladeburnerCurAction {
helper.updateDynamicRam("getCurrentAction", getRamCost(player, "bladeburner", "getCurrentAction"));
updateRam("getCurrentAction");
checkBladeburnerAccess("getCurrentAction");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.getTypeAndNameFromActionId(bladeburner.action);
},
getActionTime: function (_type: unknown, _name: unknown): number {
updateRam("getActionTime");
const type = helper.string("getActionTime", "type", _type);
const name = helper.string("getActionTime", "name", _name);
helper.updateDynamicRam("getActionTime", getRamCost(player, "bladeburner", "getActionTime"));
checkBladeburnerAccess("getActionTime");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -140,12 +143,9 @@ export function NetscriptBladeburner(
}
},
getActionEstimatedSuccessChance: function (_type: unknown, _name: unknown): [number, number] {
updateRam("getActionEstimatedSuccessChance");
const type = helper.string("getActionEstimatedSuccessChance", "type", _type);
const name = helper.string("getActionEstimatedSuccessChance", "name", _name);
helper.updateDynamicRam(
"getActionEstimatedSuccessChance",
getRamCost(player, "bladeburner", "getActionEstimatedSuccessChance"),
);
checkBladeburnerAccess("getActionEstimatedSuccessChance");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -156,10 +156,10 @@ export function NetscriptBladeburner(
}
},
getActionRepGain: function (_type: unknown, _name: unknown, _level: unknown): number {
updateRam("getActionRepGain");
const type = helper.string("getActionRepGain", "type", _type);
const name = helper.string("getActionRepGain", "name", _name);
const level = helper.number("getActionRepGain", "level", _level);
helper.updateDynamicRam("getActionRepGain", getRamCost(player, "bladeburner", "getActionRepGain"));
checkBladeburnerAccess("getActionRepGain");
const action = getBladeburnerActionObject("getActionRepGain", type, name);
let rewardMultiplier;
@ -172,9 +172,9 @@ export function NetscriptBladeburner(
return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank;
},
getActionCountRemaining: function (_type: unknown, _name: unknown): number {
updateRam("getActionCountRemaining");
const type = helper.string("getActionCountRemaining", "type", _type);
const name = helper.string("getActionCountRemaining", "name", _name);
helper.updateDynamicRam("getActionCountRemaining", getRamCost(player, "bladeburner", "getActionCountRemaining"));
checkBladeburnerAccess("getActionCountRemaining");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -185,43 +185,43 @@ export function NetscriptBladeburner(
}
},
getActionMaxLevel: function (_type: unknown, _name: unknown): number {
updateRam("getActionMaxLevel");
const type = helper.string("getActionMaxLevel", "type", _type);
const name = helper.string("getActionMaxLevel", "name", _name);
helper.updateDynamicRam("getActionMaxLevel", getRamCost(player, "bladeburner", "getActionMaxLevel"));
checkBladeburnerAccess("getActionMaxLevel");
const action = getBladeburnerActionObject("getActionMaxLevel", type, name);
return action.maxLevel;
},
getActionCurrentLevel: function (_type: unknown, _name: unknown): number {
updateRam("getActionCurrentLevel");
const type = helper.string("getActionCurrentLevel", "type", _type);
const name = helper.string("getActionCurrentLevel", "name", _name);
helper.updateDynamicRam("getActionCurrentLevel", getRamCost(player, "bladeburner", "getActionCurrentLevel"));
checkBladeburnerAccess("getActionCurrentLevel");
const action = getBladeburnerActionObject("getActionCurrentLevel", type, name);
return action.level;
},
getActionAutolevel: function (_type: unknown, _name: unknown): boolean {
updateRam("getActionAutolevel");
const type = helper.string("getActionAutolevel", "type", _type);
const name = helper.string("getActionAutolevel", "name", _name);
helper.updateDynamicRam("getActionAutolevel", getRamCost(player, "bladeburner", "getActionAutolevel"));
checkBladeburnerAccess("getActionAutolevel");
const action = getBladeburnerActionObject("getActionCurrentLevel", type, name);
return action.autoLevel;
},
setActionAutolevel: function (_type: unknown, _name: unknown, _autoLevel: unknown = true): void {
updateRam("setActionAutolevel");
const type = helper.string("setActionAutolevel", "type", _type);
const name = helper.string("setActionAutolevel", "name", _name);
const autoLevel = helper.boolean(_autoLevel);
helper.updateDynamicRam("setActionAutolevel", getRamCost(player, "bladeburner", "setActionAutolevel"));
checkBladeburnerAccess("setActionAutolevel");
const action = getBladeburnerActionObject("setActionAutolevel", type, name);
action.autoLevel = autoLevel;
},
setActionLevel: function (_type: unknown, _name: unknown, _level: unknown = 1): void {
updateRam("setActionLevel");
const type = helper.string("setActionLevel", "type", _type);
const name = helper.string("setActionLevel", "name", _name);
const level = helper.number("setActionLevel", "level", _level);
helper.updateDynamicRam("setActionLevel", getRamCost(player, "bladeburner", "setActionLevel"));
checkBladeburnerAccess("setActionLevel");
const action = getBladeburnerActionObject("setActionLevel", type, name);
if (level < 1 || level > action.maxLevel) {
@ -233,22 +233,22 @@ export function NetscriptBladeburner(
action.level = level;
},
getRank: function (): number {
helper.updateDynamicRam("getRank", getRamCost(player, "bladeburner", "getRank"));
updateRam("getRank");
checkBladeburnerAccess("getRank");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.rank;
},
getSkillPoints: function (): number {
helper.updateDynamicRam("getSkillPoints", getRamCost(player, "bladeburner", "getSkillPoints"));
updateRam("getSkillPoints");
checkBladeburnerAccess("getSkillPoints");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.skillPoints;
},
getSkillLevel: function (_skillName: unknown): number {
updateRam("getSkillLevel");
const skillName = helper.string("getSkillLevel", "skillName", _skillName);
helper.updateDynamicRam("getSkillLevel", getRamCost(player, "bladeburner", "getSkillLevel"));
checkBladeburnerAccess("getSkillLevel");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -259,8 +259,8 @@ export function NetscriptBladeburner(
}
},
getSkillUpgradeCost: function (_skillName: unknown): number {
updateRam("getSkillUpgradeCost");
const skillName = helper.string("getSkillUpgradeCost", "skillName", _skillName);
helper.updateDynamicRam("getSkillUpgradeCost", getRamCost(player, "bladeburner", "getSkillUpgradeCost"));
checkBladeburnerAccess("getSkillUpgradeCost");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -271,8 +271,8 @@ export function NetscriptBladeburner(
}
},
upgradeSkill: function (_skillName: unknown): boolean {
updateRam("upgradeSkill");
const skillName = helper.string("upgradeSkill", "skillName", _skillName);
helper.updateDynamicRam("upgradeSkill", getRamCost(player, "bladeburner", "upgradeSkill"));
checkBladeburnerAccess("upgradeSkill");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -283,9 +283,9 @@ export function NetscriptBladeburner(
}
},
getTeamSize: function (_type: unknown, _name: unknown): number {
updateRam("getTeamSize");
const type = helper.string("getTeamSize", "type", _type);
const name = helper.string("getTeamSize", "name", _name);
helper.updateDynamicRam("getTeamSize", getRamCost(player, "bladeburner", "getTeamSize"));
checkBladeburnerAccess("getTeamSize");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -296,10 +296,10 @@ export function NetscriptBladeburner(
}
},
setTeamSize: function (_type: unknown, _name: unknown, _size: unknown): number {
updateRam("setTeamSize");
const type = helper.string("setTeamSize", "type", _type);
const name = helper.string("setTeamSize", "name", _name);
const size = helper.number("setTeamSize", "size", _size);
helper.updateDynamicRam("setTeamSize", getRamCost(player, "bladeburner", "setTeamSize"));
checkBladeburnerAccess("setTeamSize");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
@ -310,11 +310,8 @@ export function NetscriptBladeburner(
}
},
getCityEstimatedPopulation: function (_cityName: unknown): number {
updateRam("getCityEstimatedPopulation");
const cityName = helper.string("getCityEstimatedPopulation", "cityName", _cityName);
helper.updateDynamicRam(
"getCityEstimatedPopulation",
getRamCost(player, "bladeburner", "getCityEstimatedPopulation"),
);
checkBladeburnerAccess("getCityEstimatedPopulation");
checkBladeburnerCity("getCityEstimatedPopulation", cityName);
const bladeburner = player.bladeburner;
@ -322,8 +319,8 @@ export function NetscriptBladeburner(
return bladeburner.cities[cityName].popEst;
},
getCityCommunities: function (_cityName: unknown): number {
updateRam("getCityCommunities");
const cityName = helper.string("getCityCommunities", "cityName", _cityName);
helper.updateDynamicRam("getCityCommunities", getRamCost(player, "bladeburner", "getCityCommunities"));
checkBladeburnerAccess("getCityCommunities");
checkBladeburnerCity("getCityCommunities", cityName);
const bladeburner = player.bladeburner;
@ -331,8 +328,8 @@ export function NetscriptBladeburner(
return bladeburner.cities[cityName].comms;
},
getCityChaos: function (_cityName: unknown): number {
updateRam("getCityChaos");
const cityName = helper.string("getCityChaos", "cityName", _cityName);
helper.updateDynamicRam("getCityChaos", getRamCost(player, "bladeburner", "getCityChaos"));
checkBladeburnerAccess("getCityChaos");
checkBladeburnerCity("getCityChaos", cityName);
const bladeburner = player.bladeburner;
@ -340,15 +337,15 @@ export function NetscriptBladeburner(
return bladeburner.cities[cityName].chaos;
},
getCity: function (): string {
helper.updateDynamicRam("getCity", getRamCost(player, "bladeburner", "getCity"));
updateRam("getCity");
checkBladeburnerAccess("getCityChaos");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.city;
},
switchCity: function (_cityName: unknown): boolean {
updateRam("switchCity");
const cityName = helper.string("switchCity", "cityName", _cityName);
helper.updateDynamicRam("switchCity", getRamCost(player, "bladeburner", "switchCity"));
checkBladeburnerAccess("switchCity");
checkBladeburnerCity("switchCity", cityName);
const bladeburner = player.bladeburner;
@ -357,21 +354,21 @@ export function NetscriptBladeburner(
return true;
},
getStamina: function (): [number, number] {
helper.updateDynamicRam("getStamina", getRamCost(player, "bladeburner", "getStamina"));
updateRam("getStamina");
checkBladeburnerAccess("getStamina");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return [bladeburner.stamina, bladeburner.maxStamina];
},
joinBladeburnerFaction: function (): boolean {
helper.updateDynamicRam("joinBladeburnerFaction", getRamCost(player, "bladeburner", "joinBladeburnerFaction"));
updateRam("joinBladeburnerFaction");
checkBladeburnerAccess("joinBladeburnerFaction", true);
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
return bladeburner.joinBladeburnerFactionNetscriptFn(workerScript);
},
joinBladeburnerDivision: function (): boolean {
helper.updateDynamicRam("joinBladeburnerDivision", getRamCost(player, "bladeburner", "joinBladeburnerDivision"));
updateRam("joinBladeburnerDivision");
if (player.bitNodeN === 7 || player.sourceFileLvl(7) > 0) {
if (player.bitNodeN === 8) {
return false;
@ -399,7 +396,7 @@ export function NetscriptBladeburner(
return false;
},
getBonusTime: function (): number {
helper.updateDynamicRam("getBonusTime", getRamCost(player, "bladeburner", "getBonusTime"));
updateRam("getBonusTime");
checkBladeburnerAccess("getBonusTime");
const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");

@ -24,6 +24,9 @@ export function NetscriptCodingContract(
return contract;
};
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "codingcontract", funcName));
return {
attempt: function (
answer: any,
@ -31,7 +34,7 @@ export function NetscriptCodingContract(
_hostname: unknown = workerScript.hostname,
{ returnReward }: CodingAttemptOptions = { returnReward: false },
): boolean | string {
helper.updateDynamicRam("attempt", getRamCost(player, "codingcontract", "attempt"));
updateRam("attempt");
const filename = helper.string("attempt", "filename", _filename);
const hostname = helper.string("attempt", "hostname", _hostname);
const contract = getCodingContract("attempt", hostname, filename);
@ -83,14 +86,14 @@ export function NetscriptCodingContract(
}
},
getContractType: function (_filename: unknown, _hostname: unknown = workerScript.hostname): string {
helper.updateDynamicRam("getContractType", getRamCost(player, "codingcontract", "getContractType"));
updateRam("getContractType");
const filename = helper.string("getContractType", "filename", _filename);
const hostname = helper.string("getContractType", "hostname", _hostname);
const contract = getCodingContract("getContractType", hostname, filename);
return contract.getType();
},
getData: function (_filename: unknown, _hostname: unknown = workerScript.hostname): any {
helper.updateDynamicRam("getData", getRamCost(player, "codingcontract", "getData"));
updateRam("getData");
const filename = helper.string("getContractType", "filename", _filename);
const hostname = helper.string("getContractType", "hostname", _hostname);
const contract = getCodingContract("getData", hostname, filename);
@ -112,14 +115,14 @@ export function NetscriptCodingContract(
}
},
getDescription: function (_filename: unknown, _hostname: unknown = workerScript.hostname): string {
helper.updateDynamicRam("getDescription", getRamCost(player, "codingcontract", "getDescription"));
updateRam("getDescription");
const filename = helper.string("getDescription", "filename", _filename);
const hostname = helper.string("getDescription", "hostname", _hostname);
const contract = getCodingContract("getDescription", hostname, filename);
return contract.getDescription();
},
getNumTriesRemaining: function (_filename: unknown, _hostname: unknown = workerScript.hostname): number {
helper.updateDynamicRam("getNumTriesRemaining", getRamCost(player, "codingcontract", "getNumTriesRemaining"));
updateRam("getNumTriesRemaining");
const filename = helper.string("getNumTriesRemaining", "filename", _filename);
const hostname = helper.string("getNumTriesRemaining", "hostname", _hostname);
const contract = getCodingContract("getNumTriesRemaining", hostname, filename);

@ -47,10 +47,12 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return task;
};
const updateRam = (funcName: string): void => helper.updateDynamicRam(funcName, getRamCost(player, "gang", funcName));
return {
createGang: function (_faction: unknown): boolean {
updateRam("createGang");
const faction = helper.string("createGang", "faction", _faction);
helper.updateDynamicRam("createGang", getRamCost(player, "gang", "createGang"));
// this list is copied from Faction/ui/Root.tsx
if (!player.canAccessGang() || !GangConstants.Names.includes(faction)) return false;
@ -62,18 +64,18 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return true;
},
inGang: function (): boolean {
helper.updateDynamicRam("inGang", getRamCost(player, "gang", "inGang"));
updateRam("inGang");
return player.inGang();
},
getMemberNames: function (): string[] {
helper.updateDynamicRam("getMemberNames", getRamCost(player, "gang", "getMemberNames"));
updateRam("getMemberNames");
checkGangApiAccess("getMemberNames");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
return gang.members.map((member) => member.name);
},
getGangInformation: function (): GangGenInfo {
helper.updateDynamicRam("getGangInformation", getRamCost(player, "gang", "getGangInformation"));
updateRam("getGangInformation");
checkGangApiAccess("getGangInformation");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -93,7 +95,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
};
},
getOtherGangInformation: function (): GangOtherInfo {
helper.updateDynamicRam("getOtherGangInformation", getRamCost(player, "gang", "getOtherGangInformation"));
updateRam("getOtherGangInformation");
checkGangApiAccess("getOtherGangInformation");
const cpy: any = {};
for (const gang of Object.keys(AllGangs)) {
@ -103,8 +105,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return cpy;
},
getMemberInformation: function (_memberName: unknown): GangMemberInfo {
updateRam("getMemberInformation");
const memberName = helper.string("getMemberInformation", "memberName", _memberName);
helper.updateDynamicRam("getMemberInformation", getRamCost(player, "gang", "getMemberInformation"));
checkGangApiAccess("getMemberInformation");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -157,15 +159,15 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
};
},
canRecruitMember: function (): boolean {
helper.updateDynamicRam("canRecruitMember", getRamCost(player, "gang", "canRecruitMember"));
updateRam("canRecruitMember");
checkGangApiAccess("canRecruitMember");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
return gang.canRecruitMember();
},
recruitMember: function (_memberName: unknown): boolean {
updateRam("recruitMember");
const memberName = helper.string("recruitMember", "memberName", _memberName);
helper.updateDynamicRam("recruitMember", getRamCost(player, "gang", "recruitMember"));
checkGangApiAccess("recruitMember");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -179,7 +181,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return recruited;
},
getTaskNames: function (): string[] {
helper.updateDynamicRam("getTaskNames", getRamCost(player, "gang", "getTaskNames"));
updateRam("getTaskNames");
checkGangApiAccess("getTaskNames");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -188,9 +190,9 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return tasks;
},
setMemberTask: function (_memberName: unknown, _taskName: unknown): boolean {
updateRam("setMemberTask");
const memberName = helper.string("setMemberTask", "memberName", _memberName);
const taskName = helper.string("setMemberTask", "taskName", _taskName);
helper.updateDynamicRam("setMemberTask", getRamCost(player, "gang", "setMemberTask"));
checkGangApiAccess("setMemberTask");
const member = getGangMember("setMemberTask", memberName);
const gang = player.gang;
@ -219,8 +221,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return success;
},
getTaskStats: function (_taskName: unknown): GangTaskStats {
updateRam("getTaskStats");
const taskName = helper.string("getTaskStats", "taskName", _taskName);
helper.updateDynamicRam("getTaskStats", getRamCost(player, "gang", "getTaskStats"));
checkGangApiAccess("getTaskStats");
const task = getGangTask("getTaskStats", taskName);
const copy = Object.assign({}, task);
@ -228,13 +230,13 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return copy;
},
getEquipmentNames: function (): string[] {
helper.updateDynamicRam("getEquipmentNames", getRamCost(player, "gang", "getEquipmentNames"));
updateRam("getEquipmentNames");
checkGangApiAccess("getEquipmentNames");
return Object.keys(GangMemberUpgrades);
},
getEquipmentCost: function (_equipName: any): number {
updateRam("getEquipmentCost");
const equipName = helper.string("getEquipmentCost", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentCost", getRamCost(player, "gang", "getEquipmentCost"));
checkGangApiAccess("getEquipmentCost");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -243,16 +245,16 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return gang.getUpgradeCost(upg);
},
getEquipmentType: function (_equipName: unknown): string {
updateRam("getEquipmentType");
const equipName = helper.string("getEquipmentType", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentType", getRamCost(player, "gang", "getEquipmentType"));
checkGangApiAccess("getEquipmentType");
const upg = GangMemberUpgrades[equipName];
if (upg == null) return "";
return upg.getType();
},
getEquipmentStats: function (_equipName: unknown): EquipmentStats {
updateRam("getEquipmentStats");
const equipName = helper.string("getEquipmentStats", "equipName", _equipName);
helper.updateDynamicRam("getEquipmentStats", getRamCost(player, "gang", "getEquipmentStats"));
checkGangApiAccess("getEquipmentStats");
const equipment = GangMemberUpgrades[equipName];
if (!equipment) {
@ -262,9 +264,9 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return Object.assign({}, typecheck) as any;
},
purchaseEquipment: function (_memberName: unknown, _equipName: unknown): boolean {
updateRam("purchaseEquipment");
const memberName = helper.string("purchaseEquipment", "memberName", _memberName);
const equipName = helper.string("purchaseEquipment", "equipName", _equipName);
helper.updateDynamicRam("purchaseEquipment", getRamCost(player, "gang", "purchaseEquipment"));
checkGangApiAccess("purchaseEquipment");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -284,8 +286,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return res;
},
ascendMember: function (_memberName: unknown): GangMemberAscension | undefined {
updateRam("ascendMember");
const memberName = helper.string("ascendMember", "memberName", _memberName);
helper.updateDynamicRam("ascendMember", getRamCost(player, "gang", "ascendMember"));
checkGangApiAccess("ascendMember");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -294,8 +296,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return gang.ascendMember(member, workerScript);
},
getAscensionResult: function (_memberName: unknown): GangMemberAscension | undefined {
updateRam("getAscensionResult");
const memberName = helper.string("getAscensionResult", "memberName", _memberName);
helper.updateDynamicRam("getAscensionResult", getRamCost(player, "gang", "getAscensionResult"));
checkGangApiAccess("getAscensionResult");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -307,8 +309,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
};
},
setTerritoryWarfare: function (_engage: unknown): void {
updateRam("setTerritoryWarfare");
const engage = helper.boolean(_engage);
helper.updateDynamicRam("setTerritoryWarfare", getRamCost(player, "gang", "setTerritoryWarfare"));
checkGangApiAccess("setTerritoryWarfare");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -321,8 +323,8 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
}
},
getChanceToWinClash: function (_otherGang: unknown): number {
updateRam("getChanceToWinClash");
const otherGang = helper.string("getChanceToWinClash", "otherGang", _otherGang);
helper.updateDynamicRam("getChanceToWinClash", getRamCost(player, "gang", "getChanceToWinClash"));
checkGangApiAccess("getChanceToWinClash");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");
@ -336,7 +338,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
return playerPower / (otherPower + playerPower);
},
getBonusTime: function (): number {
helper.updateDynamicRam("getBonusTime", getRamCost(player, "gang", "getBonusTime"));
updateRam("getBonusTime");
checkGangApiAccess("getBonusTime");
const gang = player.gang;
if (gang === null) throw new Error("Should not be called without Gang");

@ -20,10 +20,13 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
}
};
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "grafting", funcName));
return {
getAugmentationGraftPrice: (_augName: unknown): number => {
updateRam("getAugmentationGraftPrice");
const augName = helper.string("getAugmentationGraftPrice", "augName", _augName);
helper.updateDynamicRam("getAugmentationGraftPrice", getRamCost(player, "grafting", "getAugmentationGraftPrice"));
checkGraftingAPIAccess("getAugmentationGraftPrice");
if (!Augmentations.hasOwnProperty(augName)) {
throw helper.makeRuntimeErrorMsg("grafting.getAugmentationGraftPrice", `Invalid aug: ${augName}`);
@ -33,8 +36,8 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
},
getAugmentationGraftTime: (_augName: string): number => {
updateRam("getAugmentationGraftTime");
const augName = helper.string("getAugmentationGraftTime", "augName", _augName);
helper.updateDynamicRam("getAugmentationGraftTime", getRamCost(player, "grafting", "getAugmentationGraftTime"));
checkGraftingAPIAccess("getAugmentationGraftTime");
if (!Augmentations.hasOwnProperty(augName)) {
throw helper.makeRuntimeErrorMsg("grafting.getAugmentationGraftTime", `Invalid aug: ${augName}`);
@ -44,9 +47,9 @@ export function NetscriptGrafting(player: IPlayer, workerScript: WorkerScript, h
},
graftAugmentation: (_augName: string, _focus: unknown = true): boolean => {
updateRam("graftAugmentation");
const augName = helper.string("graftAugmentation", "augName", _augName);
const focus = helper.boolean(_focus);
helper.updateDynamicRam("graftAugmentation", getRamCost(player, "grafting", "graftAugmentation"));
checkGraftingAPIAccess("graftAugmentation");
if (player.city !== CityName.NewTokyo) {
throw helper.makeRuntimeErrorMsg(

@ -96,10 +96,12 @@ export function NetscriptSingularity(
}
}
};
const updateRam = (funcName: string): void => helper.updateDynamicRam(funcName, getRamCost(player, funcName));
return {
getOwnedAugmentations: function (_purchased: unknown = false): string[] {
updateRam("getOwnedAugmentations");
const purchased = helper.boolean(_purchased);
helper.updateDynamicRam("getOwnedAugmentations", getRamCost(player, "getOwnedAugmentations"));
helper.checkSingularityAccess("getOwnedAugmentations");
const res = [];
for (let i = 0; i < player.augmentations.length; ++i) {
@ -113,52 +115,52 @@ export function NetscriptSingularity(
return res;
},
getAugmentationsFromFaction: function (_facName: unknown): string[] {
updateRam("getAugmentationsFromFaction");
const facName = helper.string("getAugmentationsFromFaction", "facName", _facName);
helper.updateDynamicRam("getAugmentationsFromFaction", getRamCost(player, "getAugmentationsFromFaction"));
helper.checkSingularityAccess("getAugmentationsFromFaction");
const faction = getFaction("getAugmentationsFromFaction", facName);
return getFactionAugmentationsFiltered(player, faction);
},
getAugmentationCost: function (_augName: unknown): [number, number] {
updateRam("getAugmentationCost");
const augName = helper.string("getAugmentationCost", "augName", _augName);
helper.updateDynamicRam("getAugmentationCost", getRamCost(player, "getAugmentationCost"));
helper.checkSingularityAccess("getAugmentationCost");
const aug = getAugmentation("getAugmentationCost", augName);
return [aug.baseRepRequirement, aug.baseCost];
},
getAugmentationPrereq: function (_augName: unknown): string[] {
updateRam("getAugmentationPrereq");
const augName = helper.string("getAugmentationPrereq", "augName", _augName);
helper.updateDynamicRam("getAugmentationPrereq", getRamCost(player, "getAugmentationPrereq"));
helper.checkSingularityAccess("getAugmentationPrereq");
const aug = getAugmentation("getAugmentationPrereq", augName);
return aug.prereqs.slice();
},
getAugmentationPrice: function (_augName: unknown): number {
updateRam("getAugmentationPrice");
const augName = helper.string("getAugmentationPrice", "augName", _augName);
helper.updateDynamicRam("getAugmentationPrice", getRamCost(player, "getAugmentationPrice"));
helper.checkSingularityAccess("getAugmentationPrice");
const aug = getAugmentation("getAugmentationPrice", augName);
return aug.baseCost;
},
getAugmentationRepReq: function (_augName: unknown): number {
updateRam("getAugmentationRepReq");
const augName = helper.string("getAugmentationRepReq", "augName", _augName);
helper.updateDynamicRam("getAugmentationRepReq", getRamCost(player, "getAugmentationRepReq"));
helper.checkSingularityAccess("getAugmentationRepReq");
const aug = getAugmentation("getAugmentationRepReq", augName);
return aug.baseRepRequirement;
},
getAugmentationStats: function (_augName: unknown): AugmentationStats {
updateRam("getAugmentationStats");
const augName = helper.string("getAugmentationStats", "augName", _augName);
helper.updateDynamicRam("getAugmentationStats", getRamCost(player, "getAugmentationStats"));
helper.checkSingularityAccess("getAugmentationStats");
const aug = getAugmentation("getAugmentationStats", augName);
return Object.assign({}, aug.mults);
},
purchaseAugmentation: function (_facName: unknown, _augName: unknown): boolean {
updateRam("purchaseAugmentation");
const facName = helper.string("purchaseAugmentation", "facName", _facName);
const augName = helper.string("purchaseAugmentation", "augName", _augName);
helper.updateDynamicRam("purchaseAugmentation", getRamCost(player, "purchaseAugmentation"));
helper.checkSingularityAccess("purchaseAugmentation");
const fac = getFaction("purchaseAugmentation", facName);
const aug = getAugmentation("purchaseAugmentation", augName);
@ -204,8 +206,8 @@ export function NetscriptSingularity(
}
},
softReset: function (_cbScript: unknown): void {
updateRam("softReset");
const cbScript = helper.string("softReset", "cbScript", _cbScript);
helper.updateDynamicRam("softReset", getRamCost(player, "softReset"));
helper.checkSingularityAccess("softReset");
workerScript.log("softReset", () => "Soft resetting. This will cause this script to be killed");
@ -219,8 +221,8 @@ export function NetscriptSingularity(
killWorkerScript(workerScript);
},
installAugmentations: function (_cbScript: unknown): boolean {
updateRam("installAugmentations");
const cbScript = helper.string("installAugmentations", "cbScript", _cbScript);
helper.updateDynamicRam("installAugmentations", getRamCost(player, "installAugmentations"));
helper.checkSingularityAccess("installAugmentations");
if (player.queuedAugmentations.length === 0) {
@ -243,8 +245,8 @@ export function NetscriptSingularity(
},
goToLocation: function (_locationName: unknown): boolean {
updateRam("goToLocation");
const locationName = helper.string("goToLocation", "locationName", _locationName);
helper.updateDynamicRam("goToLocation", getRamCost(player, "goToLocation"));
helper.checkSingularityAccess("goToLocation");
const location = Object.values(Locations).find((l) => l.name === locationName);
if (!location) {
@ -260,10 +262,10 @@ export function NetscriptSingularity(
return true;
},
universityCourse: function (_universityName: unknown, _className: unknown, _focus: unknown = true): boolean {
updateRam("universityCourse");
const universityName = helper.string("universityCourse", "universityName", _universityName);
const className = helper.string("universityCourse", "className", _className);
const focus = helper.boolean(_focus);
helper.updateDynamicRam("universityCourse", getRamCost(player, "universityCourse"));
helper.checkSingularityAccess("universityCourse");
const wasFocusing = player.focus;
if (player.isWorking) {
@ -351,10 +353,10 @@ export function NetscriptSingularity(
},
gymWorkout: function (_gymName: unknown, _stat: unknown, _focus: unknown = true): boolean {
updateRam("gymWorkout");
const gymName = helper.string("gymWorkout", "gymName", _gymName);
const stat = helper.string("gymWorkout", "stat", _stat);
const focus = helper.boolean(_focus);
helper.updateDynamicRam("gymWorkout", getRamCost(player, "gymWorkout"));
helper.checkSingularityAccess("gymWorkout");
const wasFocusing = player.focus;
if (player.isWorking) {
@ -466,8 +468,8 @@ export function NetscriptSingularity(
},
travelToCity: function (_cityName: unknown): boolean {
updateRam("travelToCity");
const cityName = helper.city("travelToCity", "cityName", _cityName);
helper.updateDynamicRam("travelToCity", getRamCost(player, "travelToCity"));
helper.checkSingularityAccess("travelToCity");
switch (cityName) {
@ -492,7 +494,7 @@ export function NetscriptSingularity(
},
purchaseTor: function (): boolean {
helper.updateDynamicRam("purchaseTor", getRamCost(player, "purchaseTor"));
updateRam("purchaseTor");
helper.checkSingularityAccess("purchaseTor");
if (player.hasTorRouter()) {
@ -524,8 +526,8 @@ export function NetscriptSingularity(
return true;
},
purchaseProgram: function (_programName: unknown): boolean {
updateRam("purchaseProgram");
const programName = helper.string("purchaseProgram", "programName", _programName).toLowerCase();
helper.updateDynamicRam("purchaseProgram", getRamCost(player, "purchaseProgram"));
helper.checkSingularityAccess("purchaseProgram");
if (!player.hasTorRouter()) {
@ -562,13 +564,13 @@ export function NetscriptSingularity(
return true;
},
getCurrentServer: function (): string {
helper.updateDynamicRam("getCurrentServer", getRamCost(player, "getCurrentServer"));
updateRam("getCurrentServer");
helper.checkSingularityAccess("getCurrentServer");
return player.getCurrentServer().hostname;
},
connect: function (_hostname: unknown): boolean {
updateRam("connect");
const hostname = helper.string("purchaseProgram", "hostname", _hostname);
helper.updateDynamicRam("connect", getRamCost(player, "connect"));
helper.checkSingularityAccess("connect");
if (!hostname) {
throw helper.makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
@ -603,13 +605,13 @@ export function NetscriptSingularity(
return false;
},
manualHack: function (): Promise<number> {
helper.updateDynamicRam("manualHack", getRamCost(player, "manualHack"));
updateRam("manualHack");
helper.checkSingularityAccess("manualHack");
const server = player.getCurrentServer();
return helper.hack(server.hostname, true);
},
installBackdoor: function (): Promise<void> {
helper.updateDynamicRam("installBackdoor", getRamCost(player, "installBackdoor"));
updateRam("installBackdoor");
helper.checkSingularityAccess("installBackdoor");
const baseserver = player.getCurrentServer();
if (!(baseserver instanceof Server)) {
@ -642,13 +644,13 @@ export function NetscriptSingularity(
});
},
isFocused: function (): boolean {
helper.updateDynamicRam("isFocused", getRamCost(player, "isFocused"));
updateRam("isFocused");
helper.checkSingularityAccess("isFocused");
return player.focus;
},
setFocus: function (_focus: unknown): boolean {
updateRam("setFocus");
const focus = helper.boolean(_focus);
helper.updateDynamicRam("setFocus", getRamCost(player, "setFocus"));
helper.checkSingularityAccess("setFocus");
if (!player.isWorking) {
throw helper.makeRuntimeErrorMsg("setFocus", "Not currently working");
@ -676,7 +678,7 @@ export function NetscriptSingularity(
return false;
},
getStats: function (): PlayerSkills {
helper.updateDynamicRam("getStats", getRamCost(player, "getStats"));
updateRam("getStats");
helper.checkSingularityAccess("getStats");
workerScript.log("getStats", () => `getStats is deprecated, please use getplayer`);
@ -691,7 +693,7 @@ export function NetscriptSingularity(
};
},
getCharacterInformation: function (): CharacterInfo {
helper.updateDynamicRam("getCharacterInformation", getRamCost(player, "getCharacterInformation"));
updateRam("getCharacterInformation");
helper.checkSingularityAccess("getCharacterInformation");
workerScript.log("getCharacterInformation", () => `getCharacterInformation is deprecated, please use getplayer`);
@ -741,7 +743,7 @@ export function NetscriptSingularity(
};
},
hospitalize: function (): void {
helper.updateDynamicRam("hospitalize", getRamCost(player, "hospitalize"));
updateRam("hospitalize");
helper.checkSingularityAccess("hospitalize");
if (player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) {
workerScript.log("hospitalize", () => "Cannot go to the hospital because the player is busy.");
@ -750,12 +752,12 @@ export function NetscriptSingularity(
player.hospitalize();
},
isBusy: function (): boolean {
helper.updateDynamicRam("isBusy", getRamCost(player, "isBusy"));
updateRam("isBusy");
helper.checkSingularityAccess("isBusy");
return player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse;
},
stopAction: function (): boolean {
helper.updateDynamicRam("stopAction", getRamCost(player, "stopAction"));
updateRam("stopAction");
helper.checkSingularityAccess("stopAction");
if (player.isWorking) {
if (player.focus) {
@ -769,7 +771,7 @@ export function NetscriptSingularity(
return false;
},
upgradeHomeCores: function (): boolean {
helper.updateDynamicRam("upgradeHomeCores", getRamCost(player, "upgradeHomeCores"));
updateRam("upgradeHomeCores");
helper.checkSingularityAccess("upgradeHomeCores");
// Check if we're at max cores
@ -799,13 +801,13 @@ export function NetscriptSingularity(
return true;
},
getUpgradeHomeCoresCost: function (): number {
helper.updateDynamicRam("getUpgradeHomeCoresCost", getRamCost(player, "getUpgradeHomeCoresCost"));
updateRam("getUpgradeHomeCoresCost");
helper.checkSingularityAccess("getUpgradeHomeCoresCost");
return player.getUpgradeHomeCoresCost();
},
upgradeHomeRam: function (): boolean {
helper.updateDynamicRam("upgradeHomeRam", getRamCost(player, "upgradeHomeRam"));
updateRam("upgradeHomeRam");
helper.checkSingularityAccess("upgradeHomeRam");
// Check if we're at max RAM
@ -838,15 +840,15 @@ export function NetscriptSingularity(
return true;
},
getUpgradeHomeRamCost: function (): number {
helper.updateDynamicRam("getUpgradeHomeRamCost", getRamCost(player, "getUpgradeHomeRamCost"));
updateRam("getUpgradeHomeRamCost");
helper.checkSingularityAccess("getUpgradeHomeRamCost");
return player.getUpgradeHomeRamCost();
},
workForCompany: function (_companyName: unknown, _focus: unknown = true): boolean {
updateRam("workForCompany");
let companyName = helper.string("workForCompany", "companyName", _companyName);
const focus = helper.boolean(_focus);
helper.updateDynamicRam("workForCompany", getRamCost(player, "workForCompany"));
helper.checkSingularityAccess("workForCompany");
// Sanitize input
@ -900,9 +902,9 @@ export function NetscriptSingularity(
return true;
},
applyToCompany: function (_companyName: unknown, _field: unknown): boolean {
updateRam("applyToCompany");
const companyName = helper.string("applyToCompany", "companyName", _companyName);
const field = helper.string("applyToCompany", "field", _field);
helper.updateDynamicRam("applyToCompany", getRamCost(player, "applyToCompany"));
helper.checkSingularityAccess("applyToCompany");
getCompany("applyToCompany", companyName);
@ -972,22 +974,22 @@ export function NetscriptSingularity(
return res;
},
getCompanyRep: function (_companyName: unknown): number {
updateRam("getCompanyRep");
const companyName = helper.string("getCompanyRep", "companyName", _companyName);
helper.updateDynamicRam("getCompanyRep", getRamCost(player, "getCompanyRep"));
helper.checkSingularityAccess("getCompanyRep");
const company = getCompany("getCompanyRep", companyName);
return company.playerReputation;
},
getCompanyFavor: function (_companyName: unknown): number {
updateRam("getCompanyFavor");
const companyName = helper.string("getCompanyFavor", "companyName", _companyName);
helper.updateDynamicRam("getCompanyFavor", getRamCost(player, "getCompanyFavor"));
helper.checkSingularityAccess("getCompanyFavor");
const company = getCompany("getCompanyFavor", companyName);
return company.favor;
},
getCompanyFavorGain: function (_companyName: unknown): number {
updateRam("getCompanyFavorGain");
const companyName = helper.string("getCompanyFavorGain", "companyName", _companyName);
helper.updateDynamicRam("getCompanyFavorGain", getRamCost(player, "getCompanyFavorGain"));
helper.checkSingularityAccess("getCompanyFavorGain");
const company = getCompany("getCompanyFavorGain", companyName);
return company.getFavorGain();
@ -999,8 +1001,8 @@ export function NetscriptSingularity(
return player.factionInvitations.slice();
},
joinFaction: function (_facName: unknown): boolean {
updateRam("joinFaction");
const facName = helper.string("joinFaction", "facName", _facName);
helper.updateDynamicRam("joinFaction", getRamCost(player, "joinFaction"));
helper.checkSingularityAccess("joinFaction");
getFaction("joinFaction", facName);
@ -1023,10 +1025,10 @@ export function NetscriptSingularity(
return true;
},
workForFaction: function (_facName: unknown, _type: unknown, _focus: unknown = true): boolean {
updateRam("workForFaction");
const facName = helper.string("workForFaction", "facName", _facName);
const type = helper.string("workForFaction", "type", _type);
const focus = helper.boolean(_focus);
helper.updateDynamicRam("workForFaction", getRamCost(player, "workForFaction"));
helper.checkSingularityAccess("workForFaction");
getFaction("workForFaction", facName);
@ -1109,30 +1111,30 @@ export function NetscriptSingularity(
return true;
},
getFactionRep: function (_facName: unknown): number {
updateRam("getFactionRep");
const facName = helper.string("getFactionRep", "facName", _facName);
helper.updateDynamicRam("getFactionRep", getRamCost(player, "getFactionRep"));
helper.checkSingularityAccess("getFactionRep");
const faction = getFaction("getFactionRep", facName);
return faction.playerReputation;
},
getFactionFavor: function (_facName: unknown): number {
updateRam("getFactionFavor");
const facName = helper.string("getFactionRep", "facName", _facName);
helper.updateDynamicRam("getFactionFavor", getRamCost(player, "getFactionFavor"));
helper.checkSingularityAccess("getFactionFavor");
const faction = getFaction("getFactionFavor", facName);
return faction.favor;
},
getFactionFavorGain: function (_facName: unknown): number {
updateRam("getFactionFavorGain");
const facName = helper.string("getFactionFavorGain", "facName", _facName);
helper.updateDynamicRam("getFactionFavorGain", getRamCost(player, "getFactionFavorGain"));
helper.checkSingularityAccess("getFactionFavorGain");
const faction = getFaction("getFactionFavorGain", facName);
return faction.getFavorGain();
},
donateToFaction: function (_facName: unknown, _amt: unknown): boolean {
updateRam("donateToFaction");
const facName = helper.string("donateToFaction", "facName", _facName);
const amt = helper.number("donateToFaction", "amt", _amt);
helper.updateDynamicRam("donateToFaction", getRamCost(player, "donateToFaction"));
helper.checkSingularityAccess("donateToFaction");
const faction = getFaction("donateToFaction", facName);
if (!player.factions.includes(faction.name)) {
@ -1179,9 +1181,9 @@ export function NetscriptSingularity(
return true;
},
createProgram: function (_programName: unknown, _focus: unknown = true): boolean {
updateRam("createProgram");
const programName = helper.string("createProgram", "programName", _programName).toLowerCase();
const focus = helper.boolean(_focus);
helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram"));
helper.checkSingularityAccess("createProgram");
const wasFocusing = player.focus;
@ -1228,8 +1230,8 @@ export function NetscriptSingularity(
return true;
},
commitCrime: function (_crimeRoughName: unknown): number {
updateRam("commitCrime");
const crimeRoughName = helper.string("commitCrime", "crimeRoughName", _crimeRoughName);
helper.updateDynamicRam("commitCrime", getRamCost(player, "commitCrime"));
helper.checkSingularityAccess("commitCrime");
if (player.isWorking) {
@ -1249,8 +1251,8 @@ export function NetscriptSingularity(
return crime.commit(Router, player, 1, workerScript);
},
getCrimeChance: function (_crimeRoughName: unknown): number {
updateRam("getCrimeChance");
const crimeRoughName = helper.string("getCrimeChance", "crimeRoughName", _crimeRoughName);
helper.updateDynamicRam("getCrimeChance", getRamCost(player, "getCrimeChance"));
helper.checkSingularityAccess("getCrimeChance");
const crime = findCrime(crimeRoughName.toLowerCase());
@ -1261,8 +1263,8 @@ export function NetscriptSingularity(
return crime.successRate(player);
},
getCrimeStats: function (_crimeRoughName: unknown): CrimeStats {
updateRam("getCrimeStats");
const crimeRoughName = helper.string("getCrimeStats", "crimeRoughName", _crimeRoughName);
helper.updateDynamicRam("getCrimeStats", getRamCost(player, "getCrimeStats"));
helper.checkSingularityAccess("getCrimeStats");
const crime = findCrime(crimeRoughName.toLowerCase());
@ -1273,7 +1275,7 @@ export function NetscriptSingularity(
return Object.assign({}, crime);
},
getDarkwebPrograms: function (): string[] {
helper.updateDynamicRam("getDarkwebPrograms", getRamCost(player, "getDarkwebPrograms"));
updateRam("getDarkwebPrograms");
helper.checkSingularityAccess("getDarkwebPrograms");
// If we don't have Tor, log it and return [] (empty list)
@ -1284,8 +1286,8 @@ export function NetscriptSingularity(
return Object.values(DarkWebItems).map((p) => p.program);
},
getDarkwebProgramCost: function (_programName: unknown): number {
updateRam("getDarkwebProgramCost");
const programName = helper.string("getDarkwebProgramCost", "programName", _programName).toLowerCase();
helper.updateDynamicRam("getDarkwebProgramCost", getRamCost(player, "getDarkwebProgramCost"));
helper.checkSingularityAccess("getDarkwebProgramCost");
// If we don't have Tor, log it and return -1

@ -50,28 +50,31 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
};
};
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "sleeve", funcName));
return {
getNumSleeves: function (): number {
helper.updateDynamicRam("getNumSleeves", getRamCost(player, "sleeve", "getNumSleeves"));
updateRam("getNumSleeves");
checkSleeveAPIAccess("getNumSleeves");
return player.sleeves.length;
},
setToShockRecovery: function (_sleeveNumber: unknown): boolean {
helper.updateDynamicRam("setToShockRecovery", getRamCost(player, "sleeve", "setToShockRecovery"));
updateRam("setToShockRecovery");
const sleeveNumber = helper.number("setToShockRecovery", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("setToShockRecovery");
checkSleeveNumber("setToShockRecovery", sleeveNumber);
return player.sleeves[sleeveNumber].shockRecovery(player);
},
setToSynchronize: function (_sleeveNumber: unknown): boolean {
helper.updateDynamicRam("setToSynchronize", getRamCost(player, "sleeve", "setToSynchronize"));
updateRam("setToSynchronize");
const sleeveNumber = helper.number("setToSynchronize", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("setToSynchronize");
checkSleeveNumber("setToSynchronize", sleeveNumber);
return player.sleeves[sleeveNumber].synchronize(player);
},
setToCommitCrime: function (_sleeveNumber: unknown, _crimeRoughName: unknown): boolean {
helper.updateDynamicRam("setToCommitCrime", getRamCost(player, "sleeve", "setToCommitCrime"));
updateRam("setToCommitCrime");
const sleeveNumber = helper.number("setToCommitCrime", "sleeveNumber", _sleeveNumber);
const crimeRoughName = helper.string("setToCommitCrime", "crimeName", _crimeRoughName);
checkSleeveAPIAccess("setToCommitCrime");
@ -83,7 +86,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].commitCrime(player, crime.name);
},
setToUniversityCourse: function (_sleeveNumber: unknown, _universityName: unknown, _className: unknown): boolean {
helper.updateDynamicRam("setToUniversityCourse", getRamCost(player, "sleeve", "setToUniversityCourse"));
updateRam("setToUniversityCourse");
const sleeveNumber = helper.number("setToUniversityCourse", "sleeveNumber", _sleeveNumber);
const universityName = helper.string("setToUniversityCourse", "universityName", _universityName);
const className = helper.string("setToUniversityCourse", "className", _className);
@ -92,7 +95,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].takeUniversityCourse(player, universityName, className);
},
travel: function (_sleeveNumber: unknown, _cityName: unknown): boolean {
helper.updateDynamicRam("travel", getRamCost(player, "sleeve", "travel"));
updateRam("travel");
const sleeveNumber = helper.number("travel", "sleeveNumber", _sleeveNumber);
const cityName = helper.string("setToUniversityCourse", "cityName", _cityName);
checkSleeveAPIAccess("travel");
@ -100,7 +103,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].travel(player, cityName as CityName);
},
setToCompanyWork: function (_sleeveNumber: unknown, acompanyName: unknown): boolean {
helper.updateDynamicRam("setToCompanyWork", getRamCost(player, "sleeve", "setToCompanyWork"));
updateRam("setToCompanyWork");
const sleeveNumber = helper.number("setToCompanyWork", "sleeveNumber", _sleeveNumber);
const companyName = helper.string("setToUniversityCourse", "companyName", acompanyName);
checkSleeveAPIAccess("setToCompanyWork");
@ -127,7 +130,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
_factionName: unknown,
_workType: unknown,
): boolean | undefined {
helper.updateDynamicRam("setToFactionWork", getRamCost(player, "sleeve", "setToFactionWork"));
updateRam("setToFactionWork");
const sleeveNumber = helper.number("setToFactionWork", "sleeveNumber", _sleeveNumber);
const factionName = helper.string("setToUniversityCourse", "factionName", _factionName);
const workType = helper.string("setToUniversityCourse", "workType", _workType);
@ -158,7 +161,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].workForFaction(player, factionName, workType);
},
setToGymWorkout: function (_sleeveNumber: unknown, _gymName: unknown, _stat: unknown): boolean {
helper.updateDynamicRam("setToGymWorkout", getRamCost(player, "sleeve", "setToGymWorkout"));
updateRam("setToGymWorkout");
const sleeveNumber = helper.number("setToGymWorkout", "sleeveNumber", _sleeveNumber);
const gymName = helper.string("setToUniversityCourse", "gymName", _gymName);
const stat = helper.string("setToUniversityCourse", "stat", _stat);
@ -168,14 +171,14 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return player.sleeves[sleeveNumber].workoutAtGym(player, gymName, stat);
},
getSleeveStats: function (_sleeveNumber: unknown): SleeveSkills {
helper.updateDynamicRam("getSleeveStats", getRamCost(player, "sleeve", "getSleeveStats"));
updateRam("getSleeveStats");
const sleeveNumber = helper.number("getSleeveStats", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("getSleeveStats");
checkSleeveNumber("getSleeveStats", sleeveNumber);
return getSleeveStats(sleeveNumber);
},
getTask: function (_sleeveNumber: unknown): SleeveTask {
helper.updateDynamicRam("getTask", getRamCost(player, "sleeve", "getTask"));
updateRam("getTask");
const sleeveNumber = helper.number("getTask", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("getTask");
checkSleeveNumber("getTask", sleeveNumber);
@ -190,7 +193,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
};
},
getInformation: function (_sleeveNumber: unknown): SleeveInformation {
helper.updateDynamicRam("getInformation", getRamCost(player, "sleeve", "getInformation"));
updateRam("getInformation");
const sleeveNumber = helper.number("getInformation", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("getInformation");
checkSleeveNumber("getInformation", sleeveNumber);
@ -256,7 +259,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
};
},
getSleeveAugmentations: function (_sleeveNumber: unknown): string[] {
helper.updateDynamicRam("getSleeveAugmentations", getRamCost(player, "sleeve", "getSleeveAugmentations"));
updateRam("getSleeveAugmentations");
const sleeveNumber = helper.number("getSleeveAugmentations", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("getSleeveAugmentations");
checkSleeveNumber("getSleeveAugmentations", sleeveNumber);
@ -268,7 +271,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return augs;
},
getSleevePurchasableAugs: function (_sleeveNumber: unknown): AugmentPair[] {
helper.updateDynamicRam("getSleevePurchasableAugs", getRamCost(player, "sleeve", "getSleevePurchasableAugs"));
updateRam("getSleevePurchasableAugs");
const sleeveNumber = helper.number("getSleevePurchasableAugs", "sleeveNumber", _sleeveNumber);
checkSleeveAPIAccess("getSleevePurchasableAugs");
checkSleeveNumber("getSleevePurchasableAugs", sleeveNumber);
@ -286,7 +289,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel
return augs;
},
purchaseSleeveAug: function (_sleeveNumber: unknown, _augName: unknown): boolean {
helper.updateDynamicRam("purchaseSleeveAug", getRamCost(player, "sleeve", "purchaseSleeveAug"));
updateRam("purchaseSleeveAug");
const sleeveNumber = helper.number("purchaseSleeveAug", "sleeveNumber", _sleeveNumber);
const augName = helper.string("purchaseSleeveAug", "augName", _augName);
checkSleeveAPIAccess("purchaseSleeveAug");

@ -21,22 +21,24 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
}
}
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "stanek", funcName));
return {
giftWidth: function (): number {
helper.updateDynamicRam("giftWidth", getRamCost(player, "stanek", "giftWidth"));
updateRam("giftWidth");
checkStanekAPIAccess("giftWidth");
return staneksGift.width();
},
giftHeight: function (): number {
helper.updateDynamicRam("giftHeight", getRamCost(player, "stanek", "giftHeight"));
updateRam("giftHeight");
checkStanekAPIAccess("giftHeight");
return staneksGift.height();
},
chargeFragment: function (_rootX: unknown, _rootY: unknown): Promise<void> {
updateRam("chargeFragment");
const rootX = helper.number("stanek.chargeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.chargeFragment", "rootY", _rootY);
helper.updateDynamicRam("chargeFragment", getRamCost(player, "stanek", "chargeFragment"));
checkStanekAPIAccess("chargeFragment");
const fragment = staneksGift.findFragment(rootX, rootY);
if (!fragment)
@ -49,13 +51,13 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
});
},
fragmentDefinitions: function (): IFragment[] {
helper.updateDynamicRam("fragmentDefinitions", getRamCost(player, "stanek", "fragmentDefinitions"));
updateRam("fragmentDefinitions");
checkStanekAPIAccess("fragmentDefinitions");
workerScript.log("stanek.fragmentDefinitions", () => `Returned ${Fragments.length} fragments`);
return Fragments.map((f) => f.copy());
},
activeFragments: function (): IActiveFragment[] {
helper.updateDynamicRam("activeFragments", getRamCost(player, "stanek", "activeFragments"));
updateRam("activeFragments");
checkStanekAPIAccess("activeFragments");
workerScript.log("stanek.activeFragments", () => `Returned ${staneksGift.fragments.length} fragments`);
return staneksGift.fragments.map((af) => {
@ -63,17 +65,17 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
});
},
clearGift: function (): void {
helper.updateDynamicRam("clearGift", getRamCost(player, "stanek", "clearGift"));
updateRam("clearGift");
checkStanekAPIAccess("clearGift");
workerScript.log("stanek.clearGift", () => `Cleared Stanek's Gift.`);
staneksGift.clear();
},
canPlaceFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
updateRam("canPlaceFragment");
const rootX = helper.number("stanek.canPlaceFragment", "rootX", _rootX);
const rootY = helper.number("stanek.canPlaceFragment", "rootY", _rootY);
const rotation = helper.number("stanek.canPlaceFragment", "rotation", _rotation);
const fragmentId = helper.number("stanek.canPlaceFragment", "fragmentId", _fragmentId);
helper.updateDynamicRam("canPlaceFragment", getRamCost(player, "stanek", "canPlaceFragment"));
checkStanekAPIAccess("canPlaceFragment");
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlaceFragment", `Invalid fragment id: ${fragmentId}`);
@ -81,29 +83,29 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
return can;
},
placeFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
updateRam("placeFragment");
const rootX = helper.number("stanek.placeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.placeFragment", "rootY", _rootY);
const rotation = helper.number("stanek.placeFragment", "rotation", _rotation);
const fragmentId = helper.number("stanek.placeFragment", "fragmentId", _fragmentId);
helper.updateDynamicRam("placeFragment", getRamCost(player, "stanek", "placeFragment"));
checkStanekAPIAccess("placeFragment");
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.placeFragment", `Invalid fragment id: ${fragmentId}`);
return staneksGift.place(rootX, rootY, rotation, fragment);
},
getFragment: function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
updateRam("getFragment");
const rootX = helper.number("stanek.getFragment", "rootX", _rootX);
const rootY = helper.number("stanek.getFragment", "rootY", _rootY);
helper.updateDynamicRam("getFragment", getRamCost(player, "stanek", "getFragment"));
checkStanekAPIAccess("getFragment");
const fragment = staneksGift.findFragment(rootX, rootY);
if (fragment !== undefined) return fragment.copy();
return undefined;
},
removeFragment: function (_rootX: unknown, _rootY: unknown): boolean {
updateRam("removeFragment");
const rootX = helper.number("stanek.removeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.removeFragment", "rootY", _rootY);
helper.updateDynamicRam("removeFragment", getRamCost(player, "stanek", "removeFragment"));
checkStanekAPIAccess("removeFragment");
return staneksGift.delete(rootX, rootY);
},

@ -38,14 +38,18 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock;
};
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "stock", funcName));
return {
getSymbols: function (): string[] {
helper.updateDynamicRam("getSymbols", getRamCost(player, "stock", "getSymbols"));
updateRam("getSymbols");
checkTixApiAccess("getSymbols");
return Object.values(StockSymbols);
},
getPrice: function (_symbol: unknown): number {
helper.updateDynamicRam("getPrice", getRamCost(player, "stock", "getPrice"));
updateRam("getPrice");
const symbol = helper.string("getPrice", "symbol", _symbol);
checkTixApiAccess("getPrice");
const stock = getStockFromSymbol(symbol, "getPrice");
@ -53,7 +57,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock.price;
},
getAskPrice: function (_symbol: unknown): number {
helper.updateDynamicRam("getAskPrice", getRamCost(player, "stock", "getAskPrice"));
updateRam("getAskPrice");
const symbol = helper.string("getAskPrice", "symbol", _symbol);
checkTixApiAccess("getAskPrice");
const stock = getStockFromSymbol(symbol, "getAskPrice");
@ -61,7 +65,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock.getAskPrice();
},
getBidPrice: function (_symbol: unknown): number {
helper.updateDynamicRam("getBidPrice", getRamCost(player, "stock", "getBidPrice"));
updateRam("getBidPrice");
const symbol = helper.string("getBidPrice", "symbol", _symbol);
checkTixApiAccess("getBidPrice");
const stock = getStockFromSymbol(symbol, "getBidPrice");
@ -69,7 +73,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock.getBidPrice();
},
getPosition: function (_symbol: unknown): [number, number, number, number] {
helper.updateDynamicRam("getPosition", getRamCost(player, "stock", "getPosition"));
updateRam("getPosition");
const symbol = helper.string("getPosition", "symbol", _symbol);
checkTixApiAccess("getPosition");
const stock = SymbolToStockMap[symbol];
@ -79,7 +83,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return [stock.playerShares, stock.playerAvgPx, stock.playerShortShares, stock.playerAvgShortPx];
},
getMaxShares: function (_symbol: unknown): number {
helper.updateDynamicRam("getMaxShares", getRamCost(player, "stock", "getMaxShares"));
updateRam("getMaxShares");
const symbol = helper.string("getMaxShares", "symbol", _symbol);
checkTixApiAccess("getMaxShares");
const stock = getStockFromSymbol(symbol, "getMaxShares");
@ -87,7 +91,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock.maxShares;
},
getPurchaseCost: function (_symbol: unknown, _shares: unknown, _posType: unknown): number {
helper.updateDynamicRam("getPurchaseCost", getRamCost(player, "stock", "getPurchaseCost"));
updateRam("getPurchaseCost");
const symbol = helper.string("getPurchaseCost", "symbol", _symbol);
let shares = helper.number("getPurchaseCost", "shares", _shares);
const posType = helper.string("getPurchaseCost", "posType", _posType);
@ -113,7 +117,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res;
},
getSaleGain: function (_symbol: unknown, _shares: unknown, _posType: unknown): number {
helper.updateDynamicRam("getSaleGain", getRamCost(player, "stock", "getSaleGain"));
updateRam("getSaleGain");
const symbol = helper.string("getSaleGain", "symbol", _symbol);
let shares = helper.number("getSaleGain", "shares", _shares);
const posType = helper.string("getSaleGain", "posType", _posType);
@ -139,7 +143,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res;
},
buy: function (_symbol: unknown, _shares: unknown): number {
helper.updateDynamicRam("buy", getRamCost(player, "stock", "buy"));
updateRam("buy");
const symbol = helper.string("buy", "symbol", _symbol);
const shares = helper.number("buy", "shares", _shares);
checkTixApiAccess("buy");
@ -148,7 +152,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res ? stock.getAskPrice() : 0;
},
sell: function (_symbol: unknown, _shares: unknown): number {
helper.updateDynamicRam("sell", getRamCost(player, "stock", "sell"));
updateRam("sell");
const symbol = helper.string("sell", "symbol", _symbol);
const shares = helper.number("sell", "shares", _shares);
checkTixApiAccess("sell");
@ -158,7 +162,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res ? stock.getBidPrice() : 0;
},
short: function (_symbol: unknown, _shares: unknown): number {
helper.updateDynamicRam("short", getRamCost(player, "stock", "short"));
updateRam("short");
const symbol = helper.string("short", "symbol", _symbol);
const shares = helper.number("short", "shares", _shares);
checkTixApiAccess("short");
@ -176,7 +180,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res ? stock.getBidPrice() : 0;
},
sellShort: function (_symbol: unknown, _shares: unknown): number {
helper.updateDynamicRam("sellShort", getRamCost(player, "stock", "sellShort"));
updateRam("sellShort");
const symbol = helper.string("sellShort", "symbol", _symbol);
const shares = helper.number("sellShort", "shares", _shares);
checkTixApiAccess("sellShort");
@ -194,7 +198,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return res ? stock.getAskPrice() : 0;
},
placeOrder: function (_symbol: unknown, _shares: unknown, _price: unknown, _type: unknown, _pos: unknown): boolean {
helper.updateDynamicRam("placeOrder", getRamCost(player, "stock", "placeOrder"));
updateRam("placeOrder");
const symbol = helper.string("placeOrder", "symbol", _symbol);
const shares = helper.number("placeOrder", "shares", _shares);
const price = helper.number("placeOrder", "price", _price);
@ -244,7 +248,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
_type: unknown,
_pos: unknown,
): boolean {
helper.updateDynamicRam("cancelOrder", getRamCost(player, "stock", "cancelOrder"));
updateRam("cancelOrder");
const symbol = helper.string("cancelOrder", "symbol", _symbol);
const shares = helper.number("cancelOrder", "shares", _shares);
const price = helper.number("cancelOrder", "price", _price);
@ -299,7 +303,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return cancelOrder(params, workerScript);
},
getOrders: function (): any {
helper.updateDynamicRam("getOrders", getRamCost(player, "stock", "getOrders"));
updateRam("getOrders");
checkTixApiAccess("getOrders");
if (player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 2) {
@ -331,7 +335,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return orders;
},
getVolatility: function (_symbol: unknown): number {
helper.updateDynamicRam("getVolatility", getRamCost(player, "stock", "getVolatility"));
updateRam("getVolatility");
const symbol = helper.string("getVolatility", "symbol", _symbol);
if (!player.has4SDataTixApi) {
throw helper.makeRuntimeErrorMsg("getVolatility", "You don't have 4S Market Data TIX API Access!");
@ -341,7 +345,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return stock.mv / 100; // Convert from percentage to decimal
},
getForecast: function (_symbol: unknown): number {
helper.updateDynamicRam("getForecast", getRamCost(player, "stock", "getForecast"));
updateRam("getForecast");
const symbol = helper.string("getForecast", "symbol", _symbol);
if (!player.has4SDataTixApi) {
throw helper.makeRuntimeErrorMsg("getForecast", "You don't have 4S Market Data TIX API Access!");
@ -353,7 +357,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return forecast / 100; // Convert from percentage to decimal
},
purchase4SMarketData: function (): boolean {
helper.updateDynamicRam("purchase4SMarketData", getRamCost(player, "stock", "purchase4SMarketData"));
updateRam("purchase4SMarketData");
checkTixApiAccess("purchase4SMarketData");
if (player.has4SData) {
@ -372,7 +376,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return true;
},
purchase4SMarketDataTixApi: function (): boolean {
helper.updateDynamicRam("purchase4SMarketDataTixApi", getRamCost(player, "stock", "purchase4SMarketDataTixApi"));
updateRam("purchase4SMarketDataTixApi");
checkTixApiAccess("purchase4SMarketDataTixApi");
if (player.has4SDataTixApi) {
@ -394,7 +398,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return true;
},
purchaseWseAccount: function (): boolean {
helper.updateDynamicRam("PurchaseWseAccount", getRamCost(player, "stock", "purchaseWseAccount"));
updateRam("PurchaseWseAccount");
if (player.hasWseAccount) {
workerScript.log("stock.purchaseWseAccount", () => "Already purchased WSE Account");
@ -412,7 +416,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
return true;
},
purchaseTixApi: function (): boolean {
helper.updateDynamicRam("purchaseTixApi", getRamCost(player, "stock", "purchaseTixApi"));
updateRam("purchaseTixApi");
if (player.hasTixApiAccess) {
workerScript.log("stock.purchaseTixApi", () => "Already purchased TIX API");

@ -20,19 +20,20 @@ export function NetscriptUserInterface(
workerScript: WorkerScript,
helper: INetscriptHelper,
): IUserInterface {
const updateRam = (funcName: string): void => helper.updateDynamicRam(funcName, getRamCost(player, "ui", funcName));
return {
getTheme: function (): UserInterfaceTheme {
helper.updateDynamicRam("getTheme", getRamCost(player, "ui", "getTheme"));
updateRam("getTheme");
return { ...Settings.theme };
},
getStyles: function (): IStyleSettings {
helper.updateDynamicRam("getStyles", getRamCost(player, "ui", "getStyles"));
updateRam("getStyles");
return { ...Settings.styles };
},
setTheme: function (newTheme: UserInterfaceTheme): void {
helper.updateDynamicRam("setTheme", getRamCost(player, "ui", "setTheme"));
updateRam("setTheme");
const hex = /^(#)((?:[A-Fa-f0-9]{2}){3,4}|(?:[A-Fa-f0-9]{3}))$/;
const currentTheme = { ...Settings.theme };
const errors: string[] = [];
@ -57,7 +58,7 @@ export function NetscriptUserInterface(
},
setStyles: function (newStyles: IStyleSettings): void {
helper.updateDynamicRam("setStyles", getRamCost(player, "ui", "setStyles"));
updateRam("setStyles");
const currentStyles = { ...Settings.styles };
const errors: string[] = [];
@ -80,21 +81,21 @@ export function NetscriptUserInterface(
},
resetTheme: function (): void {
helper.updateDynamicRam("resetTheme", getRamCost(player, "ui", "resetTheme"));
updateRam("resetTheme");
Settings.theme = { ...defaultTheme };
ThemeEvents.emit();
workerScript.log("ui.resetTheme", () => `Reinitialized theme to default`);
},
resetStyles: function (): void {
helper.updateDynamicRam("resetStyles", getRamCost(player, "ui", "resetStyles"));
updateRam("resetStyles");
Settings.styles = { ...defaultStyles };
ThemeEvents.emit();
workerScript.log("ui.resetStyles", () => `Reinitialized styles to default`);
},
getGameInfo: function (): GameInfo {
helper.updateDynamicRam("getGameInfo", getRamCost(player, "ui", "getGameInfo"));
updateRam("getGameInfo");
const version = CONSTANTS.VersionString;
const commit = hash();
const platform = navigator.userAgent.toLowerCase().indexOf(" electron/") > -1 ? "Steam" : "Browser";

@ -94,7 +94,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
runPotentiallyAsyncFunction(curr, ...args);
runPotentiallyAsyncFunction(curr, ...args);
runPotentiallyAsyncFunction(curr, ...args);
} catch (e) {}
} catch (e) { }
} else {
throw new Error(`Invalid function specified: [${fnDesc}]`);
}
@ -160,7 +160,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
runPotentiallyAsyncFunction(curr);
runPotentiallyAsyncFunction(curr);
runPotentiallyAsyncFunction(curr);
} catch (e) {}
} catch (e) { }
} else {
throw new Error(`Invalid function specified: [${fnDesc}]`);
}
@ -293,7 +293,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
it("exec()", async function () {
const f = ["exec"];
jest.spyOn(console, "log").mockImplementation(() => {}); // eslint-disable-line
jest.spyOn(console, "log").mockImplementation(() => { }); // eslint-disable-line
await testNonzeroDynamicRamCost(f);
});

@ -0,0 +1,336 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { describe, expect, jest } from "@jest/globals";
// Player is needed for calculating costs like Singularity functions, that depend on acquired source files
import { Player } from "../../../src/Player";
import { RamCostConstants } from "../../../src/Netscript/RamCostGenerator";
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
import { Script } from "../../../src/Script/Script";
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
virtual: true,
});
const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost;
const HackCost = 0.1;
const GrowCost = 0.15;
const SleeveGetTaskCost = 4;
const HacknetCost = 4;
const CorpCost = 1024 - ScriptBaseCost;
describe("Parsing NetScript code to work out static RAM costs", function () {
// Tests numeric equality, allowing for floating point imprecision - and includes script base cost
function expectCost(val, expected) {
const expectedWithBase = expected + ScriptBaseCost;
expect(val).toBeGreaterThanOrEqual(expectedWithBase - 100 * Number.EPSILON);
expect(val).toBeLessThanOrEqual(expectedWithBase + 100 * Number.EPSILON);
}
describe("Single files with basic NS functions", function () {
it("Empty main function", async function () {
const code = `
export async function main(ns) { }
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, 0);
});
it("Free NS function directly in main", async function () {
const code = `
export async function main(ns) {
ns.print("Slum snakes r00l!");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, 0);
});
it("Single simple base NS function directly in main", async function () {
const code = `
export async function main(ns) {
await ns.hack("joesguns");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
it("Single simple base NS function directly in main with differing arg name", async function () {
const code = `
export async function main(X) {
await X.hack("joesguns");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
it("Repeated simple base NS function directly in main", async function () {
const code = `
export async function main(ns) {
await ns.hack("joesguns");
await ns.hack("joesguns");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
it("Multiple simple base NS functions directly in main", async function () {
const code = `
export async function main(ns) {
await ns.hack("joesguns");
await ns.grow("joesguns");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost + GrowCost);
});
it("Simple base NS functions in a referenced function", async function () {
const code = `
export async function main(ns) {
doHacking(ns);
}
async function doHacking(ns) {
await ns.hack("joesguns");
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
it("Simple base NS functions in a referenced class", async function () {
const code = `
export async function main(ns) {
await new Hacker(ns).doHacking();
}
class Hacker {
ns;
constructor(ns) { this.ns = ns; }
async doHacking() { await this.ns.hack("joesguns"); }
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
it("Simple base NS functions in a referenced class", async function () {
const code = `
export async function main(ns) {
await new Hacker(ns).doHacking();
}
class Hacker {
#ns;
constructor(ns) { this.#ns = ns; }
async doHacking() { await this.#ns.hack("joesguns"); }
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HackCost);
});
});
describe("Functions that can be confused with NS functions", function () {
it("Function 'get' that can be confused with Stanek.get", async function () {
const code = `
export async function main(ns) {
get();
}
function get() { return 0; }
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, 0);
});
it("Function 'purchaseNode' that can be confused with Hacknet.purchaseNode", async function () {
const code = `
export async function main(ns) {
purchaseNode();
}
function purchaseNode() { return 0; }
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
// Works at present, because the parser checks the namespace only, not the function name
expectCost(calculated, 0);
});
// TODO: once we fix static parsing this should pass
it.skip("Function 'getTask' that can be confused with Sleeve.getTask", async function () {
const code = `
export async function main(ns) {
getTask();
}
function getTask() { return 0; }
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, 0);
});
});
describe("Single files with non-core NS functions", function () {
it("Hacknet NS function with a cost from namespace", async function () {
const code = `
export async function main(ns) {
ns.hacknet.purchaseNode(0);
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, HacknetCost);
});
it("Corporation NS function with a cost from namespace", async function () {
const code = `
export async function main(ns) {
ns.corporation.getCorporation();
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, CorpCost);
});
it("Both Corporation and Hacknet functions", async function () {
const code = `
export async function main(ns) {
ns.corporation.getCorporation();
ns.hacknet.purchaseNode(0);
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, CorpCost + HacknetCost);
});
it("Sleeve functions with an individual cost", async function () {
const code = `
export async function main(ns) {
ns.sleeve.getTask(3);
}
`;
const calculated = (await calculateRamUsage(Player, code, [])).cost;
expectCost(calculated, SleeveGetTaskCost);
});
});
describe("Imported files", function () {
it("Simple imported function with no cost", async function () {
const libCode = `
export function dummy() { return 0; }
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import { dummy } from "libTest";
export async function main(ns) {
dummy();
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, 0);
});
it("Imported ns function", async function () {
const libCode = `
export async function doHack(ns) { return await ns.hack("joesguns"); }
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import { doHack } from "libTest";
export async function main(ns) {
await doHack(ns);
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, HackCost);
});
it("Importing a single function from a library that exports multiple", async function () {
const libCode = `
export async function doHack(ns) { return await ns.hack("joesguns"); }
export async function doGrow(ns) { return await ns.grow("joesguns"); }
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import { doHack } from "libTest";
export async function main(ns) {
await doHack(ns);
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, HackCost);
});
it("Importing all functions from a library that exports multiple", async function () {
const libCode = `
export async function doHack(ns) { return await ns.hack("joesguns"); }
export async function doGrow(ns) { return await ns.grow("joesguns"); }
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import * as test from "libTest";
export async function main(ns) {
await test.doHack(ns);
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, HackCost + GrowCost);
});
// TODO: once we fix static parsing this should pass
it.skip("Importing a function from a library that contains a class", async function () {
const libCode = `
export async function doHack(ns) { return await ns.hack("joesguns"); }
class Grower {
ns;
constructor(ns) { this.ns = ns; }
async doGrow() { return await this.ns.grow("joesguns"); }
}
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import * as test from "libTest";
export async function main(ns) {
await test.doHack(ns);
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, HackCost);
});
it("Importing a function from a library that creates a class in a function", async function () {
const libCode = `
export function createClass() {
class Grower {
ns;
constructor(ns) { this.ns = ns; }
async doGrow() { return await this.ns.grow("joesguns"); }
}
return Grower;
}
`;
const lib = new Script(Player, "libTest.js", libCode, []);
const code = `
import { createClass } from "libTest";
export async function main(ns) {
const grower = createClass();
const growerInstance = new grower(ns);
await growerInstance.doGrow();
}
`;
const calculated = (await calculateRamUsage(Player, code, [lib])).cost;
expectCost(calculated, GrowCost);
});
});
});

@ -3,213 +3,213 @@ import { numeralWrapper } from "../../../src/ui/numeralFormat";
let decimalFormat = "0.[000000]";
describe("Numeral formatting for positive numbers", () => {
test("should not format too small numbers", () => {
expect(numeralWrapper.format(0.0000000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(0.000000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(0.00000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(0.0000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(0.000001, decimalFormat)).toEqual("0.000001");
expect(numeralWrapper.format(0.00001, decimalFormat)).toEqual("0.00001");
expect(numeralWrapper.format(0.0001, decimalFormat)).toEqual("0.0001");
expect(numeralWrapper.format(0.001, decimalFormat)).toEqual("0.001");
expect(numeralWrapper.format(0.01, decimalFormat)).toEqual("0.01");
expect(numeralWrapper.format(0.1, decimalFormat)).toEqual("0.1");
expect(numeralWrapper.format(1, decimalFormat)).toEqual("1");
describe('Numeral formatting for positive numbers', () => {
test('should not format too small numbers', () => {
expect(numeralWrapper.format(0.0000000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(0.000000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(0.00000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(0.0000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(0.000001, decimalFormat)).toEqual('0.000001');
expect(numeralWrapper.format(0.00001, decimalFormat)).toEqual('0.00001');
expect(numeralWrapper.format(0.0001, decimalFormat)).toEqual('0.0001');
expect(numeralWrapper.format(0.001, decimalFormat)).toEqual('0.001');
expect(numeralWrapper.format(0.01, decimalFormat)).toEqual('0.01');
expect(numeralWrapper.format(0.1, decimalFormat)).toEqual('0.1');
expect(numeralWrapper.format(1, decimalFormat)).toEqual('1');
});
test("should format big numbers in short format", () => {
expect(numeralWrapper.formatBigNumber(987654000000000000)).toEqual("987654.000t");
expect(numeralWrapper.formatBigNumber(987654300000000000)).toEqual("987654.300t");
expect(numeralWrapper.formatBigNumber(987654320000000000)).toEqual("987654.320t");
expect(numeralWrapper.formatBigNumber(987654321000000000)).toEqual("987654.321t");
expect(numeralWrapper.formatBigNumber(987654321900000000)).toEqual("987654.322t");
test('should format big numbers in short format', () => {
expect(numeralWrapper.formatBigNumber(987654000000000000)).toEqual('987654.000t');
expect(numeralWrapper.formatBigNumber(987654300000000000)).toEqual('987654.300t');
expect(numeralWrapper.formatBigNumber(987654320000000000)).toEqual('987654.320t');
expect(numeralWrapper.formatBigNumber(987654321000000000)).toEqual('987654.321t');
expect(numeralWrapper.formatBigNumber(987654321900000000)).toEqual('987654.322t');
});
test("should format really big numbers in readable format", () => {
expect(numeralWrapper.formatReallyBigNumber(987)).toEqual("987.000");
expect(numeralWrapper.formatReallyBigNumber(987654)).toEqual("987.654k");
expect(numeralWrapper.formatReallyBigNumber(987654321)).toEqual("987.654m");
expect(numeralWrapper.formatReallyBigNumber(987654321987)).toEqual("987.654b");
expect(numeralWrapper.formatReallyBigNumber(987654321987654)).toEqual("987.654t");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321)).toEqual("987.654q");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987)).toEqual("987.654Q");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654)).toEqual("987.654s");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321)).toEqual("987.654S");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987)).toEqual("987.654o");
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987654)).toEqual("987.654n");
test('should format really big numbers in readable format', () => {
expect(numeralWrapper.formatReallyBigNumber(987)).toEqual('987.000');
expect(numeralWrapper.formatReallyBigNumber(987654)).toEqual('987.654k');
expect(numeralWrapper.formatReallyBigNumber(987654321)).toEqual('987.654m');
expect(numeralWrapper.formatReallyBigNumber(987654321987)).toEqual('987.654b');
expect(numeralWrapper.formatReallyBigNumber(987654321987654)).toEqual('987.654t');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321)).toEqual('987.654q');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987)).toEqual('987.654Q');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654)).toEqual('987.654s');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321)).toEqual('987.654S');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987)).toEqual('987.654o');
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987654)).toEqual('987.654n');
});
test("should format even bigger really big numbers in scientific format", () => {
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987654321)).toEqual("9.877e+35");
expect(numeralWrapper.formatReallyBigNumber(9876543219876543219876543219876543219)).toEqual("9.877e+36");
expect(numeralWrapper.formatReallyBigNumber(98765432198765432198765432198765432198)).toEqual("9.877e+37");
test('should format even bigger really big numbers in scientific format', () => {
expect(numeralWrapper.formatReallyBigNumber(987654321987654321987654321987654321)).toEqual('9.877e+35');
expect(numeralWrapper.formatReallyBigNumber(9876543219876543219876543219876543219)).toEqual('9.877e+36');
expect(numeralWrapper.formatReallyBigNumber(98765432198765432198765432198765432198)).toEqual('9.877e+37');
});
test("should format percentage", () => {
expect(numeralWrapper.formatPercentage(1234.56789)).toEqual("123456.79%");
test('should format percentage', () => {
expect(numeralWrapper.formatPercentage(1234.56789)).toEqual('123456.79%');
});
});
describe("Numeral formatting for negative numbers", () => {
test("should not format too small numbers", () => {
expect(numeralWrapper.format(-0.0000000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(-0.000000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(-0.00000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(-0.0000001, decimalFormat)).toEqual("0");
expect(numeralWrapper.format(-0.000001, decimalFormat)).toEqual("-0.000001");
expect(numeralWrapper.format(-0.00001, decimalFormat)).toEqual("-0.00001");
expect(numeralWrapper.format(-0.0001, decimalFormat)).toEqual("-0.0001");
expect(numeralWrapper.format(-0.001, decimalFormat)).toEqual("-0.001");
expect(numeralWrapper.format(-0.01, decimalFormat)).toEqual("-0.01");
expect(numeralWrapper.format(-0.1, decimalFormat)).toEqual("-0.1");
expect(numeralWrapper.format(-1, decimalFormat)).toEqual("-1");
describe('Numeral formatting for negative numbers', () => {
test('should not format too small numbers', () => {
expect(numeralWrapper.format(-0.0000000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(-0.000000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(-0.00000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(-0.0000001, decimalFormat)).toEqual('0');
expect(numeralWrapper.format(-0.000001, decimalFormat)).toEqual('-0.000001');
expect(numeralWrapper.format(-0.00001, decimalFormat)).toEqual('-0.00001');
expect(numeralWrapper.format(-0.0001, decimalFormat)).toEqual('-0.0001');
expect(numeralWrapper.format(-0.001, decimalFormat)).toEqual('-0.001');
expect(numeralWrapper.format(-0.01, decimalFormat)).toEqual('-0.01');
expect(numeralWrapper.format(-0.1, decimalFormat)).toEqual('-0.1');
expect(numeralWrapper.format(-1, decimalFormat)).toEqual('-1');
});
test("should format big numbers in short format", () => {
expect(numeralWrapper.formatBigNumber(-987654000000000000)).toEqual("-987654.000t");
expect(numeralWrapper.formatBigNumber(-987654300000000000)).toEqual("-987654.300t");
expect(numeralWrapper.formatBigNumber(-987654320000000000)).toEqual("-987654.320t");
expect(numeralWrapper.formatBigNumber(-987654321000000000)).toEqual("-987654.321t");
expect(numeralWrapper.formatBigNumber(-987654321900000000)).toEqual("-987654.322t");
test('should format big numbers in short format', () => {
expect(numeralWrapper.formatBigNumber(-987654000000000000)).toEqual('-987654.000t');
expect(numeralWrapper.formatBigNumber(-987654300000000000)).toEqual('-987654.300t');
expect(numeralWrapper.formatBigNumber(-987654320000000000)).toEqual('-987654.320t');
expect(numeralWrapper.formatBigNumber(-987654321000000000)).toEqual('-987654.321t');
expect(numeralWrapper.formatBigNumber(-987654321900000000)).toEqual('-987654.322t');
});
test("should format really big numbers in readable format", () => {
expect(numeralWrapper.formatReallyBigNumber(-987)).toEqual("-987.000");
expect(numeralWrapper.formatReallyBigNumber(-987654)).toEqual("-987.654k");
expect(numeralWrapper.formatReallyBigNumber(-987654321)).toEqual("-987.654m");
expect(numeralWrapper.formatReallyBigNumber(-987654321987)).toEqual("-987.654b");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654)).toEqual("-987.654t");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321)).toEqual("-987.654q");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987)).toEqual("-987.654Q");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654)).toEqual("-987.654s");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321)).toEqual("-987.654S");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987)).toEqual("-987.654o");
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987654)).toEqual("-987.654n");
test('should format really big numbers in readable format', () => {
expect(numeralWrapper.formatReallyBigNumber(-987)).toEqual('-987.000');
expect(numeralWrapper.formatReallyBigNumber(-987654)).toEqual('-987.654k');
expect(numeralWrapper.formatReallyBigNumber(-987654321)).toEqual('-987.654m');
expect(numeralWrapper.formatReallyBigNumber(-987654321987)).toEqual('-987.654b');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654)).toEqual('-987.654t');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321)).toEqual('-987.654q');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987)).toEqual('-987.654Q');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654)).toEqual('-987.654s');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321)).toEqual('-987.654S');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987)).toEqual('-987.654o');
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987654)).toEqual('-987.654n');
});
test("should format even bigger really big numbers in scientific format", () => {
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987654321)).toEqual("-9.877e+35");
expect(numeralWrapper.formatReallyBigNumber(-9876543219876543219876543219876543219)).toEqual("-9.877e+36");
expect(numeralWrapper.formatReallyBigNumber(-98765432198765432198765432198765432198)).toEqual("-9.877e+37");
test('should format even bigger really big numbers in scientific format', () => {
expect(numeralWrapper.formatReallyBigNumber(-987654321987654321987654321987654321)).toEqual('-9.877e+35');
expect(numeralWrapper.formatReallyBigNumber(-9876543219876543219876543219876543219)).toEqual('-9.877e+36');
expect(numeralWrapper.formatReallyBigNumber(-98765432198765432198765432198765432198)).toEqual('-9.877e+37');
});
test("should format percentage", () => {
expect(numeralWrapper.formatPercentage(-1234.56789)).toEqual("-123456.79%");
test('should format percentage', () => {
expect(numeralWrapper.formatPercentage(-1234.56789)).toEqual('-123456.79%');
});
});
describe("Numeral formatting of text", () => {
test("should filter non-numeric text", () => {
expect(numeralWrapper.format("abc")).toEqual("0");
expect(numeralWrapper.format("123abc")).toEqual("123");
expect(numeralWrapper.format("!3")).toEqual("3");
expect(numeralWrapper.format("3!")).toEqual("3");
expect(numeralWrapper.format("0.001", decimalFormat)).toEqual("0.001");
describe('Numeral formatting of text', () => {
test('should filter non-numeric text', () => {
expect(numeralWrapper.format('abc')).toEqual('0');
expect(numeralWrapper.format('123abc')).toEqual('123');
expect(numeralWrapper.format('!3')).toEqual('3');
expect(numeralWrapper.format('3!')).toEqual('3');
expect(numeralWrapper.format('0.001', decimalFormat)).toEqual('0.001');
});
test("should not format too small numbers", () => {
expect(numeralWrapper.format("0.00000001", decimalFormat)).toEqual("0");
expect(numeralWrapper.format("0.0000001", decimalFormat)).toEqual("0");
expect(numeralWrapper.format("0.000001", decimalFormat)).toEqual("0.000001");
expect(numeralWrapper.format("0.00001", decimalFormat)).toEqual("0.00001");
expect(numeralWrapper.format("1", decimalFormat)).toEqual("1");
expect(numeralWrapper.format("-0.00000001", decimalFormat)).toEqual("0");
expect(numeralWrapper.format("-0.0000001", decimalFormat)).toEqual("0");
expect(numeralWrapper.format("-0.000001", decimalFormat)).toEqual("-0.000001");
expect(numeralWrapper.format("-0.00001", decimalFormat)).toEqual("-0.00001");
expect(numeralWrapper.format("-1", decimalFormat)).toEqual("-1");
test('should not format too small numbers', () => {
expect(numeralWrapper.format('0.00000001', decimalFormat)).toEqual('0');
expect(numeralWrapper.format('0.0000001', decimalFormat)).toEqual('0');
expect(numeralWrapper.format('0.000001', decimalFormat)).toEqual('0.000001');
expect(numeralWrapper.format('0.00001', decimalFormat)).toEqual('0.00001');
expect(numeralWrapper.format('1', decimalFormat)).toEqual('1');
expect(numeralWrapper.format('-0.00000001', decimalFormat)).toEqual('0');
expect(numeralWrapper.format('-0.0000001', decimalFormat)).toEqual('0');
expect(numeralWrapper.format('-0.000001', decimalFormat)).toEqual('-0.000001');
expect(numeralWrapper.format('-0.00001', decimalFormat)).toEqual('-0.00001');
expect(numeralWrapper.format('-1', decimalFormat)).toEqual('-1');
});
test("should format big numbers in short format", () => {
expect(numeralWrapper.formatBigNumber("987654000000000000")).toEqual("987654.000t");
expect(numeralWrapper.formatBigNumber("987654300000000000")).toEqual("987654.300t");
expect(numeralWrapper.formatBigNumber("987654320000000000")).toEqual("987654.320t");
expect(numeralWrapper.formatBigNumber("987654321000000000")).toEqual("987654.321t");
expect(numeralWrapper.formatBigNumber("987654321900000000")).toEqual("987654.322t");
expect(numeralWrapper.formatBigNumber("-987654000000000000")).toEqual("-987654.000t");
expect(numeralWrapper.formatBigNumber("-987654300000000000")).toEqual("-987654.300t");
expect(numeralWrapper.formatBigNumber("-987654320000000000")).toEqual("-987654.320t");
expect(numeralWrapper.formatBigNumber("-987654321000000000")).toEqual("-987654.321t");
expect(numeralWrapper.formatBigNumber("-987654321900000000")).toEqual("-987654.322t");
test('should format big numbers in short format', () => {
expect(numeralWrapper.formatBigNumber('987654000000000000')).toEqual('987654.000t');
expect(numeralWrapper.formatBigNumber('987654300000000000')).toEqual('987654.300t');
expect(numeralWrapper.formatBigNumber('987654320000000000')).toEqual('987654.320t');
expect(numeralWrapper.formatBigNumber('987654321000000000')).toEqual('987654.321t');
expect(numeralWrapper.formatBigNumber('987654321900000000')).toEqual('987654.322t');
expect(numeralWrapper.formatBigNumber('-987654000000000000')).toEqual('-987654.000t');
expect(numeralWrapper.formatBigNumber('-987654300000000000')).toEqual('-987654.300t');
expect(numeralWrapper.formatBigNumber('-987654320000000000')).toEqual('-987654.320t');
expect(numeralWrapper.formatBigNumber('-987654321000000000')).toEqual('-987654.321t');
expect(numeralWrapper.formatBigNumber('-987654321900000000')).toEqual('-987654.322t');
});
test("should format really big numbers in readable format", () => {
expect(numeralWrapper.formatReallyBigNumber("987")).toEqual("987.000");
expect(numeralWrapper.formatReallyBigNumber("987654")).toEqual("987.654k");
expect(numeralWrapper.formatReallyBigNumber("987654321")).toEqual("987.654m");
expect(numeralWrapper.formatReallyBigNumber("987654321987")).toEqual("987.654b");
expect(numeralWrapper.formatReallyBigNumber("987654321987654")).toEqual("987.654t");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321")).toEqual("987.654q");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987")).toEqual("987.654Q");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987654")).toEqual("987.654s");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987654321")).toEqual("987.654S");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987654321987")).toEqual("987.654o");
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987654321987654")).toEqual("987.654n");
expect(numeralWrapper.formatReallyBigNumber("-987")).toEqual("-987.000");
expect(numeralWrapper.formatReallyBigNumber("-987654")).toEqual("-987.654k");
expect(numeralWrapper.formatReallyBigNumber("-987654321")).toEqual("-987.654m");
expect(numeralWrapper.formatReallyBigNumber("-987654321987")).toEqual("-987.654b");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654")).toEqual("-987.654t");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321")).toEqual("-987.654q");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987")).toEqual("-987.654Q");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987654")).toEqual("-987.654s");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987654321")).toEqual("-987.654S");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987654321987")).toEqual("-987.654o");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987654321987654")).toEqual("-987.654n");
test('should format really big numbers in readable format', () => {
expect(numeralWrapper.formatReallyBigNumber('987')).toEqual('987.000');
expect(numeralWrapper.formatReallyBigNumber('987654')).toEqual('987.654k');
expect(numeralWrapper.formatReallyBigNumber('987654321')).toEqual('987.654m');
expect(numeralWrapper.formatReallyBigNumber('987654321987')).toEqual('987.654b');
expect(numeralWrapper.formatReallyBigNumber('987654321987654')).toEqual('987.654t');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321')).toEqual('987.654q');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987')).toEqual('987.654Q');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987654')).toEqual('987.654s');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987654321')).toEqual('987.654S');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987654321987')).toEqual('987.654o');
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987654321987654')).toEqual('987.654n');
expect(numeralWrapper.formatReallyBigNumber('-987')).toEqual('-987.000');
expect(numeralWrapper.formatReallyBigNumber('-987654')).toEqual('-987.654k');
expect(numeralWrapper.formatReallyBigNumber('-987654321')).toEqual('-987.654m');
expect(numeralWrapper.formatReallyBigNumber('-987654321987')).toEqual('-987.654b');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654')).toEqual('-987.654t');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321')).toEqual('-987.654q');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987')).toEqual('-987.654Q');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987654')).toEqual('-987.654s');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987654321')).toEqual('-987.654S');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987654321987')).toEqual('-987.654o');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987654321987654')).toEqual('-987.654n');
});
test("should format even bigger really big numbers in scientific format", () => {
expect(numeralWrapper.formatReallyBigNumber("987654321987654321987654321987654321")).toEqual("9.877e+35");
expect(numeralWrapper.formatReallyBigNumber("9876543219876543219876543219876543219")).toEqual("9.877e+36");
expect(numeralWrapper.formatReallyBigNumber("98765432198765432198765432198765432198")).toEqual("9.877e+37");
expect(numeralWrapper.formatReallyBigNumber("-987654321987654321987654321987654321")).toEqual("-9.877e+35");
expect(numeralWrapper.formatReallyBigNumber("-9876543219876543219876543219876543219")).toEqual("-9.877e+36");
expect(numeralWrapper.formatReallyBigNumber("-98765432198765432198765432198765432198")).toEqual("-9.877e+37");
test('should format even bigger really big numbers in scientific format', () => {
expect(numeralWrapper.formatReallyBigNumber('987654321987654321987654321987654321')).toEqual('9.877e+35');
expect(numeralWrapper.formatReallyBigNumber('9876543219876543219876543219876543219')).toEqual('9.877e+36');
expect(numeralWrapper.formatReallyBigNumber('98765432198765432198765432198765432198')).toEqual('9.877e+37');
expect(numeralWrapper.formatReallyBigNumber('-987654321987654321987654321987654321')).toEqual('-9.877e+35');
expect(numeralWrapper.formatReallyBigNumber('-9876543219876543219876543219876543219')).toEqual('-9.877e+36');
expect(numeralWrapper.formatReallyBigNumber('-98765432198765432198765432198765432198')).toEqual('-9.877e+37');
});
test("should format percentage", () => {
expect(numeralWrapper.formatPercentage("1234.56789")).toEqual("123456.79%");
expect(numeralWrapper.formatPercentage("-1234.56789")).toEqual("-123456.79%");
test('should format percentage', () => {
expect(numeralWrapper.formatPercentage('1234.56789')).toEqual('123456.79%');
expect(numeralWrapper.formatPercentage('-1234.56789')).toEqual('-123456.79%');
});
});
describe("Numeral formatting of scientific text", () => {
test("should format even bigger really big numbers in scientific format", () => {
describe('Numeral formatting of scientific text', () => {
test('should format even bigger really big numbers in scientific format', () => {
// Accepted by numeral.js
expect(numeralWrapper.parseMoney("123")).toEqual(123);
expect(numeralWrapper.parseMoney("123.456")).toEqual(123.456);
expect(numeralWrapper.parseMoney("123k")).toEqual(123000);
expect(numeralWrapper.parseMoney("123.456k")).toEqual(123456);
expect(numeralWrapper.parseMoney("123m")).toEqual(123000000);
expect(numeralWrapper.parseMoney("123.456m")).toEqual(123456000);
expect(numeralWrapper.parseMoney("123b")).toEqual(123000000000);
expect(numeralWrapper.parseMoney("123.456b")).toEqual(123456000000);
expect(numeralWrapper.parseMoney("123t")).toEqual(123000000000000);
expect(numeralWrapper.parseMoney("123.456t")).toEqual(123456000000000);
expect(numeralWrapper.parseMoney('123')).toEqual(123);
expect(numeralWrapper.parseMoney('123.456')).toEqual(123.456);
expect(numeralWrapper.parseMoney('123k')).toEqual(123000);
expect(numeralWrapper.parseMoney('123.456k')).toEqual(123456);
expect(numeralWrapper.parseMoney('123m')).toEqual(123000000);
expect(numeralWrapper.parseMoney('123.456m')).toEqual(123456000);
expect(numeralWrapper.parseMoney('123b')).toEqual(123000000000);
expect(numeralWrapper.parseMoney('123.456b')).toEqual(123456000000);
expect(numeralWrapper.parseMoney('123t')).toEqual(123000000000000);
expect(numeralWrapper.parseMoney('123.456t')).toEqual(123456000000000);
// Custom formats, parseFloat has some rounding issues
expect(numeralWrapper.parseMoney("123q")).toBeCloseTo(123000000000000000);
expect(numeralWrapper.parseMoney("123.456q")).toBeCloseTo(123456000000000000);
expect(numeralWrapper.parseMoney("123Q")).toBeCloseTo(123000000000000000000);
expect(numeralWrapper.parseMoney("123.456Q")).toBeCloseTo(123456000000000000000);
expect(numeralWrapper.parseMoney("123s")).toBeCloseTo(123000000000000000000000);
expect(numeralWrapper.parseMoney("123.456s")).toBeCloseTo(123456000000000000000000);
expect(numeralWrapper.parseMoney("123S")).toBeCloseTo(123000000000000000000000000);
expect(numeralWrapper.parseMoney("123.456S")).toBeCloseTo(123456000000000000000000000);
expect(numeralWrapper.parseMoney('123q')).toBeCloseTo(123000000000000000);
expect(numeralWrapper.parseMoney('123.456q')).toBeCloseTo(123456000000000000);
expect(numeralWrapper.parseMoney('123Q')).toBeCloseTo(123000000000000000000);
expect(numeralWrapper.parseMoney('123.456Q')).toBeCloseTo(123456000000000000000);
expect(numeralWrapper.parseMoney('123s')).toBeCloseTo(123000000000000000000000);
expect(numeralWrapper.parseMoney('123.456s')).toBeCloseTo(123456000000000000000000);
expect(numeralWrapper.parseMoney('123S')).toBeCloseTo(123000000000000000000000000);
expect(numeralWrapper.parseMoney('123.456S')).toBeCloseTo(123456000000000000000000000);
// Larger numbers fail the test due to rounding issues
//expect(numeralWrapper.parseMoney('123o')).toBeCloseTo(123000000000000000000000000000);
//expect(numeralWrapper.parseMoney('123.456o')).toBeCloseTo(123456000000000000000000000000);
//expect(numeralWrapper.parseMoney('123n')).toBeCloseTo(123000000000000000000000000000000);
//expect(numeralWrapper.parseMoney('123.456n')).toBeCloseTo(123456000000000000000000000000000);
});
test("should format even bigger really big negative numbers in scientific format", () => {
test('should format even bigger really big negative numbers in scientific format', () => {
// Accepted by numeral.js
expect(numeralWrapper.parseMoney("-123")).toEqual(-123);
expect(numeralWrapper.parseMoney("-123.456")).toEqual(-123.456);
expect(numeralWrapper.parseMoney("-123k")).toEqual(-123000);
expect(numeralWrapper.parseMoney("-123.456k")).toEqual(-123456);
expect(numeralWrapper.parseMoney("-123m")).toEqual(-123000000);
expect(numeralWrapper.parseMoney("-123.456m")).toEqual(-123456000);
expect(numeralWrapper.parseMoney("-123b")).toEqual(-123000000000);
expect(numeralWrapper.parseMoney("-123.456b")).toEqual(-123456000000);
expect(numeralWrapper.parseMoney("-123t")).toEqual(-123000000000000);
expect(numeralWrapper.parseMoney("-123.456t")).toEqual(-123456000000000);
expect(numeralWrapper.parseMoney('-123')).toEqual(-123);
expect(numeralWrapper.parseMoney('-123.456')).toEqual(-123.456);
expect(numeralWrapper.parseMoney('-123k')).toEqual(-123000);
expect(numeralWrapper.parseMoney('-123.456k')).toEqual(-123456);
expect(numeralWrapper.parseMoney('-123m')).toEqual(-123000000);
expect(numeralWrapper.parseMoney('-123.456m')).toEqual(-123456000);
expect(numeralWrapper.parseMoney('-123b')).toEqual(-123000000000);
expect(numeralWrapper.parseMoney('-123.456b')).toEqual(-123456000000);
expect(numeralWrapper.parseMoney('-123t')).toEqual(-123000000000000);
expect(numeralWrapper.parseMoney('-123.456t')).toEqual(-123456000000000);
// Custom formats, parseFloat has some rounding issues
expect(numeralWrapper.parseMoney("-123q")).toBeCloseTo(-123000000000000000);
expect(numeralWrapper.parseMoney("-123.456q")).toBeCloseTo(-123456000000000000);
expect(numeralWrapper.parseMoney("-123Q")).toBeCloseTo(-123000000000000000000);
expect(numeralWrapper.parseMoney("-123.456Q")).toBeCloseTo(-123456000000000000000);
expect(numeralWrapper.parseMoney("-123s")).toBeCloseTo(-123000000000000000000000);
expect(numeralWrapper.parseMoney("-123.456s")).toBeCloseTo(-123456000000000000000000);
expect(numeralWrapper.parseMoney("-123S")).toBeCloseTo(-123000000000000000000000000);
expect(numeralWrapper.parseMoney("-123.456S")).toBeCloseTo(-123456000000000000000000000);
expect(numeralWrapper.parseMoney('-123q')).toBeCloseTo(-123000000000000000);
expect(numeralWrapper.parseMoney('-123.456q')).toBeCloseTo(-123456000000000000);
expect(numeralWrapper.parseMoney('-123Q')).toBeCloseTo(-123000000000000000000);
expect(numeralWrapper.parseMoney('-123.456Q')).toBeCloseTo(-123456000000000000000);
expect(numeralWrapper.parseMoney('-123s')).toBeCloseTo(-123000000000000000000000);
expect(numeralWrapper.parseMoney('-123.456s')).toBeCloseTo(-123456000000000000000000);
expect(numeralWrapper.parseMoney('-123S')).toBeCloseTo(-123000000000000000000000000);
expect(numeralWrapper.parseMoney('-123.456S')).toBeCloseTo(-123456000000000000000000000);
// Larger numbers fail the test due to rounding issues
//expect(numeralWrapper.parseMoney('-123o')).toBeCloseTo(-123000000000000000000000000000);
//expect(numeralWrapper.parseMoney('-123.456o')).toBeCloseTo(-123456000000000000000000000000);
@ -218,30 +218,30 @@ describe("Numeral formatting of scientific text", () => {
});
});
describe("Finding the number furthest away from 0", () => {
test("should work if all numbers are equal", () => {
describe('Finding the number furthest away from 0', () => {
test('should work if all numbers are equal', () => {
expect(numeralWrapper.largestAbsoluteNumber(0, 0, 0)).toEqual(0);
expect(numeralWrapper.largestAbsoluteNumber(1, 1, 1)).toEqual(1);
expect(numeralWrapper.largestAbsoluteNumber(123, 123, 123)).toEqual(123);
expect(numeralWrapper.largestAbsoluteNumber(-1, -1, -1)).toEqual(-1);
expect(numeralWrapper.largestAbsoluteNumber(-123, -123, -123)).toEqual(-123);
});
test("should work for different positive numbers, and for the largest number in each spot", () => {
test('should work for different positive numbers, and for the largest number in each spot', () => {
expect(numeralWrapper.largestAbsoluteNumber(1, 2, 3)).toEqual(3);
expect(numeralWrapper.largestAbsoluteNumber(456, 789, 123)).toEqual(789);
expect(numeralWrapper.largestAbsoluteNumber(789123, 123456, 456789)).toEqual(789123);
});
test("should work for different negative numbers, and for the smallest number in each spot", () => {
test('should work for different negative numbers, and for the smallest number in each spot', () => {
expect(numeralWrapper.largestAbsoluteNumber(-1, -2, -3)).toEqual(-3);
expect(numeralWrapper.largestAbsoluteNumber(-456, -789, -123)).toEqual(-789);
expect(numeralWrapper.largestAbsoluteNumber(-789123, -123456, -456789)).toEqual(-789123);
});
test("should work for combined positive and negative numbers", () => {
test('should work for combined positive and negative numbers', () => {
expect(numeralWrapper.largestAbsoluteNumber(1, -2, 3)).toEqual(3);
expect(numeralWrapper.largestAbsoluteNumber(-456, 789, -123)).toEqual(789);
expect(numeralWrapper.largestAbsoluteNumber(789123, -123456, -456789)).toEqual(789123);
});
test("Should return 0 for invalid input", () => {
expect(numeralWrapper.largestAbsoluteNumber("abc", undefined, null)).toEqual(0);
test('Should return 0 for invalid input', () => {
expect(numeralWrapper.largestAbsoluteNumber('abc', undefined, null)).toEqual(0);
});
});