Exemplo n.º 1
0
        public static void FlagArrayContainsLongB()
        {
            var flagarray = new FlagArray(60, true);

            Assert.AreEqual(60, flagarray.Count);
            Assert.IsFalse(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
            flagarray[20] = false;
            Assert.AreEqual(59, flagarray.Count);
            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
            flagarray[0] = false;
            Assert.AreEqual(58, flagarray.Count);
            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
            for (int index = 1; index < 20; index++)
            {
                flagarray[index] = false;
            }
            for (int index = 21; index < 60; index++)
            {
                flagarray[index] = false;
            }
            Assert.AreEqual(0, flagarray.Count);
            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsFalse(flagarray.Contains(true));
        }
Exemplo n.º 2
0
        private FlagArray(FlagArray prototype)
        {
            var length = prototype._entries.Length;

            _entries = new int[length];
            Capacity = prototype.Capacity;
            prototype._entries.CopyTo(_entries, 0);
        }
Exemplo n.º 3
0
        public static void FlagArrayStoresValues()
        {
            var flagarray = new FlagArray(12);

            Assert.IsFalse(flagarray[5]);
            flagarray[5] = true;
            Assert.IsTrue(flagarray[5]);
            Assert.IsFalse(flagarray[9]);
            flagarray[9] = true;
            Assert.IsTrue(flagarray[9]);
        }
Exemplo n.º 4
0
        public static void FlagArrayIndexOf()
        {
            var flagarray = new FlagArray(12);

            flagarray[5] = true;
            Assert.AreEqual(5, flagarray.IndexOf(true));
            Assert.AreEqual(0, flagarray.IndexOf(false));
            flagarray[0] = true;
            Assert.AreEqual(0, flagarray.IndexOf(true));
            Assert.AreEqual(1, flagarray.IndexOf(false));
        }
Exemplo n.º 5
0
        public FlagArray(FlagArray prototype)
        {
            if (prototype == null)
            {
                throw new ArgumentNullException(nameof(prototype), "prototype is null.");
            }
            Capacity = prototype.Capacity;
            _entries = ArrayReservoir <int> .GetArray(GetLength(Capacity));

            prototype._entries.CopyTo(_entries, 0);
        }
Exemplo n.º 6
0
        public FlagArray(FlagArray prototype)
        {
            if (ReferenceEquals(prototype, null))
            {
                throw new ArgumentNullException("prototype", "prototype is null.");
            }
            _length  = prototype._length;
            _entries = ArrayReservoir <int> .GetArray(GetLength(_length));

            prototype._entries.CopyTo(_entries, 0);
            _asReadOnly = new ExtendedReadOnlyCollection <bool>(this);
        }
Exemplo n.º 7
0
        public FlagArray(FlagArray prototype)
        {
            if (prototype == null)
            {
                throw new ArgumentNullException(nameof(prototype), "prototype is null.");
            }
            Capacity = prototype.Capacity;
            _entries = ArrayReservoir <int> .GetArray(GetLength(Capacity));

            prototype._entries.CopyTo(_entries, 0);
            _asReadOnly = Extensions.WrapAsIReadOnlyCollection(this);
        }
Exemplo n.º 8
0
        public static void FlagArrayGetEnumerator()
        {
            var flagarray = new FlagArray(6);

            flagarray[0] = true;
            flagarray[5] = true;
            var expected = new[] { true, false, false, false, false, true };
            var index    = 0;

            foreach (var flag in flagarray)
            {
                Assert.AreEqual(expected[index], flag);
                index++;
            }
        }
Exemplo n.º 9
0
        public static void FlagArrayFlags()
        {
            var flagarray = new FlagArray(6);
            var expected  = new[] { 0, 5 };

            foreach (var flagIndex in expected)
            {
                flagarray[flagIndex] = true;
            }
            var index = 0;

            foreach (var flagIndex in flagarray.Flags)
            {
                Assert.AreEqual(expected[index], flagIndex);
                index++;
            }
        }
Exemplo n.º 10
0
        public static void FlagArrayCopyTo()
        {
            var flagarray = new FlagArray(6);

            flagarray[0] = true;
            flagarray[5] = true;
            var expected = new[] { true, false, false, false, false, true };
            var found    = new bool[6];

            flagarray.CopyTo(found);
            var index = 0;

            foreach (var flag in found)
            {
                Assert.AreEqual(expected[index], flag);
                index++;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns a new <see cref="FlagArray"/> with all the flags negated.
        /// </summary>
        /// <remarks>The returned <see cref="FlagArray"/> is of the same capacity.</remarks>
        public FlagArray Not()
        {
            var result = new FlagArray(Capacity);

            for (var index = 0; index < _entries.Length; index++)
            {
                result._entries[index] = ~_entries[index];
            }

            var mask = GetMask(Capacity);

            if (mask != 0)
            {
                result._entries[result._entries.Length - 1] &= mask;
            }

            return(result);
        }
Exemplo n.º 12
0
        public static void FlagArrayContainsShort()
        {
            var flagarray = new FlagArray(6);

            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsFalse(flagarray.Contains(true));
            flagarray[5] = true;
            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
            flagarray[0] = true;
            Assert.IsTrue(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
            flagarray[1] = true;
            flagarray[2] = true;
            flagarray[3] = true;
            flagarray[4] = true;
            Assert.IsFalse(flagarray.Contains(false));
            Assert.IsTrue(flagarray.Contains(true));
        }
Exemplo n.º 13
0
        public static void FlagArrayConstructorTest()
        {
            var flagarray = new FlagArray(12);

            Assert.AreEqual(12, flagarray.Capacity);
        }