@Test
public void testPreferenceShufflerWithSyntheticData() throws Exception {
setUpSyntheticData();
ParallelSGDFactorizer.PreferenceShuffler shuffler = new PreferenceShuffler(dataModel);
shuffler.shuffle();
shuffler.stage();
FastByIDMap<FastByIDMap<Boolean>> checked = new FastByIDMap<FastByIDMap<Boolean>>();
for (int i = 0; i < shuffler.size(); i++) {
Preference pref=shuffler.get(i);
float value = dataModel.getPreferenceValue(pref.getUserID(), pref.getItemID());
assertEquals(pref.getValue(), value, 0.0);
if (!checked.containsKey(pref.getUserID())) {
checked.put(pref.getUserID(), new FastByIDMap<Boolean>());
}
assertNull(checked.get(pref.getUserID()).get(pref.getItemID()));
checked.get(pref.getUserID()).put(pref.getItemID(), true);
}
LongPrimitiveIterator userIDs = dataModel.getUserIDs();
int index=0;
while (userIDs.hasNext()) {
long userID = userIDs.nextLong();
PreferenceArray preferencesFromUser = dataModel.getPreferencesFromUser(userID);
for (Preference preference : preferencesFromUser) {
assertTrue(checked.get(preference.getUserID()).get(preference.getItemID()));
index++;
}
}
assertEquals(index, shuffler.size());
}