@Test public void weightedFriendRecommendation() throws Exception { deleteSocialGraph(); Person a = personRepository.createPerson("a"); Person b = personRepository.createPerson("b"); Person c = personRepository.createPerson("c"); Person d = personRepository.createPerson("d"); Person e = personRepository.createPerson("e"); Person f = personRepository.createPerson("f"); // A is friends with B,C and D a.addFriend(b); a.addFriend(c); a.addFriend(d); // E is only friend with B e.addFriend(b); // F is friend with B, C, D f.addFriend(b); f.addFriend(c); f.addFriend(d); ArrayList<Person> recommendations = fromIterableToArrayList(a.getFriendRecommendation(2).iterator()); // Recommend F to A assertThat(recommendations.get(0), equalTo(f)); // Recommend E to A assertThat(recommendations.get(1), equalTo(e)); }
@Test public void singleFriendRecommendation() throws Exception { deleteSocialGraph(); Person a = personRepository.createPerson("a"); Person b = personRepository.createPerson("b"); Person c = personRepository.createPerson("c"); Person d = personRepository.createPerson("d"); Person e = personRepository.createPerson("e"); // A is friends with B,C and D a.addFriend(b); a.addFriend(c); a.addFriend(d); // E is also friend with B, C and D e.addFriend(b); e.addFriend(c); e.addFriend(d); Person recommendation = IteratorUtil.single(a.getFriendRecommendation(1).iterator()); assertThat(recommendation, equalTo(e)); }