// Path: src/main/java/org/apache/solr/request/BidirectionalFacetResponseBuilder.java
// public static abstract class Env<T extends FieldType & FacetPayload, K extends FacetKey<K>> {
//   public final int offset;
//   public final int limit;
//   public final int targetIdx;
//   public final int mincount;
//   public final String fieldName;
//   public final T ft;
//   public final String ftDelim;
//   public final NamedList res;
// 
//   public Env(int offset, int limit, int targetIdx, int mincount, String fieldName, T ft, NamedList res) {
//     this.offset = offset;
//     this.limit = limit;
//     this.targetIdx = targetIdx;
//     this.mincount = mincount;
//     this.fieldName = fieldName;
//     this.ft = ft;
//     if (ft instanceof MultiSerializable) {
//       ftDelim = ((MultiSerializable)ft).getDelim();
//     } else {
//       ftDelim = "\u0000";
//     }
//     this.res = res;
//   }
//     
//   public abstract K incrementKey(K previousKey);
//     
//   public abstract K decrementKey(K previousKey);
//     
//   public abstract void addEntry(LimitMinder<T, K> limitMinder, K facetKey, Deque<Entry<String, Object>> entryBuilder) throws IOException;
//     
//   public abstract K targetKey() throws IOException;
// 
//   public abstract K targetKeyInit(boolean ascending) throws IOException;
// 
//   public abstract void initState(K key);
// 
//   public NamedList<Object> finalize(NamedList<Object> ret) {
//     return ret;
//   }
// 
// }
// 
// Path: src/main/java/org/apache/solr/request/BidirectionalFacetResponseBuilder.java
// public static class SimpleTermIndexKey extends BaseTermIndexKey<SimpleTermIndexKey> {
// 
//   public SimpleTermIndexKey(int index) {
//     super(index);
//   }
// 
// }


import java.io.IOException;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Deque;
import java.util.Map;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.BidirectionalFacetResponseBuilder.Env;
import org.apache.solr.request.BidirectionalFacetResponseBuilder.SimpleTermIndexKey;
import org.apache.solr.schema.FieldType;
import org.junit.Test;
import static org.junit.Assert.*;
    runTest(1, 3, -1, 1, 2);
  }
  
  @Test
  public void testLargeNegativeOffsetWindowOOB() throws IOException {
    runTest(1, 1, -2, -1, 2);
  }
  
  @Test
  public void testPositiveOffsetWindowOOB() throws IOException {
    runTest(1, 0, 1, 0, 0);
  }
  
  @Test
  public void testLargePositiveOffsetWindowOOB() throws IOException {
    runTest(1, 0, 2, 0, 0);
    runTest(1, 1, 2, 1, 0);
  }
  
  private void runTest(int limit, int targetIdx, int requestedOffset, Integer expectedOffset, int... expectedIndices) throws IOException {
    runTest(counts, limit, targetIdx, requestedOffset, expectedOffset, expectedIndices);
  }

  private void runTest(int[] counts, int limit, int targetIdx, int requestedOffset, Integer expectedOffset, int... expectedIndices) throws IOException {
    String targetDoc = null;
    int mincount = 1;
    String fieldName = "myField";
    T ft = null;
    NamedList exp = buildExpected(expectedOffset, expectedIndices);
    NamedList actual = new NamedList(3);
// Path: src/main/java/org/apache/solr/request/BidirectionalFacetResponseBuilder.java
// public static abstract class Env<T extends FieldType & FacetPayload, K extends FacetKey<K>> {
//   public final int offset;
//   public final int limit;
//   public final int targetIdx;
//   public final int mincount;
//   public final String fieldName;
//   public final T ft;
//   public final String ftDelim;
//   public final NamedList res;
// 
//   public Env(int offset, int limit, int targetIdx, int mincount, String fieldName, T ft, NamedList res) {
//     this.offset = offset;
//     this.limit = limit;
//     this.targetIdx = targetIdx;
//     this.mincount = mincount;
//     this.fieldName = fieldName;
//     this.ft = ft;
//     if (ft instanceof MultiSerializable) {
//       ftDelim = ((MultiSerializable)ft).getDelim();
//     } else {
//       ftDelim = "\u0000";
//     }
//     this.res = res;
//   }
//     
//   public abstract K incrementKey(K previousKey);
//     
//   public abstract K decrementKey(K previousKey);
//     
//   public abstract void addEntry(LimitMinder<T, K> limitMinder, K facetKey, Deque<Entry<String, Object>> entryBuilder) throws IOException;
//     
//   public abstract K targetKey() throws IOException;
// 
//   public abstract K targetKeyInit(boolean ascending) throws IOException;
// 
//   public abstract void initState(K key);
// 
//   public NamedList<Object> finalize(NamedList<Object> ret) {
//     return ret;
//   }
// 
// }
// 
// Path: src/main/java/org/apache/solr/request/BidirectionalFacetResponseBuilder.java
// public static class SimpleTermIndexKey extends BaseTermIndexKey<SimpleTermIndexKey> {
// 
//   public SimpleTermIndexKey(int index) {
//     super(index);
//   }
// 
// }


// Path: src/test/java/org/apache/solr/request/BidirectionalFacetResponseBuilderTest.java
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Deque;
import java.util.Map;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.BidirectionalFacetResponseBuilder.Env;
import org.apache.solr.request.BidirectionalFacetResponseBuilder.SimpleTermIndexKey;
import org.apache.solr.schema.FieldType;
import org.junit.Test;
import static org.junit.Assert.*;

    runTest(1, 3, -1, 1, 2);
  }
  
  @Test
  public void testLargeNegativeOffsetWindowOOB() throws IOException {
    runTest(1, 1, -2, -1, 2);
  }
  
  @Test
  public void testPositiveOffsetWindowOOB() throws IOException {
    runTest(1, 0, 1, 0, 0);
  }
  
  @Test
  public void testLargePositiveOffsetWindowOOB() throws IOException {
    runTest(1, 0, 2, 0, 0);
    runTest(1, 1, 2, 1, 0);
  }
  
  private void runTest(int limit, int targetIdx, int requestedOffset, Integer expectedOffset, int... expectedIndices) throws IOException {
    runTest(counts, limit, targetIdx, requestedOffset, expectedOffset, expectedIndices);
  }

  private void runTest(int[] counts, int limit, int targetIdx, int requestedOffset, Integer expectedOffset, int... expectedIndices) throws IOException {
    String targetDoc = null;
    int mincount = 1;
    String fieldName = "myField";
    T ft = null;
    NamedList exp = buildExpected(expectedOffset, expectedIndices);
    NamedList actual = new NamedList(3);
    Env<T, SimpleTermIndexKey> env = new TestEnv<>(requestedOffset, limit, targetIdx, mincount, fieldName, ft, actual, counts);