Skip to content

Commit

Permalink
Merge pull request #138 from benjaminpjones/score-estimator-more-cove…
Browse files Browse the repository at this point in the history
…rage

Add ScoreEstimator tests and raise threshold
  • Loading branch information
anoek authored Nov 12, 2023
2 parents a83af37 + 21a811c commit fa4589e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
"global": {
"lines": 55
"lines": 60
}
},

Expand Down
71 changes: 71 additions & 0 deletions src/__tests__/ScoreEstimator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GoEngine } from "../GoEngine";
import { makeMatrix } from "../GoMath";
import {
ScoreEstimator,
adjust_estimate,
Expand Down Expand Up @@ -323,4 +324,74 @@ describe("ScoreEstimator", () => {
expect(se.getProbablyDead()).toBe("babbcacb");
// expect(se.getProbablyDead()).toBe("cacb");
});

test("Falls back to local scorer if remote scorer is not set", async () => {
set_remote_scorer(undefined as any);
const mock_local_scorer = jest.fn();
mock_local_scorer.mockReturnValue([
[1, 1, -1, -1],
[1, 1, -1, -1],
]);
set_local_scorer(mock_local_scorer);

const se = new ScoreEstimator(undefined, engine, 10, 0.5, true);
await se.when_ready;

expect(mock_local_scorer).toBeCalled();
expect(se.ownership).toEqual([
[1, 0, 0, -1],
[1, 0, 0, -1],
]);
});

test("remote scorers do not need to set score", async () => {
const engine = new GoEngine({ komi: 3.5, width: 4, height: 2, rules: "chinese" });
engine.place(1, 0);
engine.place(2, 0);
engine.place(1, 1);
engine.place(2, 1);

set_remote_scorer(async () => ({
ownership: OWNERSHIP,
}));

const se = new ScoreEstimator(undefined, engine, 10, 0.5, true);
await se.when_ready;

expect(se.ownership).toEqual(OWNERSHIP);
expect(se.winner).toBe("Black");
// I'm not actually sure this is the "right" behavior when the
// remote scorer doesn't return a score. I would think it would
// derive the score from the ownership map. Instead, it assumes
// missing score means zero, and compensates for a komi of 7.5..
// - bpj
expect(se.amount).toBe(4);
});

test("local scorer with stones removed", async () => {
set_local_scorer(estimateScoreVoronoi);
const se = new ScoreEstimator(undefined, engine, 10, 0.5, false);
await se.when_ready;

se.handleClick(1, 0, false);
se.handleClick(2, 0, false);
expect(se.removal).toEqual([
[0, 1, 1, 0],
[0, 1, 1, 0],
]);

expect(se.ownership).toEqual(makeMatrix(4, 2));
});

test("modkey", async () => {
set_local_scorer(estimateScoreVoronoi);
const se = new ScoreEstimator(undefined, engine, 10, 0.5, false);
await se.when_ready;

se.handleClick(1, 0, true);
expect(se.removal).toEqual([
[0, 1, 0, 0],
[0, 0, 0, 0],
]);
});
});

0 comments on commit fa4589e

Please sign in to comment.