@Test
public void testReduce() throws Exception {

  LLRReducer reducer = new LLRReducer(ll);
  
  // test input, input[*][0] is the key,
  // input[*][1..n] are the values passed in via
  // the iterator.
  
  
  Gram[][] input = {
    {new Gram("the best",  1, Gram.Type.NGRAM), new Gram("the",   2, Gram.Type.HEAD), new Gram("best",  1, Gram.Type.TAIL) },
    {new Gram("best of",   1, Gram.Type.NGRAM), new Gram("best",  1, Gram.Type.HEAD), new Gram("of",    2, Gram.Type.TAIL) },
    {new Gram("of times",  2, Gram.Type.NGRAM), new Gram("of",    2, Gram.Type.HEAD), new Gram("times", 2, Gram.Type.TAIL) },
    {new Gram("times the", 1, Gram.Type.NGRAM), new Gram("times", 1, Gram.Type.HEAD), new Gram("the",   1, Gram.Type.TAIL) },
    {new Gram("the worst", 1, Gram.Type.NGRAM), new Gram("the",   2, Gram.Type.HEAD), new Gram("worst", 1, Gram.Type.TAIL) },
    {new Gram("worst of",  1, Gram.Type.NGRAM), new Gram("worst", 1, Gram.Type.HEAD), new Gram("of",    2, Gram.Type.TAIL) }
  };
  
  int[][] expectations = {
                          // A+B, A+!B, !A+B, !A+!B
                          {1, 1, 0, 5}, // the best
                          {1, 0, 1, 5}, // best of
                          {2, 0, 0, 5}, // of times
                          {1, 0, 0, 6}, // times the
                          {1, 1, 0, 5}, // the worst
                          {1, 0, 1, 5}  // worst of
  };
  
  Configuration config = getConfiguration();
  config.set(LLRReducer.NGRAM_TOTAL, "7");
  EasyMock.expect(context.getConfiguration()).andReturn(config);
  
  for (int i=0; i < expectations.length; i++) {
    int[] ee = expectations[i];
    context.write(EasyMock.eq(new Text(input[i][0].getString())), (DoubleWritable) EasyMock.anyObject());
    EasyMock.expect(ll.logLikelihoodRatio(ee[0], ee[1], ee[2], ee[3])).andDelegateTo(cl);
    
  }
  EasyMock.replay(context, ll);
  
  reducer.setup(context);
  
  for (Gram[] ii: input) {
    Collection<Gram> vv = Lists.newLinkedList();
    vv.addAll(Arrays.asList(ii).subList(1, ii.length));
    reducer.reduce(ii[0], vv, context);
  }
  
  EasyMock.verify(ll);
}