コード例 #1
0
ファイル: BitSetTest.cs プロジェクト: KornnerStudios/KSoft
        static void CompareBitArrayAndSet(BitArray bitarray, BitSet bitset)
        {
            Assert.AreEqual(bitarray.Length, bitset.Length);

            #region Compare via indexing
            for (int x = 0; x < bitarray.Length; x++)
            {
                Assert.AreEqual(bitarray[x], bitset[x]);
            }
            #endregion

            #region Compare via BitSet's indices enumerators
            int cardinality_zeros = 0;
            foreach (int idx in bitset.ClearBitIndices)
            {
                Assert.IsFalse(bitarray[idx]);
                cardinality_zeros++;
            }

            int cardinality = 0;
            foreach (int idx in bitset.SetBitIndices)
            {
                Assert.IsTrue(bitarray[idx]);
                cardinality++;
            }

            Assert.AreEqual(cardinality, bitset.Cardinality);
            Assert.AreEqual(cardinality_zeros, bitset.CardinalityZeros);
            #endregion

            #region Compare via GetEnumerator
            var bitarray_iter = bitarray.GetEnumerator();
            var bitset_iter   = bitset.GetEnumerator();
            while (bitarray_iter.MoveNext() && bitset_iter.MoveNext())
            {
                Assert.AreEqual((bool)bitarray_iter.Current, bitset_iter.Current);
            }
            #endregion
        }