// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static final Random RANDOM = new Random(0);
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<Integer> generateRandomInts(final int numOfElements) {
//     final List<Integer> ret = newArrayList();
//     for(int i = 0; i < numOfElements; i++) {
//         ret.add(RANDOM.nextInt(1000));
//     }
//     return ret;
// }
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<Long> generateRandomLongs(final int numOfElements) {
//     final List<Long> ret = newArrayList();
//     for(int i = 0; i < numOfElements; i++) {
//         final long val = RANDOM.nextInt(10000);
//         ret.add(val);
//     }
//     return ret;
// }
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<String> generateRandomWords(final int numberOfWords) {
//     final String[] randomStrings = new String[numberOfWords];
//     for(int i = 0; i < numberOfWords; i++)
//     {
//         final char[] word = new char[RANDOM.nextInt(8) + 3]; // words of length 3 through 10. (1 and 2 letter words are boring.)
//         for(int j = 0; j < word.length; j++)
//         {
//             word[j] = (char) ('a' + RANDOM.nextInt(26));
//         }
//         randomStrings[i] = new String(word);
//     }
//     return newArrayList(randomStrings);
// }


import static com.google.common.collect.Lists.newArrayList;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.RANDOM;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomInts;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomLongs;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomWords;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.node.Node;
import org.elasticsearch.search.facet.FacetBuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

        int rIndex1 = RANDOM.nextInt(numOfWords);
        int rIndex2 = RANDOM.nextInt(numOfWords);
        for(int i = 0; i < numOfElements; i++) {
            putSync(newID(), words.get(rIndex1), words.get(rIndex2), 0, 0);
            rIndex1++;
            rIndex1 %= numOfWords;

            rIndex2++;
            rIndex2 %= numOfWords;
        }

        final Set<String> uniqs = new HashSet<String>(words);

        assertEquals(numOfElements, countAll());
        final SearchResponse response1 = getTermList(__txtField1, numOfElements, 1, mode);
        final SearchResponse response2 = getTermList(__txtField2, numOfElements, 1, mode);

        checkStringSearchResponse(response1, numOfElements, uniqs.size(), words);
        checkStringSearchResponse(response2, numOfElements, uniqs.size(), words);
    }

    private void testInts(final String mode) throws Exception {

        final int testLength = 7;
        final int maxPerShard = 3;
        final List<Integer> numList = generateRandomInts(testLength);
        for(int i = 0; i < numList.size(); i++) {
            putSync(newID(), "", "", numList.get(i), 0);
        }
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static final Random RANDOM = new Random(0);
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<Integer> generateRandomInts(final int numOfElements) {
//     final List<Integer> ret = newArrayList();
//     for(int i = 0; i < numOfElements; i++) {
//         ret.add(RANDOM.nextInt(1000));
//     }
//     return ret;
// }
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<Long> generateRandomLongs(final int numOfElements) {
//     final List<Long> ret = newArrayList();
//     for(int i = 0; i < numOfElements; i++) {
//         final long val = RANDOM.nextInt(10000);
//         ret.add(val);
//     }
//     return ret;
// }
// 
// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TestUtils.java
// public static List<String> generateRandomWords(final int numberOfWords) {
//     final String[] randomStrings = new String[numberOfWords];
//     for(int i = 0; i < numberOfWords; i++)
//     {
//         final char[] word = new char[RANDOM.nextInt(8) + 3]; // words of length 3 through 10. (1 and 2 letter words are boring.)
//         for(int j = 0; j < word.length; j++)
//         {
//             word[j] = (char) ('a' + RANDOM.nextInt(26));
//         }
//         randomStrings[i] = new String(word);
//     }
//     return newArrayList(randomStrings);
// }


// Path: src/test/java/com/pearson/entech/elasticsearch/search/facet/approx/termlist/TermListFacetTest.java
import static com.google.common.collect.Lists.newArrayList;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.RANDOM;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomInts;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomLongs;
import static com.pearson.entech.elasticsearch.search.facet.approx.termlist.TestUtils.generateRandomWords;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.node.Node;
import org.elasticsearch.search.facet.FacetBuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


        int rIndex1 = RANDOM.nextInt(numOfWords);
        int rIndex2 = RANDOM.nextInt(numOfWords);
        for(int i = 0; i < numOfElements; i++) {
            putSync(newID(), words.get(rIndex1), words.get(rIndex2), 0, 0);
            rIndex1++;
            rIndex1 %= numOfWords;

            rIndex2++;
            rIndex2 %= numOfWords;
        }

        final Set<String> uniqs = new HashSet<String>(words);

        assertEquals(numOfElements, countAll());
        final SearchResponse response1 = getTermList(__txtField1, numOfElements, 1, mode);
        final SearchResponse response2 = getTermList(__txtField2, numOfElements, 1, mode);

        checkStringSearchResponse(response1, numOfElements, uniqs.size(), words);
        checkStringSearchResponse(response2, numOfElements, uniqs.size(), words);
    }

    private void testInts(final String mode) throws Exception {

        final int testLength = 7;
        final int maxPerShard = 3;
        final List<Integer> numList = generateRandomInts(testLength);
        for(int i = 0; i < numList.size(); i++) {
            putSync(newID(), "", "", numList.get(i), 0);
        }
        final SearchResponse response1 = getTermList(__intField1, maxPerShard, 1, mode);