mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
REFACTOR: Make getPlayer 10x faster (#2548)
This commit is contained in:
37
test/jest/Netscript/GetPlayer.test.ts
Normal file
37
test/jest/Netscript/GetPlayer.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Bench } from "tinybench";
|
||||
import { initGameEnvironment, setupBasicTestingEnvironment, getWorkerScriptAndNS } from "../Utilities";
|
||||
import { Player } from "@player";
|
||||
|
||||
initGameEnvironment();
|
||||
|
||||
beforeEach(() => {
|
||||
setupBasicTestingEnvironment();
|
||||
});
|
||||
|
||||
test("getPlayer", () => {
|
||||
const { ns } = getWorkerScriptAndNS();
|
||||
const props = [
|
||||
"hp",
|
||||
"skills",
|
||||
"exp",
|
||||
"mults",
|
||||
"city",
|
||||
"numPeopleKilled",
|
||||
"money",
|
||||
"location",
|
||||
"totalPlaytime",
|
||||
"jobs",
|
||||
"factions",
|
||||
"entropy",
|
||||
"karma",
|
||||
] as const;
|
||||
const expected = Object.fromEntries(props.map((k) => [k, Player[k]]));
|
||||
expect(ns.getPlayer()).toEqual(expected);
|
||||
});
|
||||
// Benchmarks shouldn't waste time on every test run. Un-skip this when evaluating changes.
|
||||
test.skip("Benchmark getPlayer", async () => {
|
||||
const { ns } = getWorkerScriptAndNS();
|
||||
const bench = new Bench().add("getPlayer", () => ns.getPlayer());
|
||||
await bench.run();
|
||||
console.table(bench.table());
|
||||
});
|
||||
Reference in New Issue
Block a user