Implement ChessUp server, vanilla TS UI, Stockfish analytics, and Docker/Cloudflared setup
This commit is contained in:
commit
e2e085b341
52 changed files with 15730 additions and 0 deletions
87
tests/winProb.test.ts
Normal file
87
tests/winProb.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
classifyMove,
|
||||
computeMoveAccuracy,
|
||||
computePlayerSummary,
|
||||
cpToWinPercent,
|
||||
formatEvalShort
|
||||
} from '../src/shared/winProb';
|
||||
import type { PlyAnalysis } from '../src/shared/types';
|
||||
|
||||
test('cpToWinPercent symmetry and mate bounds', () => {
|
||||
assert.equal(cpToWinPercent(0, null), 50);
|
||||
assert.equal(cpToWinPercent(null, 3), 100);
|
||||
assert.equal(cpToWinPercent(null, -2), 0);
|
||||
|
||||
const pos = cpToWinPercent(250, null);
|
||||
const neg = cpToWinPercent(-250, null);
|
||||
assert.ok(pos > 65 && pos < 80);
|
||||
assert.ok(Math.abs(pos + neg - 100) < 1e-6);
|
||||
});
|
||||
|
||||
test('classifyMove thresholds and accuracy', () => {
|
||||
assert.equal(classifyMove(60, 60, true), 'best');
|
||||
assert.equal(classifyMove(60, 59, false), 'best');
|
||||
assert.equal(classifyMove(60, 55, false), 'good');
|
||||
assert.equal(classifyMove(60, 49, false), 'inaccuracy');
|
||||
assert.equal(classifyMove(60, 39, false), 'mistake');
|
||||
assert.equal(classifyMove(60, 29, false), 'blunder');
|
||||
|
||||
assert.equal(computeMoveAccuracy(0), 100);
|
||||
assert.ok(computeMoveAccuracy(35) < 25);
|
||||
});
|
||||
|
||||
test('computePlayerSummary calculates ACPL and counts accurately', () => {
|
||||
const plies: PlyAnalysis[] = [
|
||||
{
|
||||
ply: 1,
|
||||
moveUci: 'e2e4',
|
||||
moveSan: 'e4',
|
||||
color: 'w',
|
||||
evalCpBefore: 20,
|
||||
evalMateBefore: null,
|
||||
evalCpAfter: 20,
|
||||
evalMateAfter: null,
|
||||
winPercentBefore: 51,
|
||||
winPercentAfter: 51,
|
||||
winDrop: 0,
|
||||
accuracy: 100,
|
||||
bestMoveUci: 'e2e4',
|
||||
bestMoveSan: 'e4',
|
||||
pvUci: ['e2e4'],
|
||||
pvSan: ['e4'],
|
||||
classification: 'best'
|
||||
},
|
||||
{
|
||||
ply: 2,
|
||||
moveUci: 'g7g5',
|
||||
moveSan: 'g5',
|
||||
color: 'b',
|
||||
evalCpBefore: 20,
|
||||
evalMateBefore: null,
|
||||
evalCpAfter: 320,
|
||||
evalMateAfter: null,
|
||||
winPercentBefore: 51,
|
||||
winPercentAfter: 76,
|
||||
winDrop: 25,
|
||||
accuracy: 31.6,
|
||||
bestMoveUci: 'e7e5',
|
||||
bestMoveSan: 'e5',
|
||||
pvUci: ['e7e5'],
|
||||
pvSan: ['e5'],
|
||||
classification: 'mistake'
|
||||
}
|
||||
];
|
||||
|
||||
const wSum = computePlayerSummary(plies, 'w');
|
||||
assert.equal(wSum.accuracy, 100);
|
||||
assert.equal(wSum.acpl, 0);
|
||||
assert.equal(wSum.best, 1);
|
||||
|
||||
const bSum = computePlayerSummary(plies, 'b');
|
||||
assert.equal(bSum.acpl, 300);
|
||||
assert.equal(bSum.mistakes, 1);
|
||||
assert.equal(formatEvalShort(145, null), '+1.5');
|
||||
assert.equal(formatEvalShort(null, -4), '-M4');
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue