/** * tests {@link UserVectorSplitterMapper} in the special case that some userIDs shall be excluded */ @Test public void testUserVectorSplitterMapperUserExclusion() throws Exception { Mapper<VarLongWritable, VectorWritable, VarIntWritable, VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write( EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f)); context.write( EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); FastIDSet usersToRecommendFor = new FastIDSet(); usersToRecommendFor.add(123L); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 10); setField(mapper, "usersToRecommendFor", usersToRecommendFor); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); mapper.map(new VarLongWritable(456L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** tests {@link AggregateAndRecommendReducer} */ @Test public void testAggregateAndRecommendReducer() throws Exception { Reducer< VarLongWritable, PrefAndSimilarityColumnWritable, VarLongWritable, RecommendedItemsWritable> .Context context = EasyMock.createMock(Reducer.Context.class); context.write( EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch( new GenericRecommendedItem(1L, 2.8f), new GenericRecommendedItem(2L, 2.0f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); similarityColumnOne.set(2, 0.5); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 3); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
/** tests {@link SimilarityMatrixRowWrapperMapper} */ @Test public void testSimilarityMatrixRowWrapperMapper() throws Exception { Mapper<IntWritable, VectorWritable, VarIntWritable, VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write( EasyMock.eq(new VarIntWritable(12)), vectorOfVectorOrPrefWritableMatches(MathHelper.elem(34, 0.5), MathHelper.elem(56, 0.7))); EasyMock.replay(context); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(12, 1.0); vector.set(34, 0.5); vector.set(56, 0.7); new SimilarityMatrixRowWrapperMapper() .map(new IntWritable(12), new VectorWritable(vector), context); EasyMock.verify(context); }