TESTS: Prevent some test spam (#1126)

This commit is contained in:
Snarling 2024-02-26 08:22:33 -05:00 committed by GitHub
parent 373ced2efe
commit 91105c6d8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 26 deletions

@ -199,7 +199,6 @@ describe("Netscript Go API unit tests", () => {
const mockLogger = jest.fn();
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(result.success).toEqual(false);
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 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(result.success).toEqual(false);
expect(Go.currentGame.previousBoard).toEqual(null);
@ -253,7 +251,6 @@ describe("Netscript Go API unit tests", () => {
const mockLogger = jest.fn();
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(result.success).toEqual(false);
expect(Go.currentGame.previousBoard).toEqual(null);

@ -33,8 +33,6 @@ describe("Go AI tests", () => {
const boardState = boardStateFromSimpleBoard(board, GoOpponent.Daedalus);
const move = await getMove(boardState, GoColor.white, GoOpponent.Daedalus, 0);
console.log(move);
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);
// Write our own check because Jest is a goblin that can't provide context
if (value !== threads + 1) {
console.log(
throw new Error(
`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);
// Write our own check because Jest is a goblin that can't provide context
if (value !== threads + 1) {
console.log(
throw new Error(
`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", () => {
initSourceFiles();
Player.sourceFiles.set(1, 1);
jest.spyOn(console, "warn").mockImplementation(() => {}); // Prevent test spam
Player.queueAugmentation(AugmentationName.TheRedPill);
installAugmentations();
Player.gainHackingExp(2 ** 200);

@ -24,6 +24,7 @@ function grabCost<API>(ramEntry: RamCostTree<API>[keyof API]) {
}
describe("Netscript RAM Calculation/Generation Tests", function () {
jest.spyOn(console, "warn").mockImplementation(() => {});
Player.sourceFiles.set(4, 3);
// For simulating costs of singularity functions.
const baseCost = RamCostConstants.Base;
@ -44,7 +45,9 @@ describe("Netscript RAM Calculation/Generation Tests", function () {
function tryFunction(fn: PotentiallyAsyncFunction) {
try {
fn()?.catch?.(() => undefined);
} catch {}
} catch {
// Intentionally empty
}
}
let scriptRef = createRunningScript("");

@ -1,3 +1,5 @@
import type { ScriptFilePath } from "../../../src/Paths/ScriptFilePath";
import { calculateRamUsage } from "../../../src/Script/RamCalculations";
import { RamCosts } from "../../../src/Netscript/RamCostGenerator";
import { Script } from "../../../src/Script/Script";
@ -8,10 +10,10 @@ const GrowCost = 0.15;
const SleeveGetTaskCost = 4;
const HacknetCost = 4;
const MaxCost = 1024;
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 */
function expectCost(val: number, expected: number) {
function expectCost(val: number | undefined, expected: number) {
const expectedWithBase = Math.min(expected + BaseCost, MaxCost);
expect(val).toBeGreaterThanOrEqual(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 = `
export function dummy() { return 0; }
`;
const lib = new Script("libTest.js", libCode);
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
const code = `
import { dummy } from "libTest";
@ -194,7 +196,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
@ -202,7 +204,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
const libCode = `
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 = `
import { doHack } from "libTest";
@ -210,7 +212,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
@ -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 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 = `
import { doHack } from "libTest";
@ -227,7 +229,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
@ -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 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 = `
import * as test from "libTest";
@ -244,7 +246,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
@ -279,7 +281,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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 = `
import * as test from "libTest";
@ -287,7 +289,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
@ -302,7 +304,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
return Grower;
}
`;
const lib = new Script("libTest.js", libCode);
const lib = new Script("libTest.js" as ScriptFilePath, libCode);
const code = `
import { createClass } from "libTest";
@ -313,7 +315,7 @@ describe("Parsing NetScript code to work out static RAM costs", function () {
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);
});
});