Skip to content

Commit fbe4bec

Browse files
committed
feat(web): add quotientPathHasInputs tests for SearchQuotientClusters
1 parent 38ccc61 commit fbe4bec

3 files changed

Lines changed: 60 additions & 9 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ export const buildAlphabeticClusterFixtures = () => {
116116

117117
return {
118118
distributions: {
119-
0: {
119+
1: {
120120
distrib_c1_i1d0,
121121
distrib_c1_i2d0
122122
},
123-
1: {
123+
2: {
124124
distrib_v1_i1d0
125125
},
126-
2: {
126+
3: {
127127
distrib_v2_i1d0,
128128
distrib_v2_i1d1,
129129
distrib_v2_i2d1
130130
},
131-
3: {
131+
4: {
132132
distrib_c2_i1d0,
133133
distrib_c2_i2d0
134134
}
@@ -172,7 +172,7 @@ export const buildAlphabeticClusterFixtures = () => {
172172

173173
describe('SearchCluster', () => {
174174
describe('constructor()', () => {
175-
it('initializes from root SearchPath', () => {
175+
it('initializes from LegacySearchRoot', () => {
176176
const path = new LegacyQuotientRoot(testModel);
177177
const cluster = new SearchQuotientCluster([path]);
178178
assert.equal(cluster.inputCount, 0);
@@ -182,7 +182,7 @@ describe('SearchCluster', () => {
182182
assert.deepEqual(cluster.parents, [path]);
183183
});
184184

185-
it('initializes from arbitrary SearchPath', () => {
185+
it('initializes from arbitrary SearchQuotientSpur', () => {
186186
const rootPath = new LegacyQuotientRoot(testModel);
187187

188188
const leadEdgeDistribution: Distribution<Transform> = [
@@ -228,11 +228,11 @@ describe('SearchCluster', () => {
228228
]);
229229
});
230230

231-
it('throws an error when SearchPath array is empty', () => {
231+
it('throws an error when constructor array parameter is empty', () => {
232232
assert.throws(() => new SearchQuotientCluster([]));
233233
});
234234

235-
it('throws an error if SearchPath .inputCount values don\'t match', () => {
235+
it('throws an error if parent .inputCount values don\'t match', () => {
236236
const rootPath = new LegacyQuotientRoot(testModel);
237237

238238
const leadEdgeDistribution: Distribution<Transform> = [

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LegacyQuotientRoot, models, quotientPathHasInputs } from '@keymanapp/lm
66
import { buildSimplePathSplitFixture } from './search-quotient-spur.tests.js';
77

88
import TrieModel = models.TrieModel;
9+
import { buildAlphabeticClusterFixtures } from './search-cluster.tests.js';
910

1011
const testModel = new TrieModel(jsonFixture('models/tries/english-1000'));
1112

@@ -48,5 +49,38 @@ describe('quotientNodeHasParents()', () => {
4849
} while(!isShuffled);
4950
assert.isFalse(quotientPathHasInputs(paths[4], shuffled));
5051
});
52+
53+
it('is able to match inputs against SearchQuotientCluster constituent input paths', () => {
54+
const { distributions, clusters } = buildAlphabeticClusterFixtures();
55+
56+
const fourCharCluster = clusters.cluster_k4c4;
57+
const fiveCharCluster = clusters.cluster_k4c5;
58+
59+
assert.isTrue(quotientPathHasInputs(fourCharCluster, [
60+
distributions[1].distrib_c1_i1d0,
61+
distributions[2].distrib_v1_i1d0,
62+
distributions[3].distrib_v2_i1d0,
63+
distributions[4].distrib_c2_i1d0
64+
]));
65+
assert.isFalse(quotientPathHasInputs(fiveCharCluster,[
66+
distributions[1].distrib_c1_i1d0,
67+
distributions[2].distrib_v1_i1d0,
68+
distributions[3].distrib_v2_i1d0,
69+
distributions[4].distrib_c2_i1d0
70+
]));
71+
72+
assert.isFalse(quotientPathHasInputs(fourCharCluster, [
73+
distributions[1].distrib_c1_i1d0,
74+
distributions[2].distrib_v1_i1d0,
75+
distributions[3].distrib_v2_i1d0,
76+
distributions[4].distrib_c2_i2d0
77+
]));
78+
assert.isTrue(quotientPathHasInputs(fiveCharCluster, [
79+
distributions[1].distrib_c1_i1d0,
80+
distributions[2].distrib_v1_i1d0,
81+
distributions[3].distrib_v2_i1d0,
82+
distributions[4].distrib_c2_i2d0
83+
]));
84+
});
5185
});
5286

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { KMWString } from '@keymanapp/web-utils';
1414
import { jsonFixture } from '@keymanapp/common-test-resources/model-helpers.mjs';
1515
import { generateSubsetId, LegacyQuotientSpur, models, LegacyQuotientRoot, quotientPathHasInputs, SearchQuotientNode, PathInputProperties, SearchQuotientSpur } from '@keymanapp/lm-worker/test-index';
1616

17+
import { buildAlphabeticClusterFixtures } from './search-cluster.tests.js';
18+
1719
import Distribution = LexicalModelTypes.Distribution;
1820
import Transform = LexicalModelTypes.Transform;
1921
import TrieModel = models.TrieModel;
@@ -291,7 +293,22 @@ describe('SearchQuotientSpur', () => {
291293
assert.sameOrderedMembers(pathSequence, paths.slice(1));
292294
});
293295

294-
// TODO: add a test for mixed SearchQuotientSpur / SearchCluster cases.
296+
it('properly enumerates child paths when encountering SearchCluster ancestors', () => {
297+
const fixture = buildAlphabeticClusterFixtures();
298+
const finalPath = fixture.paths[4].path_k4c6;
299+
300+
// The longest SearchPath at the end of that fixture's set is based on a
301+
// lead-in cluster; all variants of that should be included.
302+
assert.equal(finalPath.constituentPaths.length, fixture.clusters.cluster_k3c4.constituentPaths.length);
303+
304+
// That cluster holds the different potential penultimate paths;
305+
// finalPath's inputs are added directly after any variation that may be
306+
// output from the cluster.
307+
assert.sameDeepMembers(finalPath.constituentPaths, fixture.clusters.cluster_k3c4.constituentPaths.map((p) => {
308+
p.push(finalPath);
309+
return p;
310+
}));
311+
});
295312
});
296313

297314
describe('split()', () => {

0 commit comments

Comments
 (0)