mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-09 23:07:40 +01:00
Merge pull request #3307 from steven-r/fix-3281
Fix 3281 - ns.goToLocation is expecting the wrong minimum RAM
This commit is contained in:
commit
d8b2c003c2
@ -226,7 +226,7 @@ export const RamCosts: IMap<any> = {
|
|||||||
universityCourse: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
universityCourse: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
gymWorkout: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
gymWorkout: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
travelToCity: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
travelToCity: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
goToLocation: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
goToLocation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost),
|
||||||
purchaseTor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
purchaseTor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
purchaseProgram: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
purchaseProgram: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
getCurrentServer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
getCurrentServer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost),
|
||||||
|
@ -66,6 +66,39 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
expect(multipleCallsCalculated).toEqual(ScriptBaseCost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simplyfied version from RamCostGenerator.ts
|
||||||
|
function SF4Cost(player, cost) {
|
||||||
|
if (player.bitNodeN === 4) return cost;
|
||||||
|
const sf4 = player.sourceFileLvl(4);
|
||||||
|
if (sf4 <= 1) return cost * 16;
|
||||||
|
if (sf4 === 2) return cost * 4;
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that:
|
||||||
|
* 1. A function has a specific RAM cost
|
||||||
|
* 2. The calculator and the generator result in equal values
|
||||||
|
* 3. Running multiple calls of the function does not result in additional RAM cost
|
||||||
|
* @param {string[]} fnDesc - describes the name of the function being tested,
|
||||||
|
* including the namespace(s). e.g. ["gang", "getMemberNames"]
|
||||||
|
* @param {number} cost - expected cost
|
||||||
|
*/
|
||||||
|
async function expectSpecificRamCost(fnDesc, cost) {
|
||||||
|
if (!Array.isArray(fnDesc)) {
|
||||||
|
expect.fail("Non-array passed to expectZeroRamCost()");
|
||||||
|
}
|
||||||
|
const expected = getRamCost(Player, ...fnDesc);
|
||||||
|
expect(expected).toEqual(SF4Cost(Player, cost));
|
||||||
|
|
||||||
|
const code = fnDesc.join(".") + "(); ";
|
||||||
|
const calculated = (await calculateRamUsage(Player, code, [])).cost;
|
||||||
|
testEquality(calculated, ScriptBaseCost+SF4Cost(Player, cost));
|
||||||
|
|
||||||
|
const multipleCallsCalculated = (await calculateRamUsage(Player, code, [])).cost;
|
||||||
|
expect(multipleCallsCalculated).toEqual(ScriptBaseCost+SF4Cost(Player, cost));
|
||||||
|
}
|
||||||
|
|
||||||
describe("Basic Functions", function () {
|
describe("Basic Functions", function () {
|
||||||
it("hack()", async function () {
|
it("hack()", async function () {
|
||||||
const f = ["hack"];
|
const f = ["hack"];
|
||||||
@ -466,6 +499,11 @@ describe("Netscript Static RAM Calculation/Generation Tests", function () {
|
|||||||
const f = ["getFavorToDonate"];
|
const f = ["getFavorToDonate"];
|
||||||
await expectNonZeroRamCost(f);
|
await expectNonZeroRamCost(f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("goToLocation()", async function () {
|
||||||
|
const f = ["goToLocation"];
|
||||||
|
await expectSpecificRamCost(f, RamCostConstants.ScriptSingularityFn3RamCost);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Advanced Functions", function () {
|
describe("Advanced Functions", function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user