Skip to content

Commit e622a4b

Browse files
committed
fix(web): adjusts existing unit tests to match new intermediate-prediction-data format
1 parent ab6912f commit e622a4b

10 files changed

Lines changed: 744 additions & 620 deletions

web/src/test/auto/headless/engine/predictive-text/worker-thread/correction-search/early-correction-search-stopping.tests.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { assert } from 'chai';
22

3-
import { CORRECTION_SEARCH_THRESHOLDS, CorrectionPredictionTuple, ModelCompositor, shouldStopSearchingEarly } from "@keymanapp/lm-worker/test-index";
3+
import { CORRECTION_SEARCH_THRESHOLDS, IntermediateTokenizedPrediction, ModelCompositor, shouldStopSearchingEarly } from "@keymanapp/lm-worker/test-index";
4+
5+
function mockTokenizedPrediction(value: number) {
6+
return {
7+
metadata: {
8+
probabilities: {
9+
total: value
10+
}
11+
}
12+
} as IntermediateTokenizedPrediction
13+
}
414

515
describe('correction-search: shouldStopSearchingEarly', () => {
616
it('stops early once new corrections are less likely than currently discovered predictions', () => {
@@ -12,12 +22,7 @@ describe('correction-search: shouldStopSearchingEarly', () => {
1222
assert.equal(predictionProbs.length, ModelCompositor.MAX_SUGGESTIONS, "test setup no longer valid");
1323

1424
// The only part for each entry we actually care about here: .totalProb.
15-
/** @type {import('#./predict-helpers.js').CorrectionPredictionTuple[]} */
16-
const predictions = predictionProbs.map((entry) => {
17-
return {
18-
totalProb: entry
19-
} as CorrectionPredictionTuple
20-
});
25+
const predictions = predictionProbs.map((entry) => mockTokenizedPrediction(entry));
2126

2227
// Thresholding is performed in log-space.
2328
// 0.0501 and 0.0499 are offset on each side of 0.05, the last value in the array defined above.
@@ -33,8 +38,8 @@ describe('correction-search: shouldStopSearchingEarly', () => {
3338
//
3439
// Can technically run the method with an empty array, but the actual scenario would have
3540
// at least one prediction present in the "found predictions" array.
36-
assert.isFalse(shouldStopSearchingEarly(baseCost, baseCost + expectedThreshold - 0.01, [{ totalProb: Math.exp(-1) } as CorrectionPredictionTuple]));
37-
assert.isTrue(shouldStopSearchingEarly( baseCost, baseCost + expectedThreshold + 0.01, [{ totalProb: Math.exp(-1) } as CorrectionPredictionTuple]));
41+
assert.isFalse(shouldStopSearchingEarly(baseCost, baseCost + expectedThreshold - 0.01, [mockTokenizedPrediction(Math.exp(-1))]));
42+
assert.isTrue(shouldStopSearchingEarly( baseCost, baseCost + expectedThreshold + 0.01, [mockTokenizedPrediction(Math.exp(-1))]));
3843
});
3944

4045
it('stops checking corrections earlier when enough predictions have been found', () => {
@@ -43,11 +48,7 @@ describe('correction-search: shouldStopSearchingEarly', () => {
4348

4449
// The only part for each entry we actually care about here: .totalProb.
4550
/** @type {import('#./predict-helpers.js').CorrectionPredictionTuple[]} */
46-
const predictions = predictionProbs.map((entry) => {
47-
return {
48-
totalProb: entry
49-
} as CorrectionPredictionTuple
50-
});
51+
const predictions = predictionProbs.map((entry) => mockTokenizedPrediction(entry));
5152

5253
const baseCost = 1;
5354

0 commit comments

Comments
 (0)