GetRandomArray() public static method

public static GetRandomArray ( int length, int maxNumberOfOnes ) : int[]
length int
maxNumberOfOnes int
return int[]
Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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));
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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));
        }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }