public void testFullMatchList() throws Exception {
   assertMatchEquals(
       completion.lookup(stringToCharSequence("one"), Integer.MAX_VALUE),
       "oneness/1.0",
       "onerous/1.0",
       "onesimus/1.0",
       "one/0.0");
 }
 public void testExactMatchReordering() throws Exception {
   // Check reordering of exact matches.
   assertMatchEquals(
       completion.lookup(stringToCharSequence("four"), 4),
       "four/0.0",
       "fourblah/1.0",
       "fourteen/1.0",
       "fourier/0.0");
 }
  @Override
  public List<LookupResult> lookup(CharSequence key, boolean higherWeightsFirst, int num) {
    final List<Completion> completions;
    if (higherWeightsFirst) {
      completions = higherWeightsCompletion.lookup(key, num);
    } else {
      completions = normalCompletion.lookup(key, num);
    }

    final ArrayList<LookupResult> results = new ArrayList<LookupResult>(completions.size());
    CharsRef spare = new CharsRef();
    for (Completion c : completions) {
      spare.grow(c.utf8.length);
      UnicodeUtil.UTF8toUTF16(c.utf8, spare);
      results.add(new LookupResult(spare.toString(), c.bucket));
    }
    return results;
  }
  public void testThreeByte() throws Exception {
    String key =
        new String(new byte[] {(byte) 0xF0, (byte) 0xA4, (byte) 0xAD, (byte) 0xA2}, "UTF-8");
    FSTCompletionBuilder builder = new FSTCompletionBuilder();
    builder.add(new BytesRef(key), 0);

    FSTCompletion lookup = builder.build();
    List<Completion> result = lookup.lookup(stringToCharSequence(key), 1);
    assertEquals(1, result.size());
  }
  public void testRequestedCount() throws Exception {
    // 'one' is promoted after collecting two higher ranking results.
    assertMatchEquals(completion.lookup(stringToCharSequence("one"), 2), "one/0.0", "oneness/1.0");

    // 'four' is collected in a bucket and then again as an exact match.
    assertMatchEquals(
        completion.lookup(stringToCharSequence("four"), 2), "four/0.0", "fourblah/1.0");

    // Check reordering of exact matches.
    assertMatchEquals(
        completion.lookup(stringToCharSequence("four"), 4),
        "four/0.0",
        "fourblah/1.0",
        "fourteen/1.0",
        "fourier/0.0");

    // 'one' is at the top after collecting all alphabetical results.
    assertMatchEquals(
        completionAlphabetical.lookup(stringToCharSequence("one"), 2), "one/0.0", "oneness/1.0");

    // 'one' is not promoted after collecting two higher ranking results.
    FSTCompletion noPromotion = new FSTCompletion(completion.getFST(), true, false);
    assertMatchEquals(
        noPromotion.lookup(stringToCharSequence("one"), 2), "oneness/1.0", "onerous/1.0");

    // 'one' is at the top after collecting all alphabetical results.
    assertMatchEquals(
        completionAlphabetical.lookup(stringToCharSequence("one"), 2), "one/0.0", "oneness/1.0");
  }
 public void testExactMatchLowPriority() throws Exception {
   assertMatchEquals(completion.lookup(stringToCharSequence("one"), 2), "one/0.0", "oneness/1.0");
 }
 public void testExactMatchHighPriority() throws Exception {
   assertMatchEquals(completion.lookup(stringToCharSequence("two"), 1), "two/1.0");
 }
 public void testEmptyInput() throws Exception {
   completion = new FSTCompletionBuilder().build();
   assertMatchEquals(completion.lookup(stringToCharSequence(""), 10));
 }
 public void testAlphabeticWithWeights() throws Exception {
   assertEquals(0, completionAlphabetical.lookup(stringToCharSequence("xyz"), 1).size());
 }
 public void testMiss() throws Exception {
   assertMatchEquals(completion.lookup(stringToCharSequence("xyz"), 1));
 }