11import { 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
515describe ( '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