/*
 * Unit tests for the Dummy prediction model.
 */

var assert = require('chai').assert;

var WordListModel = require('../../build/intermediate').models.WordListModel;

describe('LMLayerWorker word list model', function() {
  describe('instantiation', function () {
    it('can be instantiated with an empty word list', function () {
      var model = new WordListModel(defaultCapabilities(), []);
      assert.isObject(model);
    });

    it('can be instantiated with an word list', function () {
    });
  });

  describe('prediction', function () {
    var MIN_SUGGESTIONS = 3;

    it('should predict prefixes with an empty context and a single letter transform', function () {
      // Predicting when the user JUST typed 't' should result in something like this:
      //
      //   «t|                        » [Send]
      //   [   to   ] [   the   ] [   this    ]
      var model = new WordListModel(
        defaultCapabilities(),
        jsonFixture('wordlists/english-1000')
      );

      var suggestions = model.predict({
        insert: 't',
        deleteLeft: 0,
      }, emptyContext());
      assert.isAtLeast(suggestions.length, MIN_SUGGESTIONS);

      // Ensure all of the suggestions actually start with 't'
      var suggestion;
      var suggestedWord;
      for (var i = 0; i < MIN_SUGGESTIONS; i++) {
        suggestion = suggestions[i];
        suggestedWord = suggestion.transform.insert;
        assert.strictEqual(suggestedWord.substr(0, 1), 't');
      }
    });

    it('should predict prefixes within an word and a single letter transform', function () {
      // Predicting when the user JUST typed 'h', with the buffer having a 't' in it:
      //
      //   «th|                       » [Send]
      //   [  this  ] [   the   ] [   there   ]
      var model = new WordListModel(
        defaultCapabilities(),
        jsonFixture('wordlists/english-1000')
      );

      var initialPrefix = 't';
      var insertedLetter = 'h';
      var truePrefix = initialPrefix + insertedLetter;
      var suggestions = model.predict({
        insert: insertedLetter,
        deleteLeft: 0,
      }, {
        left: initialPrefix,
        startOfBuffer: false,
        endOfBuffer: true
      });
      assert.isAtLeast(suggestions.length, MIN_SUGGESTIONS);

      // Ensure all of the suggestions actually start with 'th'
      var suggestion;
      var suggestedWord;

      // XXX: this tests knows TOO MUCH about the implementation of the function.
      // Need a test that asserts behavior; not how it got there.
      for (var i = 0; i < MIN_SUGGESTIONS; i++) {
        suggestion = suggestions[i];
        suggestedWord = suggestion.displayAs;
        // Assuming the transform where nothing is deleted, but
        // the rest of the suggested word is inserted.
        assert.strictEqual(suggestion.transform.deleteLeft, 0);
        // The first two characters should match the prefix WITH the transform.
        assert.strictEqual(suggestedWord.substr(0, truePrefix.length), truePrefix);
        assert.strictEqual(suggestion.transform.insert[0], insertedLetter);
      }
    });

    // TODO: predict empty buffer, empty transform
  });
});


@@ -3122,62 +3122,879 @@
     
-// TODO: predict empty buffer, empty transform%0A
+it('should produce suggestions with an empty buffer and a zero transform', function () %7B%0A      // Predicting when the user has activated an empty text field:%0A      //%0A      //   %C2%AB%7C                         %C2%BB %5BSend%5D%0A      //   %5B   I'm  %5D %5B    I    %5D %5B    Hey    %5D%0A      var model = new WordListModel(%0A        defaultCapabilities(),%0A        jsonFixture('wordlists/english-1000')%0A      );%0A%0A      var suggestions = model.predict(zeroTransform(), emptyContext());%0A      assert.isAtLeast(suggestions.length, MIN_SUGGESTIONS);%0A%0A      // Ensure all of the suggestions seem valid.%0A      var suggestion;%0A      for (var i = 0; i %3C MIN_SUGGESTIONS; i++) %7B%0A        suggestion = suggestions%5Bi%5D;%0A        assert.isNotEmpty(suggestion.transform.insert);%0A        assert.strictEqual(suggestion.transform.deleteLeft, 0);%0A        assert.isNotEmpty(suggestion.displayAs);%0A      %7D%0A  
   %7D);%0A
+  
 %7D);%0A
+%7D);
 %0A

Test for predicting in an empty buffer.