### Question:
Rating extends AbstractBeanEntity implements Preference, Serializable { @Deprecated public static Rating create(long uid, long iid, double rating) { return create(uid, iid, rating, -1); } Rating(long eid, long uid, long iid, double v); private  Rating(BeanEntityLayout layout, long eid, long uid, long iid, double v); @Deprecated static Rating create(long uid, long iid, double rating); @Deprecated static Rating create(long uid, long iid, double rating, long ts); static RatingBuilder newBuilder(); @Override @EntityAttribute("user") long getUserId(); @Override @EntityAttribute("item") long getItemId(); long getTimestamp(); @EntityAttribute("rating") double getValue(); RatingBuilder copyBuilder(); @Override boolean equals(Object obj); static final EntityType ENTITY_TYPE; static final AttributeSet ATTRIBUTES; }### Answer:
@Test public void testSimpleEquality() { Rating r1 = Rating.create(1, 2, 3.0, 0); Rating r1a = Rating.create(1, 2, 3.0, 0); Rating r2 = Rating.create(1, 3, 2.5, 1); assertThat(r1, equalTo(r1)); assertThat(r1a, equalTo(r1)); assertThat(r2, not(equalTo(r1))); assertThat(r1, not(equalTo(r2))); }
@Test public void testURVRatingsInOrder() { List<Rating> ratings = new ArrayList<>(); ratings.add(Rating.create(1, 2, 3.0, 3)); ratings.add(Rating.create(1, 3, 4.5, 7)); ratings.add(Rating.create(1, 5, 2.3, 10)); Long2DoubleMap urv = Ratings.userRatingVector(ratings); assertThat(urv.isEmpty(), equalTo(false)); assertThat(urv.size(), equalTo(3)); assertThat(urv.get(2), closeTo(3.0, 1.0e-6)); assertThat(urv.get(3), closeTo(4.5, 1.0e-6)); assertThat(urv.get(5), closeTo(2.3, 1.0e-6)); assertThat(urv.containsKey(1), equalTo(false)); }
@Test public void testURVRatingsOutOfOrder() { List<Rating> ratings = new ArrayList<>(); ratings.add(Rating.create(1, 2, 3.0, 3)); ratings.add(Rating.create(1, 5, 2.3, 7)); ratings.add(Rating.create(1, 3, 4.5, 10)); Long2DoubleMap urv = Ratings.userRatingVector(ratings); assertThat(urv.isEmpty(), equalTo(false)); assertThat(urv.size(), equalTo(3)); assertThat(urv.get(2), closeTo(3.0, 1.0e-6)); assertThat(urv.get(3), closeTo(4.5, 1.0e-6)); assertThat(urv.get(5), closeTo(2.3, 1.0e-6)); assertThat(urv.containsKey(1), equalTo(false)); }
@Test public void testIRVRatings() { List<Rating> ratings = new ArrayList<>(); ratings.add(Rating.create(1, 2, 3.0, 1)); ratings.add(Rating.create(2, 2, 2.3, 3)); ratings.add(Rating.create(3, 2, 4.5, 10)); Long2DoubleMap urv = Ratings.itemRatingVector(ratings); assertThat(urv.isEmpty(), equalTo(false)); assertThat(urv.size(), equalTo(3)); assertThat(urv.get(1), closeTo(3.0, 1.0e-6)); assertThat(urv.get(3), closeTo(4.5, 1.0e-6)); assertThat(urv.get(2), closeTo(2.3, 1.0e-6)); assertThat(urv.containsKey(5), equalTo(false)); }