change(web): enhance SearchQuotientSpur unit tests

This commit is contained in:
Joshua Horton 2025-11-10 13:34:00 -06:00
parent a625596f4d
commit 58ad8c247b

View file

@ -76,6 +76,13 @@ describe('SearchQuotientSpur', () => {
assert.deepEqual(extendedPath.bestExample, {text: 't', p: 0.5});
assert.deepEqual(extendedPath.parents, [rootPath]);
assert.deepEqual(extendedPath.inputs, leadEdgeDistribution);
assert.deepEqual(extendedPath.sourceIdentifiers, [
{
trueTransform: leadEdgeDistribution[0].sample,
inputStartIndex: 0,
bestProbFromSet: leadEdgeDistribution[0].p
}
]);
// Assert the root is unchanged.
assert.equal(rootPath.inputCount, 0);
@ -121,6 +128,17 @@ describe('SearchQuotientSpur', () => {
assert.deepEqual(length2Path.bestExample, {text: 'tr', p: leadEdgeDistribution[0].p * tailEdgeDistribution[0].p});
assert.deepEqual(length2Path.parents, [length1Path]);
assert.deepEqual(length2Path.inputs, tailEdgeDistribution);
assert.deepEqual(length2Path.sourceIdentifiers, [
{
trueTransform: leadEdgeDistribution[0].sample,
inputStartIndex: 0,
bestProbFromSet: leadEdgeDistribution[0].p
}, {
trueTransform: tailEdgeDistribution[0].sample,
inputStartIndex: 0,
bestProbFromSet: tailEdgeDistribution[0].p
}
]);
assert.equal(length1Path.inputCount, 1);
assert.isNumber(length1Path.spaceId);
@ -130,6 +148,21 @@ describe('SearchQuotientSpur', () => {
assert.deepEqual(length1Path.inputs, leadEdgeDistribution);
});
it('throws if input and input-source transition IDs mismatch', () => {
const rootPath = new LegacyQuotientRoot(testModel);
const leadEdgeDistribution = [
{sample: {insert: 't', deleteLeft: 0, id: 13 }, p: 0.5},
{sample: {insert: 'a', deleteLeft: 0, id: 13 }, p: 0.3},
{sample: {insert: 'o', deleteLeft: 0, id: 13 }, p: 0.2}
];
assert.throws(() => new LegacyQuotientSpur(rootPath, leadEdgeDistribution, {
...leadEdgeDistribution[0],
sample: {...leadEdgeDistribution[0].sample, id: 15}
}));
});
it('may extend with a Transform inserting multiple codepoints', () => {
const rootPath = new LegacyQuotientRoot(testModel);
@ -167,6 +200,17 @@ describe('SearchQuotientSpur', () => {
assert.deepEqual(length2Path.bestExample, {text: 'tri', p: leadEdgeDistribution[0].p * tailEdgeDistribution[0].p});
assert.deepEqual(length2Path.parents, [length1Path]);
assert.deepEqual(length2Path.inputs, tailEdgeDistribution);
assert.deepEqual(length2Path.sourceIdentifiers, [
{
trueTransform: leadEdgeDistribution[0].sample,
inputStartIndex: 0,
bestProbFromSet: leadEdgeDistribution[0].p
}, {
trueTransform: tailEdgeDistribution[0].sample,
inputStartIndex: 0,
bestProbFromSet: tailEdgeDistribution[0].p
}
]);
assert.equal(length1Path.inputCount, 1);
assert.isNumber(length1Path.spaceId);