mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-23 14:42:28 +01:00
Fix #2344 tests failing due to SF4
This commit is contained in:
parent
c59a267437
commit
f4080ee615
@ -1,6 +1,7 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { jest, describe, expect, test } from "@jest/globals";
|
||||
|
||||
import { Player } from "../../src/Player";
|
||||
import { NetscriptFunctions } from "../../src/NetscriptFunctions";
|
||||
import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator";
|
||||
import { Environment } from "../../src/Netscript/Environment";
|
||||
@ -8,7 +9,7 @@ import { RunningScript } from "../../src/Script/RunningScript";
|
||||
import { Script } from "../../src/Script/Script";
|
||||
import { SourceFileFlags } from "../../src/SourceFile/SourceFileFlags";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => '', {
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
});
|
||||
|
||||
@ -19,7 +20,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
||||
async function createRunningScript(code) {
|
||||
const script = new Script();
|
||||
script.code = code;
|
||||
await script.updateRamUsage([]);
|
||||
await script.updateRamUsage(Player, []);
|
||||
|
||||
const runningScript = new RunningScript(script);
|
||||
|
||||
@ -52,7 +53,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
||||
if (!Array.isArray(fnDesc)) {
|
||||
throw new Error("Non-array passed to testNonzeroDynamicRamCost()");
|
||||
}
|
||||
const expected = getRamCost(...fnDesc);
|
||||
const expected = getRamCost(Player, ...fnDesc);
|
||||
expect(expected).toBeGreaterThan(0);
|
||||
|
||||
const code = `${fnDesc.join(".")}();`;
|
||||
@ -117,7 +118,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
||||
if (!Array.isArray(fnDesc)) {
|
||||
throw new Error("Non-array passed to testZeroDynamicRamCost()");
|
||||
}
|
||||
const expected = getRamCost(...fnDesc);
|
||||
const expected = getRamCost(Player, ...fnDesc);
|
||||
expect(expected).toEqual(0);
|
||||
if (skipRun) return;
|
||||
|
||||
@ -293,7 +294,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);
|
||||
});
|
||||
|
||||
@ -434,7 +435,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function () {
|
||||
|
||||
it("purchaseServer()", async function () {
|
||||
const f = ["purchaseServer"];
|
||||
await testNonzeroDynamicRamCost(f, "abc", '64');
|
||||
await testNonzeroDynamicRamCost(f, "abc", "64");
|
||||
});
|
||||
|
||||
it("deleteServer()", async function () {
|
||||
|
@ -1,9 +1,14 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { jest, describe, expect, test } from '@jest/globals'
|
||||
import { jest, describe, expect } from "@jest/globals";
|
||||
|
||||
import { Player } from "../../src/Player";
|
||||
import { getRamCost, RamCostConstants } from "../../src/Netscript/RamCostGenerator";
|
||||
import { calculateRamUsage } from "../../src/Script/RamCalculations";
|
||||
|
||||
jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", {
|
||||
virtual: true,
|
||||
});
|
||||
|
||||
const ScriptBaseCost = RamCostConstants.ScriptBaseRamCost;
|
||||
const HacknetNamespaceCost = RamCostConstants.ScriptHacknetNodesRamCost;
|
||||
|
||||
@ -26,16 +31,16 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
if (!Array.isArray(fnDesc)) {
|
||||
expect.fail("Non-array passed to expectNonZeroRamCost()");
|
||||
}
|
||||
const expected = getRamCost(...fnDesc);
|
||||
const expected = getRamCost(Player, ...fnDesc);
|
||||
expect(expected).toBeGreaterThan(0);
|
||||
|
||||
const code = fnDesc.join(".") + "(); ";
|
||||
|
||||
const calculated = await calculateRamUsage(code, []);
|
||||
const calculated = await calculateRamUsage(Player, code, []);
|
||||
testEquality(calculated, expected + ScriptBaseCost);
|
||||
|
||||
const multipleCallsCode = code.repeat(3);
|
||||
const multipleCallsCalculated = await calculateRamUsage(multipleCallsCode, []);
|
||||
const multipleCallsCalculated = await calculateRamUsage(Player, multipleCallsCode, []);
|
||||
expect(multipleCallsCalculated).toEqual(calculated);
|
||||
}
|
||||
|
||||
@ -51,15 +56,15 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
if (!Array.isArray(fnDesc)) {
|
||||
expect.fail("Non-array passed to expectZeroRamCost()");
|
||||
}
|
||||
const expected = getRamCost(...fnDesc);
|
||||
const expected = getRamCost(Player, ...fnDesc);
|
||||
expect(expected).toEqual(0);
|
||||
|
||||
const code = fnDesc.join(".") + "(); ";
|
||||
|
||||
const calculated = await calculateRamUsage(code, []);
|
||||
const calculated = await calculateRamUsage(Player, code, []);
|
||||
testEquality(calculated, ScriptBaseCost);
|
||||
|
||||
const multipleCallsCalculated = await calculateRamUsage(code, []);
|
||||
const multipleCallsCalculated = await calculateRamUsage(Player, code, []);
|
||||
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
||||
}
|
||||
|
||||
@ -495,7 +500,7 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
];
|
||||
it("should have zero RAM cost for all functions", function () {
|
||||
for (const fn of apiFunctions) {
|
||||
expect(getRamCost("hacknet", fn)).toEqual(0);
|
||||
expect(getRamCost(Player, "hacknet", fn)).toEqual(0);
|
||||
}
|
||||
});
|
||||
|
||||
@ -505,7 +510,7 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
||||
code += "hacknet." + fn + "(); ";
|
||||
}
|
||||
|
||||
const calculated = await calculateRamUsage(code, []);
|
||||
const calculated = await calculateRamUsage(Player, code, []);
|
||||
testEquality(calculated, ScriptBaseCost + HacknetNamespaceCost);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user