### Question:
TopN { public static List<NumericIDValue> selectTopN(Iterator<NumericIDValue> values, int n) { Queue<NumericIDValue> topN = initialQueue(n); selectTopNIntoQueue(topN, values, n); return selectTopNFromQueue(topN, n); } private  TopN(); static Queue<NumericIDValue> initialQueue(int n); static void selectTopNIntoQueue(Queue<NumericIDValue> topN,
                                         Iterator<NumericIDValue> values,
                                         int n); static void selectTopNIntoQueueMultithreaded(Queue<NumericIDValue> topN,
                                                      float[] queueLeastValue,
                                                      Iterator<NumericIDValue> values,
                                                      int n); static List<NumericIDValue> selectTopNFromQueue(Queue<NumericIDValue> topN, int n); static List<NumericIDValue> selectTopN(Iterator<NumericIDValue> values, int n);  }### Answer:
@Test public void testEmpty() { Collection<NumericIDValue> top2 = TopN.selectTopN(Collections.<NumericIDValue>emptyList().iterator(), 2); assertNotNull(top2); assertEquals(0, top2.size()); }
@Test public void testTopExactly() { List<NumericIDValue> candidates = makeNCandidates(3); List<NumericIDValue> top3 = TopN.selectTopN(candidates.iterator(), 3); assertNotNull(top3); assertEquals(3, top3.size()); assertEquals(3L, top3.get(0).getID()); assertEquals(3.0f, top3.get(0).getValue()); assertEquals(1L, top3.get(2).getID()); assertEquals(1.0f, top3.get(2).getValue()); }
@Test public void testTopPlusOne() { List<NumericIDValue> candidates = makeNCandidates(4); List<NumericIDValue> top3 = TopN.selectTopN(candidates.iterator(), 3); assertNotNull(top3); assertEquals(3, top3.size()); assertEquals(4L, top3.get(0).getID()); assertEquals(4.0f, top3.get(0).getValue()); assertEquals(2L, top3.get(2).getID()); assertEquals(2.0f, top3.get(2).getValue()); }
@Test public void testTopOfMany() { List<NumericIDValue> candidates = makeNCandidates(20); List<NumericIDValue> top3 = TopN.selectTopN(candidates.iterator(), 3); assertNotNull(top3); assertEquals(3, top3.size()); assertEquals(20L, top3.get(0).getID()); assertEquals(20.0f, top3.get(0).getValue()); assertEquals(18L, top3.get(2).getID()); assertEquals(18.0f, top3.get(2).getValue()); }