@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getItemIDs() { return new LongPrimitiveArrayIterator(itemIDs); }
@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
@Override public LongPrimitiveArrayIterator getUserIDs() { return new LongPrimitiveArrayIterator(userIDs); }
private static LongPrimitiveArrayIterator countingIterator(int to) { long[] data = new long[to]; for (int i = 0; i < to; i++) { data[i] = i; } return new LongPrimitiveArrayIterator(data); }
@Test public void testTopUsers() throws Exception { long[] ids = new long[100]; for (int i = 0; i < 100; i++) { ids[i] = i; } LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids); TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() { @Override public double estimate(Long thing) { return thing; } }; long[] topItems = TopItems.getTopUsers(10, possibleItemIds, null, estimator); int gold = 99; for (long topItem : topItems) { assertEquals(gold--, topItem); } }
@Test(expected = NoSuchElementException.class) public void testEmpty() { LongPrimitiveIterator it = new LongPrimitiveArrayIterator(new long[0]); assertFalse(it.hasNext()); it.next(); }
@Override protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel, boolean includeKnownItems) throws TasteException { LongPrimitiveIterator preferredItemIDsIterator = new LongPrimitiveArrayIterator(preferredItemIDs); if (preferredItemIDs.length > maxItems) { double samplingRate = (double) maxItems / preferredItemIDs.length;
@Test public void testTopItemsRandom() throws Exception { long[] ids = new long[100]; for (int i = 0; i < 100; i++) { ids[i] = i; } LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids); final Random random = RandomUtils.getRandom(); TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() { @Override public double estimate(Long thing) { return random.nextDouble(); } }; List<RecommendedItem> topItems = TopItems.getTopItems(10, possibleItemIds, null, estimator); assertEquals(10, topItems.size()); double last = 2.0; for (RecommendedItem topItem : topItems) { assertTrue(topItem.getValue() <= last); last = topItem.getItemID(); } }
@Test public void testTopItems() throws Exception { long[] ids = new long[100]; for (int i = 0; i < 100; i++) { ids[i] = i; } LongPrimitiveIterator possibleItemIds = new LongPrimitiveArrayIterator(ids); TopItems.Estimator<Long> estimator = new TopItems.Estimator<Long>() { @Override public double estimate(Long thing) { return thing; } }; List<RecommendedItem> topItems = TopItems.getTopItems(10, possibleItemIds, null, estimator); int gold = 99; for (RecommendedItem topItem : topItems) { assertEquals(gold, topItem.getItemID()); assertEquals(gold--, topItem.getValue(), 0.01); } }
@Test public void testPeekSkip() { LongPrimitiveIterator it = new LongPrimitiveArrayIterator(new long[] {3,2,1}); assertEquals(3, it.peek()); it.skip(2); assertEquals(1, it.nextLong()); assertFalse(it.hasNext()); }
@Test(expected = NoSuchElementException.class) public void testNext() { LongPrimitiveIterator it = new LongPrimitiveArrayIterator(new long[] {3,2,1}); assertTrue(it.hasNext()); assertEquals(3, (long) it.next()); assertTrue(it.hasNext()); assertEquals(2, it.nextLong()); assertTrue(it.hasNext()); assertEquals(1, (long) it.next()); assertFalse(it.hasNext()); it.nextLong(); }