AbstractFastRecommender extends AbstractRecommender<U, I> implements FastRecommender<U, I> { @Override public Recommendation<U, I> getRecommendation(U u, int maxLength) { FastRecommendation rec = getRecommendation(user2uidx(u), maxLength); return new Recommendation<>(uidx2user(rec.getUidx()), rec.getIidxs().stream() .map(this::iidx2item) .collect(toList())); } AbstractFastRecommender(FastUserIndex<U> uIndex, FastItemIndex<I> iIndex); @Override int numUsers(); @Override int user2uidx(U u); @Override U uidx2user(int uidx); @Override int numItems(); @Override int item2iidx(I i); @Override I iidx2item(int iidx); @Override Recommendation<U, I> getRecommendation(U u, int maxLength); @Override FastRecommendation getRecommendation(int uidx); @Override FastRecommendation getRecommendation(int uidx, int maxLength); @Override Recommendation<U, I> getRecommendation(U u, int maxLength, Predicate<I> filter); @Override FastRecommendation getRecommendation(int uidx, IntPredicate filter); @Override abstract FastRecommendation getRecommendation(int uidx, int maxLength, IntPredicate filter); @Override Recommendation<U, I> getRecommendation(U u, Stream<I> candidates); @Override FastRecommendation getRecommendation(int uidx, IntStream candidates);  }
@Test public void testSubclass() { int maxLength = Integer.MAX_VALUE; IntPredicate filter = i -> true; List<Tuple2id> result0 = recommender.getRecommendation(0, maxLength, filter).getIidxs(); assertEquals(recs, result0); List<Tuple2id> result1 = recommender.getRecommendation(1, maxLength, filter).getIidxs(); assertEquals(emptyList(), result1); }
@Test public void testFilter() { int maxLength = Integer.MAX_VALUE; IntPredicate filter = i -> i % 2 == 0; List<Tuple2id> result = recommender.getRecommendation(0, maxLength, filter).getIidxs(); List<Tuple2id> expected = Arrays.asList( tuple(0, 6.0), tuple(2, 4.0), tuple(4, 2.0) ); assertEquals(expected, result); }
@Test public void testMaxLength() { int maxLength = 2; IntPredicate filter = i -> true; List<Tuple2id> result = recommender.getRecommendation(0, maxLength, filter).getIidxs(); List<Tuple2id> expected = Arrays.asList( tuple(0, 6.0), tuple(1, 5.0) ); assertEquals(expected, result); }
@Test public void testFastFree() { int maxLength = Integer.MAX_VALUE; List<Tuple2id> result = recommender.getRecommendation(0, maxLength).getIidxs(); List<Tuple2id> expected = Arrays.asList( tuple(0, 6.0), tuple(1, 5.0), tuple(2, 4.0), tuple(3, 3.0), tuple(4, 2.0), tuple(5, 1.0) ); assertEquals(expected, result); }
@Test public void testFastCandidates() { IntStream candidates = IntStream.of(1, 3, 5); List<Tuple2id> result = recommender.getRecommendation(0, candidates).getIidxs(); List<Tuple2id> expected = Arrays.asList( tuple(1, 5.0), tuple(3, 3.0), tuple(5, 1.0) ); assertEquals(expected, result); }
@Test public void testStdFilter() { int maxLength = Integer.MAX_VALUE; Predicate<String> filter = item -> true; List<Tuple2od<String>> result = recommender.getRecommendation("0", maxLength, filter).getItems(); List<Tuple2od<String>> expected = Arrays.asList( tuple("0", 6.0), tuple("1", 5.0), tuple("2", 4.0), tuple("3", 3.0), tuple("4", 2.0), tuple("5", 1.0) ); assertEquals(expected, result); }
@Test public void testStdFree() { int maxLength = Integer.MAX_VALUE; List<Tuple2od<String>> result = recommender.getRecommendation("0", maxLength).getItems(); List<Tuple2od<String>> expected = Arrays.asList( tuple("0", 6.0), tuple("1", 5.0), tuple("2", 4.0), tuple("3", 3.0), tuple("4", 2.0), tuple("5", 1.0) ); assertEquals(expected, result); }
@Test public void testStdCandidates() { Stream<String> candidates = Stream.of("1", "3", "5"); List<Tuple2od<String>> result = recommender.getRecommendation("0", candidates).getItems(); List<Tuple2od<String>> expected = Arrays.asList( tuple("1", 5.0), tuple("3", 3.0), tuple("5", 1.0) ); assertEquals(expected, result); }