mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 12:45:45 +01:00
TESTS: Prevent some test spam (#1126)
This commit is contained in:
parent
373ced2efe
commit
91105c6d8c
@ -199,7 +199,6 @@ describe("Netscript Go API unit tests", () => {
|
|||||||
const mockLogger = jest.fn();
|
const mockLogger = jest.fn();
|
||||||
|
|
||||||
const result = await cheatPlayTwoMoves(mockLogger, 4, 3, 3, 4, 2, 1);
|
const result = await cheatPlayTwoMoves(mockLogger, 4, 3, 3, 4, 2, 1);
|
||||||
console.log(result);
|
|
||||||
expect(mockLogger).toHaveBeenCalledWith("Cheat failed. Your turn has been skipped.");
|
expect(mockLogger).toHaveBeenCalledWith("Cheat failed. Your turn has been skipped.");
|
||||||
expect(result.success).toEqual(false);
|
expect(result.success).toEqual(false);
|
||||||
expect(Go.currentGame.board[4]?.[3]?.color).toEqual(GoColor.empty);
|
expect(Go.currentGame.board[4]?.[3]?.color).toEqual(GoColor.empty);
|
||||||
@ -214,7 +213,6 @@ describe("Netscript Go API unit tests", () => {
|
|||||||
const mockLogger = jest.fn();
|
const mockLogger = jest.fn();
|
||||||
|
|
||||||
const result = await cheatPlayTwoMoves(mockLogger, 4, 3, 3, 4, 1, 0);
|
const result = await cheatPlayTwoMoves(mockLogger, 4, 3, 3, 4, 1, 0);
|
||||||
console.log(result);
|
|
||||||
expect(mockLogger).toHaveBeenCalledWith("Cheat failed! You have been ejected from the subnet.");
|
expect(mockLogger).toHaveBeenCalledWith("Cheat failed! You have been ejected from the subnet.");
|
||||||
expect(result.success).toEqual(false);
|
expect(result.success).toEqual(false);
|
||||||
expect(Go.currentGame.previousBoard).toEqual(null);
|
expect(Go.currentGame.previousBoard).toEqual(null);
|
||||||
@ -253,7 +251,6 @@ describe("Netscript Go API unit tests", () => {
|
|||||||
const mockLogger = jest.fn();
|
const mockLogger = jest.fn();
|
||||||
|
|
||||||
const result = await cheatRemoveRouter(mockLogger, 0, 0, 1, 0);
|
const result = await cheatRemoveRouter(mockLogger, 0, 0, 1, 0);
|
||||||
console.log(result);
|
|
||||||
expect(mockLogger).toHaveBeenCalledWith("Cheat failed! You have been ejected from the subnet.");
|
expect(mockLogger).toHaveBeenCalledWith("Cheat failed! You have been ejected from the subnet.");
|
||||||
expect(result.success).toEqual(false);
|
expect(result.success).toEqual(false);
|
||||||
expect(Go.currentGame.previousBoard).toEqual(null);
|
expect(Go.currentGame.previousBoard).toEqual(null);
|
||||||
|
@ -33,8 +33,6 @@ describe("Go AI tests", () => {
|
|||||||
const boardState = boardStateFromSimpleBoard(board, GoOpponent.Daedalus);
|
const boardState = boardStateFromSimpleBoard(board, GoOpponent.Daedalus);
|
||||||
const move = await getMove(boardState, GoColor.white, GoOpponent.Daedalus, 0);
|
const move = await getMove(boardState, GoColor.white, GoOpponent.Daedalus, 0);
|
||||||
|
|
||||||
console.log(move);
|
|
||||||
|
|
||||||
expect([move.x, move.y]).toEqual([0, 1]);
|
expect([move.x, move.y]).toEqual([0, 1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -50,10 +50,10 @@ describe("numCycleForGrowthCorrected reverses calculateServerGrowth", () => {
|
|||||||
const value = numCycleForGrowthCorrected(server, newMoney + eps, money, 1, player);
|
const value = numCycleForGrowthCorrected(server, newMoney + eps, money, 1, player);
|
||||||
// Write our own check because Jest is a goblin that can't provide context
|
// Write our own check because Jest is a goblin that can't provide context
|
||||||
if (value !== threads + 1) {
|
if (value !== threads + 1) {
|
||||||
console.log(
|
throw new Error(
|
||||||
`newMoney: ${newMoney} eps: ${eps} newMoney+eps: ${newMoney + eps} value: ${value} threads: ${threads}`,
|
`value (${value}) was not equal to threads+1 (${threads + 1})\n\n` +
|
||||||
|
`newMoney: ${newMoney} eps: ${eps} newMoney+eps: ${newMoney + eps} value: ${value} threads: ${threads}`,
|
||||||
);
|
);
|
||||||
expect(value).toBe(threads + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -67,10 +67,10 @@ describe("numCycleForGrowthCorrected reverses calculateServerGrowth", () => {
|
|||||||
const value = numCycleForGrowthCorrected(server, newMoney + eps, 0, 1, player);
|
const value = numCycleForGrowthCorrected(server, newMoney + eps, 0, 1, player);
|
||||||
// Write our own check because Jest is a goblin that can't provide context
|
// Write our own check because Jest is a goblin that can't provide context
|
||||||
if (value !== threads + 1) {
|
if (value !== threads + 1) {
|
||||||
console.log(
|
throw new Error(
|
||||||
`newMoney: ${newMoney} eps: ${eps} newMoney+eps: ${newMoney + eps} value: ${value} threads: ${threads}`,
|
`value (${value}) was not equal to threads+1 (${threads + 1})\n\n` +
|
||||||
|
`newMoney: ${newMoney} eps: ${eps} newMoney+eps: ${newMoney + eps} value: ${value} threads: ${threads}`,
|
||||||
);
|
);
|
||||||
expect(value).toBe(threads + 1);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -44,6 +44,7 @@ describe("MessageHelpers tests", () => {
|
|||||||
it("Should not repeatedly send the Icarus message after the player's first bitnode completion", () => {
|
it("Should not repeatedly send the Icarus message after the player's first bitnode completion", () => {
|
||||||
initSourceFiles();
|
initSourceFiles();
|
||||||
Player.sourceFiles.set(1, 1);
|
Player.sourceFiles.set(1, 1);
|
||||||
|
jest.spyOn(console, "warn").mockImplementation(() => {}); // Prevent test spam
|
||||||
Player.queueAugmentation(AugmentationName.TheRedPill);
|
Player.queueAugmentation(AugmentationName.TheRedPill);
|
||||||
installAugmentations();
|
installAugmentations();
|
||||||
Player.gainHackingExp(2 ** 200);
|
Player.gainHackingExp(2 ** 200);
|
||||||
|
@ -24,6 +24,7 @@ function grabCost<API>(ramEntry: RamCostTree<API>[keyof API]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("Netscript RAM Calculation/Generation Tests", function () {
|
describe("Netscript RAM Calculation/Generation Tests", function () {
|
||||||
|
jest.spyOn(console, "warn").mockImplementation(() => {});
|
||||||
Player.sourceFiles.set(4, 3);
|
Player.sourceFiles.set(4, 3);
|
||||||
// For simulating costs of singularity functions.
|
// For simulating costs of singularity functions.
|
||||||
const baseCost = RamCostConstants.Base;
|
const baseCost = RamCostConstants.Base;
|
||||||
@ -44,7 +45,9 @@ describe("Netscript RAM Calculation/Generation Tests", function () {
|
|||||||
function tryFunction(fn: PotentiallyAsyncFunction) {
|
function tryFunction(fn: PotentiallyAsyncFunction) {
|
||||||
try {
|
try {
|
||||||
fn()?.catch?.(() => undefined);
|
fn()?.catch?.(() => undefined);
|
||||||
} catch {}
|
} catch {
|
||||||
|
// Intentionally empty
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let scriptRef = createRunningScript("");
|
let scriptRef = createRunningScript("");
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type { ScriptFilePath } from "../../../src/Paths/ScriptFilePath";
|
||||||
|
|
||||||
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
|
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
|
||||||
import { RamCosts } from "../../../src/Netscript/RamCostGenerator";
|
import { RamCosts } from "../../../src/Netscript/RamCostGenerator";
|
||||||
import { Script } from "../../../src/Script/Script";
|
import { Script } from "../../../src/Script/Script";
|
||||||
@ -8,10 +10,10 @@ const GrowCost = 0.15;
|
|||||||
const SleeveGetTaskCost = 4;
|
const SleeveGetTaskCost = 4;
|
||||||
const HacknetCost = 4;
|
const HacknetCost = 4;
|
||||||
const MaxCost = 1024;
|
const MaxCost = 1024;
|
||||||
|
|
||||||
describe("Parsing NetScript code to work out static RAM costs", function () {
|
describe("Parsing NetScript code to work out static RAM costs", function () {
|
||||||
|
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||||
/** Tests numeric equality, allowing for floating point imprecision - and includes script base cost */
|
/** Tests numeric equality, allowing for floating point imprecision - and includes script base cost */
|
||||||
function expectCost(val: number, expected: number) {
|
function expectCost(val: number | undefined, expected: number) {
|
||||||
const expectedWithBase = Math.min(expected + BaseCost, MaxCost);
|
const expectedWithBase = Math.min(expected + BaseCost, MaxCost);
|
||||||
expect(val).toBeGreaterThanOrEqual(expectedWithBase - 100 * Number.EPSILON);
|
expect(val).toBeGreaterThanOrEqual(expectedWithBase - 100 * Number.EPSILON);
|
||||||
expect(val).toBeLessThanOrEqual(expectedWithBase + 100 * Number.EPSILON);
|
expect(val).toBeLessThanOrEqual(expectedWithBase + 100 * Number.EPSILON);
|
||||||
@ -186,7 +188,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
const libCode = `
|
const libCode = `
|
||||||
export function dummy() { return 0; }
|
export function dummy() { return 0; }
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import { dummy } from "libTest";
|
import { dummy } from "libTest";
|
||||||
@ -194,7 +196,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
dummy();
|
dummy();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, 0);
|
expectCost(calculated, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -202,7 +204,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
const libCode = `
|
const libCode = `
|
||||||
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import { doHack } from "libTest";
|
import { doHack } from "libTest";
|
||||||
@ -210,7 +212,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
await doHack(ns);
|
await doHack(ns);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, HackCost);
|
expectCost(calculated, HackCost);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -219,7 +221,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
||||||
export async function doGrow(ns) { return await ns.grow("joesguns"); }
|
export async function doGrow(ns) { return await ns.grow("joesguns"); }
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import { doHack } from "libTest";
|
import { doHack } from "libTest";
|
||||||
@ -227,7 +229,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
await doHack(ns);
|
await doHack(ns);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, HackCost);
|
expectCost(calculated, HackCost);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -236,7 +238,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
export async function doHack(ns) { return await ns.hack("joesguns"); }
|
||||||
export async function doGrow(ns) { return await ns.grow("joesguns"); }
|
export async function doGrow(ns) { return await ns.grow("joesguns"); }
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import * as test from "libTest";
|
import * as test from "libTest";
|
||||||
@ -244,7 +246,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
await test.doHack(ns);
|
await test.doHack(ns);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, HackCost + GrowCost);
|
expectCost(calculated, HackCost + GrowCost);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -279,7 +281,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
async doGrow() { return await this.ns.grow("joesguns"); }
|
async doGrow() { return await this.ns.grow("joesguns"); }
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import * as test from "libTest";
|
import * as test from "libTest";
|
||||||
@ -287,7 +289,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
await test.doHack(ns);
|
await test.doHack(ns);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, HackCost);
|
expectCost(calculated, HackCost);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -302,7 +304,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
return Grower;
|
return Grower;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const lib = new Script("libTest.js", libCode);
|
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
|
||||||
|
|
||||||
const code = `
|
const code = `
|
||||||
import { createClass } from "libTest";
|
import { createClass } from "libTest";
|
||||||
@ -313,7 +315,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
|
|||||||
await growerInstance.doGrow();
|
await growerInstance.doGrow();
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const calculated = calculateRamUsage(code, new Map([["libTest.js", lib]])).cost;
|
const calculated = calculateRamUsage(code, new Map([["libTest.js" as ScriptFilePath, lib]])).cost;
|
||||||
expectCost(calculated, GrowCost);
|
expectCost(calculated, GrowCost);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user