@Test
public void testReduce() throws Exception {

  // test input, input[*][0] is the key,
  // input[*][1..n] are the values passed in via
  // the iterator.
  Gram[][] input = {
      {new Gram("the", Gram.Type.UNIGRAM), new Gram("the", Gram.Type.UNIGRAM), new Gram("the", Gram.Type.UNIGRAM)},
      {new Gram("the", Gram.Type.HEAD), new Gram("the best", Gram.Type.NGRAM), new Gram("the worst", Gram.Type.NGRAM)},
      {new Gram("of", Gram.Type.HEAD), new Gram("of times", Gram.Type.NGRAM), new Gram("of times", Gram.Type.NGRAM)},
      {new Gram("times", Gram.Type.TAIL), new Gram("of times", Gram.Type.NGRAM), new Gram("of times", Gram.Type.NGRAM)}};
  
  // expected results.
  Gram[][] values = {{new Gram("the", 2, Gram.Type.UNIGRAM), new Gram("the", 2, Gram.Type.UNIGRAM)},
                                  {new Gram("the best", 1, Gram.Type.NGRAM), new Gram("the", 2, Gram.Type.HEAD)},
                                  {new Gram("the worst", 1, Gram.Type.NGRAM), new Gram("the", 2, Gram.Type.HEAD)},
                                  {new Gram("of times", 2, Gram.Type.NGRAM), new Gram("of", 2, Gram.Type.HEAD)},
                                  {new Gram("of times", 2, Gram.Type.NGRAM), new Gram("times", 2, Gram.Type.TAIL)}};
  // set up expectations
  for (Gram[] v : values) {
    context.write(v[0], v[1]);
  }
  EasyMock.replay(context);
  
  // play back the input data.
  CollocReducer c = new CollocReducer();
  
  GramKey key = new GramKey();
  byte[] empty = new byte[0];
  for (Gram[] ii : input) {
    key.set(ii[0], empty);
    Collection<Gram> vv = Lists.newLinkedList();
    vv.addAll(Arrays.asList(ii));
    c.reduce(key, vv, context);
  }
  
  EasyMock.verify(context);
}