public static void Set_InvalidIndex_ThrowsArgumentOutOfRangeException()
        {
            WireReadyBitArray WireReadyBitArray = new WireReadyBitArray(4);

            Assert.Throws <ArgumentOutOfRangeException>(() => WireReadyBitArray.Set(-1, true));
            Assert.Throws <ArgumentOutOfRangeException>(() => WireReadyBitArray.Set(WireReadyBitArray.Length, true));

            Assert.Throws <ArgumentOutOfRangeException>(() => WireReadyBitArray[-1] = true);
            Assert.Throws <ArgumentOutOfRangeException>(() => WireReadyBitArray[WireReadyBitArray.Length] = true);
        }
        public static void Ctor_Int_Bool(int length, bool defaultValue)
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(length, defaultValue);

            Assert.AreEqual(length, bitArray.Length);
            for (int i = 0; i < bitArray.Length; i++)
            {
                Assert.AreEqual(defaultValue, bitArray[i]);
                Assert.AreEqual(defaultValue, bitArray.Get(i));
            }
        }
        public static void Ctor_Int(int length)
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(length);

            Assert.AreEqual(length, bitArray.Length);
            for (int i = 0; i < bitArray.InternalIntegerArray.Count; i++)
            {
                Assert.False(bitArray[i]);
                Assert.False(bitArray.Get(i));
            }
        }
        public static void Ctor_ByteArray(byte[] bytes, bool[] expected)
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(bytes.ReinterpretToArray <int>());

            Assert.AreEqual(expected.Length, bitArray.Length);
            for (int i = 0; i < bitArray.Length; i++)
            {
                Assert.AreEqual(expected[i], bitArray[i]);
                Assert.AreEqual(expected[i], bitArray.Get(i));
            }
        }
        public static void Ctor_IntArray(int[] array, bool[] expected)
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(array);

            Assert.AreEqual(expected.Length, bitArray.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], bitArray[i], $"Index: {i} failed indexer.");
                Assert.AreEqual(expected[i], bitArray.Get(i), $"Index: {i} failed direct Get.");
            }
        }
        public static void Ctor_BitArray(string label, WireReadyBitArray bits)
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(bits);

            Assert.AreEqual(bits.Length, bitArray.Length, label);
            for (int i = 0; i < bitArray.Length; i++)
            {
                Assert.AreEqual(bits[i], bitArray[i]);
                Assert.AreEqual(bits[i], bitArray.Get(i));
            }
        }
        public static void Get_Set(bool def, bool[] newValues)
        {
            WireReadyBitArray WireReadyBitArray = new WireReadyBitArray(newValues.Length, def);

            for (int i = 0; i < newValues.Length; i++)
            {
                WireReadyBitArray.Set(i, newValues[i]);
                Assert.AreEqual(newValues[i], WireReadyBitArray[i]);
                Assert.AreEqual(newValues[i], WireReadyBitArray.Get(i));
            }
        }
        public static void Get_InvalidIndex_ThrowsArgumentOutOfRangeException()
        {
            WireReadyBitArray bitArray = new WireReadyBitArray(4);

            Assert.Throws <ArgumentOutOfRangeException>(() => bitArray.Get(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => bitArray.Get(bitArray.Length));

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var l = bitArray[-1];
            });
            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                var l = bitArray[bitArray.Length];
            });
        }
Пример #9
0
        public static void Ctor_Int_Bool(int length, bool defaultValue)
        {
            //TODO: We now only accept things divisible by 8
            if (length % 8 != 0)
            {
                return;
            }

            WireReadyBitArray bitArray = new WireReadyBitArray(length, defaultValue);

            Assert.AreEqual(length, bitArray.Length);
            for (int i = 0; i < bitArray.Length; i++)
            {
                Assert.AreEqual(defaultValue, bitArray[i]);
                Assert.AreEqual(defaultValue, bitArray.Get(i));
            }
        }
Пример #10
0
        public void Test_WireReady_Index_Enumerable_Does_Not_Throw()
        {
            //arrange
            WireReadyBitArray bitArray = new WireReadyBitArray(16);

            //act
            bitArray.Set(3, true);

            //assert
            for (int i = 0; i < 16; i++)
            {
                Assert.DoesNotThrow(() => bitArray.Get(i));
            }

            Assert.AreEqual(16, bitArray.Length);
            Assert.DoesNotThrow(() => bitArray.EnumerateSetBitsByIndex().ToArray());
        }
        public static void SetAll(int size, bool defaultValue)
        {
            WireReadyBitArray WireReadyBitArray = new WireReadyBitArray(size, defaultValue);

            WireReadyBitArray.SetAll(!defaultValue);
            for (int i = 0; i < WireReadyBitArray.Length; i++)
            {
                Assert.AreEqual(!defaultValue, WireReadyBitArray[i]);
                Assert.AreEqual(!defaultValue, WireReadyBitArray.Get(i));
            }

            WireReadyBitArray.SetAll(defaultValue);
            for (int i = 0; i < WireReadyBitArray.Length; i++)
            {
                Assert.AreEqual(defaultValue, WireReadyBitArray[i]);
                Assert.AreEqual(defaultValue, WireReadyBitArray.Get(i));
            }
        }