mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-11 03:15:33 +00:00
109 lines
3.1 KiB
JavaScript
109 lines
3.1 KiB
JavaScript
/*
|
|
* Unit tests for the Dummy prediction model.
|
|
*/
|
|
|
|
var assert = require('chai').assert;
|
|
|
|
var DummyModel = require('../../build/intermediate').models.DummyModel;
|
|
|
|
describe('LMLayerWorker dummy model', function() {
|
|
describe('instantiation', function () {
|
|
it('can be instantiated with capabilities', function () {
|
|
var model = new DummyModel(defaultCapabilities);
|
|
assert.isObject(model);
|
|
});
|
|
|
|
it('supports dependency-injected configuration', function () {
|
|
let configuration = {
|
|
leftContextCodeUnits: 64,
|
|
rightContextCodeUnits: 0
|
|
};
|
|
|
|
var model = new DummyModel({
|
|
maxLeftContextCodeUnits: 64,
|
|
},
|
|
{
|
|
configuration: configuration,
|
|
});
|
|
|
|
assert.deepEqual(model.configuration, configuration);
|
|
});
|
|
});
|
|
|
|
describe('prediction', function () {
|
|
it('can predict send back an array of injected suggestions', function (){
|
|
// We're pretending to be in this situation:
|
|
//
|
|
// «I'm a little t| » [Send]
|
|
// [ too ] [ 🍵 ] [ 😪 ]
|
|
//
|
|
// Pressing the top suggestion (middle, highlighted)
|
|
// will modified the buffer to:
|
|
//
|
|
// «I'm a little teapot| » [Send]
|
|
|
|
var expectedSuggestions = [
|
|
{
|
|
transform: {
|
|
insert: 'teapot',
|
|
deleteLeft: 0,
|
|
},
|
|
displayAs: '🍵',
|
|
},
|
|
{
|
|
transform: {
|
|
insert: 'too',
|
|
deleteLeft: 0,
|
|
},
|
|
displayAs: 'too',
|
|
},
|
|
{
|
|
transform: {
|
|
insert: 'tired',
|
|
deleteLeft: 0,
|
|
},
|
|
displayAs: '😪',
|
|
},
|
|
];
|
|
|
|
var model = new DummyModel(defaultCapabilities());
|
|
|
|
// Type a 't'
|
|
var suggestions = model.predict({
|
|
insert: 't',
|
|
deleteLeft: 0,
|
|
},
|
|
{
|
|
left: "I'm a little ",
|
|
startOfBuffer: true,
|
|
endOfBuffer: true,
|
|
}, expectedSuggestions);
|
|
assert.deepEqual(suggestions, expectedSuggestions);
|
|
});
|
|
|
|
it('can be injected with multiple suggestions to send back', function () {
|
|
// See the fixture. It's based on suggestions produced my phone's personal
|
|
// language model.
|
|
var futureSuggestions = iGotDistractedByHazel();
|
|
assert.isDefined(futureSuggestions[0]);
|
|
assert.isDefined(futureSuggestions[1]);
|
|
assert.isDefined(futureSuggestions[2]);
|
|
assert.isDefined(futureSuggestions[3]);
|
|
|
|
var model = new DummyModel(defaultCapabilities, {
|
|
futureSuggestions: futureSuggestions
|
|
});
|
|
|
|
// The dummy model should give suggestions in order,
|
|
// regardless of the provided transform and context.
|
|
assert.deepEqual(model.predict(zeroTransform(), emptyContext()),
|
|
futureSuggestions[0]);
|
|
assert.deepEqual(model.predict(zeroTransform(), emptyContext()),
|
|
futureSuggestions[1]);
|
|
assert.deepEqual(model.predict(zeroTransform(), emptyContext()),
|
|
futureSuggestions[2]);
|
|
assert.deepEqual(model.predict(zeroTransform(), emptyContext()),
|
|
futureSuggestions[3]);
|
|
});
|
|
});
|
|
});
|