public void testClear() { FastIDSet set = new FastIDSet(); set.Add(1); set.Clear(); Assert.AreEqual(0, set.Count()); Assert.True(set.IsEmpty()); Assert.False(set.Contains(1)); }
public static IDataModel getBooleanDataModel(long[] userIDs, bool[][] prefs) { FastByIDMap<FastIDSet> result = new FastByIDMap<FastIDSet>(); for (int i = 0; i < userIDs.Length; i++) { FastIDSet prefsSet = new FastIDSet(); for (int j = 0; j < prefs[i].Length; j++) { if (prefs[i][j]) { prefsSet.Add(j); } } if (!prefsSet.IsEmpty()) { result.Put(userIDs[i], prefsSet); } } return new GenericBooleanPrefDataModel(result); }
public static IDataModel getBooleanDataModel(long[] userIDs, bool[][] prefs) { FastByIDMap <FastIDSet> result = new FastByIDMap <FastIDSet>(); for (int i = 0; i < userIDs.Length; i++) { FastIDSet prefsSet = new FastIDSet(); for (int j = 0; j < prefs[i].Length; j++) { if (prefs[i][j]) { prefsSet.Add(j); } } if (!prefsSet.IsEmpty()) { result.Put(userIDs[i], prefsSet); } } return(new GenericBooleanPrefDataModel(result)); }
public void testVersusHashSet() { FastIDSet actual = new FastIDSet(1); var expected = new HashSet<int>(); //1000000 var r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); var key = r.nextInt(100); if (d < 0.4) { Assert.AreEqual(expected.Contains(key), actual.Contains(key)); } else { if (d < 0.7) { Assert.AreEqual(expected.Add(key), actual.Add(key)); } else { Assert.AreEqual(expected.Remove(key), actual.Remove(key)); } Assert.AreEqual(expected.Count, actual.Count() ); Assert.AreEqual(expected.Count==0, actual.IsEmpty()); } } }
public void testSizeEmpty() { FastIDSet set = new FastIDSet(); Assert.AreEqual(0, set.Count()); Assert.True(set.IsEmpty()); set.Add(1); Assert.AreEqual(1, set.Count()); Assert.False(set.IsEmpty()); set.Remove(1); Assert.AreEqual(0, set.Count()); Assert.True(set.IsEmpty()); }