mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
JEST: Add tests for checking getAnswer and solver of coding contracts (#2503)
This commit is contained in:
@@ -17,6 +17,8 @@ import { CodingContractRewardType } from "../../../src/CodingContract/Contract";
|
||||
import { joinFaction } from "../../../src/Faction/FactionHelpers";
|
||||
import { Factions } from "../../../src/Faction/Factions";
|
||||
import { Companies } from "../../../src/Company/Companies";
|
||||
import { CodingContractTypes } from "../../../src/CodingContract/ContractTypes";
|
||||
import { getRecordEntries } from "../../../src/Types/Record";
|
||||
|
||||
beforeAll(() => {
|
||||
initGameEnvironment();
|
||||
@@ -201,3 +203,22 @@ describe("Receive fallback reward", () => {
|
||||
expect(Factions.CyberSec.playerReputation).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Check getAnswer and solver", () => {
|
||||
// These contracts do not give a way to generate the answer.
|
||||
const skippedContractTypes = [
|
||||
CodingContractName.Proper2ColoringOfAGraph,
|
||||
CodingContractName.ShortestPathInAGrid,
|
||||
CodingContractName.SquareRoot,
|
||||
];
|
||||
for (const [name, cct] of getRecordEntries(CodingContractTypes)) {
|
||||
if (skippedContractTypes.includes(name)) {
|
||||
continue;
|
||||
}
|
||||
const state = cct.generate();
|
||||
const data = cct.getData ? cct.getData(state) : state;
|
||||
const answer = cct.getAnswer(data);
|
||||
expect(answer).not.toBeNull();
|
||||
expect(cct.solver(state, answer)).toStrictEqual(true);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user