@@ -0,0 +1,2963 @@
+package org.apache.lucene.search.suggest;%0A%0A/**%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements. See the NOTICE file distributed with this%0A * work for additional information regarding copyright ownership. The ASF%0A * licenses this file to You under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A * http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A * License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Aimport java.util.Iterator;%0Aimport java.util.Map;%0Aimport java.util.TreeMap;%0A%0Aimport org.apache.lucene.search.spell.TermFreqIterator;%0Aimport org.apache.lucene.util.BytesRef;%0Aimport org.apache.lucene.util.LuceneTestCase;%0Aimport org.apache.lucene.util._TestUtil;%0A%0Apublic class TestTermFreqIterator extends LuceneTestCase %7B%0A  public void testEmpty() throws Exception %7B%0A    TermFreqArrayIterator iterator = new TermFreqArrayIterator(new TermFreq%5B0%5D);%0A    TermFreqIterator wrapper = new SortedTermFreqIteratorWrapper(iterator, BytesRef.getUTF8SortedAsUnicodeComparator());%0A    assertNull(wrapper.next());%0A    wrapper = new UnsortedTermFreqIteratorWrapper(iterator);%0A    assertNull(wrapper.next());%0A  %7D%0A  %0A  public void testTerms() throws Exception %7B%0A    int num = atLeast(10000);%0A    %0A    TreeMap%3CBytesRef,Float%3E sorted = new TreeMap%3CBytesRef,Float%3E();%0A    TermFreq%5B%5D unsorted = new TermFreq%5Bnum%5D;%0A%0A    for (int i = 0; i %3C num; i++) %7B%0A      BytesRef key;%0A      do %7B%0A        key = new BytesRef(_TestUtil.randomUnicodeString(random));%0A      %7D while (sorted.containsKey(key));%0A      float value = random.nextFloat();%0A      sorted.put(key, value);%0A      unsorted%5Bi%5D = new TermFreq(key, value);%0A    %7D%0A    %0A    // test the sorted iterator wrapper%0A    TermFreqIterator wrapper = new SortedTermFreqIteratorWrapper(new TermFreqArrayIterator(unsorted), BytesRef.getUTF8SortedAsUnicodeComparator());%0A    Iterator%3CMap.Entry%3CBytesRef,Float%3E%3E expected = sorted.entrySet().iterator();%0A    while (expected.hasNext()) %7B%0A      Map.Entry%3CBytesRef,Float%3E entry = expected.next();%0A      %0A      assertEquals(entry.getKey(), wrapper.next());%0A      assertEquals(entry.getValue().floatValue(), wrapper.freq(), 0F);%0A    %7D%0A    assertNull(wrapper.next());%0A    %0A    // test the unsorted iterator wrapper%0A    wrapper = new UnsortedTermFreqIteratorWrapper(new TermFreqArrayIterator(unsorted));%0A    TreeMap%3CBytesRef,Float%3E actual = new TreeMap%3CBytesRef,Float%3E();%0A    BytesRef key;%0A    while ((key = wrapper.next()) != null) %7B%0A      float value = wrapper.freq();%0A      actual.put(BytesRef.deepCopyOf(key), value);%0A    %7D%0A    assertEquals(sorted, actual);%0A  %7D%0A%7D%0A

add test for suggester iterators