public virtual void ToBitArrayTest() { int TEST_SET_LENGTH = 10; int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); BitArray setArray = new BitArray(TEST_SET_LENGTH); foreach (int index in set) { setArray[index] = true; } RLEBitset testSet = (RLEBitset)CreateSetFromIndices(set, TEST_SET_LENGTH); BitArray testArray = testSet.ToBitArray(); bool expected = true; bool actual = true; for (int i = 0; i < setArray.Length; i++) { if (setArray[i]) { actual &= setArray[i] == testArray[i]; } } Assert.Equal(expected, actual); }
public virtual void EqualsTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); IBitset otherSet = CreateSetFromIndices(set, TEST_SET_LENGTH); Assert.AreEqual <IBitset>(testSet, otherSet); }
public virtual void CloneTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); var clone = testSet.Clone(); Assert.AreEqual(clone, testSet); }
public virtual void GetTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); bool expected = set.Contains(2); bool result = testSet.Get(2); Assert.AreEqual(expected, result); }
public virtual void CardinalityTest() { int[] set = SetGenerator.GetContiguousArray(1, 5000); IBitset testSet = CreateSetFromIndices(set, set.Max() + 1); int expected = set.Length; int actual = testSet.Cardinality(); Assert.AreEqual(expected, actual); }
public virtual void AndTest() { int[] first = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] second = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] result = first.Intersect(second).ToArray(); IBitset expected = CreateSetFromIndices(result, TEST_SET_LENGTH); IBitset actual = CreateSetFromIndices(first, TEST_SET_LENGTH).And(CreateSetFromIndices(second, TEST_SET_LENGTH)); Assert.AreEqual(expected, actual); }
public virtual void OrTest() { int[] first = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] second = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] result = first.Union(second).ToArray(); IBitset expected = CreateSetFromIndices(result, TEST_SET_LENGTH); IBitset actual = CreateSetFromIndices(first, TEST_SET_LENGTH).Or(CreateSetFromIndices(second, TEST_SET_LENGTH)); Assert.AreEqual(expected, actual, generateMessage("OrWith", first, second, result)); }
public virtual void GetHashCodeEqualityTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); IBitset otherTestSet = CreateSetFromIndices(set, TEST_SET_LENGTH); int hash = testSet.GetHashCode(); int otherHash = otherTestSet.GetHashCode(); Assert.AreEqual(hash, otherHash); }
public virtual void SetRangeTrueLargeTest() { int[] set = SetGenerator.GetContiguousArray(0, 5000); IBitset testSet = CreateSetFromIndices(set, 5000); testSet.Set(5007, 5009, true); bool expected = true; bool result = testSet.Get(8); Assert.AreEqual(expected, result); }
public virtual void SetRangeFalseLargeTest() { int[] set = SetGenerator.GetContiguousArray(0, 5000);; IBitset testSet = CreateSetFromIndices(set, 5000); testSet.Set(1, 3, false); bool expected = false; bool result = testSet.Get(2); Assert.AreEqual(expected, result); }
public virtual void AndWithTest() { int[] first = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] second = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] result = first.Intersect(second).ToArray(); IBitset testSet = CreateSetFromIndices(first, TEST_SET_LENGTH); testSet.AndWith(CreateSetFromIndices(second, TEST_SET_LENGTH)); Assert.AreEqual(CreateSetFromIndices(result, TEST_SET_LENGTH), testSet); }
public virtual void SetTrueTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); testSet.Set(8, true); bool expected = true; bool result = testSet.Get(8); Assert.AreEqual(expected, result); }
public virtual void OrWithTest() { int[] first = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] second = SetGenerator.GetRandomArray(TEST_SET_LENGTH); int[] result = first.Union(second).ToArray(); IBitset testSet = CreateSetFromIndices(first, TEST_SET_LENGTH); testSet.OrWith(CreateSetFromIndices(second, TEST_SET_LENGTH)); Assert.AreEqual(CreateSetFromIndices(result, TEST_SET_LENGTH), testSet, generateMessage("OrWith", first, second, result)); }
public void GetHashCodeNotEqualTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); IBitset otherTestSet = CreateSetFromIndices(set, TEST_SET_LENGTH); otherTestSet.Flip(SetGenerator.GetRandomArray(1)[0]); int hash = testSet.GetHashCode(); int otherHash = otherTestSet.GetHashCode(); Assert.NotEqual(hash, otherHash); }
public virtual void EnumerationTest() { int[] set = SetGenerator.GetRandomArray(TEST_SET_LENGTH); IBitset testSet = CreateSetFromIndices(set, TEST_SET_LENGTH); List <int> enumeratedList = new List <int>(); foreach (int i in testSet) { enumeratedList.Add(i); } CollectionAssert.AreEquivalent(enumeratedList.ToArray(), set); }
public virtual void SerializationTest() { int[] indicies = SetGenerator.GetRandomArray(TEST_SET_LENGTH); RLEBitset actual = (RLEBitset)CreateSetFromIndices(indicies, TEST_SET_LENGTH); RLEBitset expected; using (MemoryStream ms = new MemoryStream()) { actual.Serialize(ms); ms.Position = 0; expected = RLEBitset.Deserialize(ms); } Assert.Equal(actual, expected); }
public virtual void SerializationTest() { int TEST_SET_LENGTH = 10; int[] indicies = SetGenerator.GetRandomArray(TEST_SET_LENGTH); RoaringBitset actual = (RoaringBitset)CreateSetFromIndices(indicies, TEST_SET_LENGTH); RoaringBitset expected = null; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { actual.Serialize(ms); ms.Position = 0; expected = RoaringBitset.Deserialize(ms); } Assert.AreEqual(actual, expected); }
public virtual void DifferenceWithTest() { // Test arrayContainer-based sets int[] set1 = { 1, 2, 3, 7 }; RoaringBitset testSet1 = RoaringBitset.Create(set1); int[] set2 = { 1, 4, 7 }; RoaringBitset testSet2 = RoaringBitset.Create(set2); testSet1.DifferenceWith(testSet2); Assert.AreEqual(false, testSet1.Get(1)); Assert.AreEqual(true, testSet1.Get(3)); // Test bitsetContainer-based sets int[] set3 = SetGenerator.GetContiguousArray(0, 5000); RoaringBitset testSet3 = RoaringBitset.Create(set3); int[] setExceptions = { 4 }; int[] set4 = SetGenerator.GetContiguousArrayWithExceptions(0, 5000, setExceptions); RoaringBitset testSet4 = RoaringBitset.Create(set4); // Reduce contiguous array to single value (4) via DifferenceWith testSet3.DifferenceWith(testSet4); Assert.AreEqual(false, testSet3.Get(2)); Assert.AreEqual(true, testSet3.Get(4)); // // Reduce testSet2 to 4 as well testSet2.DifferenceWith(testSet4); Assert.AreEqual(false, testSet2.Get(1)); Assert.AreEqual(true, testSet2.Get(4)); // Remove contents of set1 from set4 testSet4.DifferenceWith(testSet1); Assert.AreEqual(false, testSet4.Get(2)); Assert.AreEqual(true, testSet4.Get(6)); }
public virtual void DifferenceTest() { int[] set1 = { 1, 2, 3, 7 }; IBitset testSet1 = CreateSetFromIndices(set1, 8); int[] set2 = { 1, 4, 7 }; IBitset testSet2 = CreateSetFromIndices(set2, 8); // These sparse sets will all use array containers. IBitset arrayContainerDiffSet = testSet1.Difference(testSet2); Assert.AreEqual(false, arrayContainerDiffSet.Get(1)); Assert.AreEqual(true, arrayContainerDiffSet.Get(3)); // Test difference from large contiguous bitset to exercise bitsetcontainers. int[] set3 = SetGenerator.GetContiguousArray(0, 5000); IBitset testSet3 = CreateSetFromIndices(set3, 5000); int[] setExceptions = { 4 }; int[] set4 = SetGenerator.GetContiguousArrayWithExceptions(0, 5000, setExceptions); IBitset testSet4 = CreateSetFromIndices(set4, 5000); // Both sets are using bitset containers IBitset bitsetContainerDiffSet = testSet3.Difference(testSet4); Assert.AreEqual(false, bitsetContainerDiffSet.Get(1)); Assert.AreEqual(true, bitsetContainerDiffSet.Get(4)); // Diff sets using bitset containers with array containers and vice versa IBitset mixedDiffSet1 = testSet4.Difference(testSet2); IBitset mixedDiffSet2 = testSet2.Difference(testSet4); Assert.AreEqual(false, mixedDiffSet1.Get(1)); Assert.AreEqual(true, mixedDiffSet1.Get(3)); Assert.AreEqual(false, mixedDiffSet2.Get(1)); Assert.AreEqual(true, mixedDiffSet2.Get(4)); }