public void Clone() { ReadOnlyBitField clone = new ReadOnlyBitField(bf); Assert.IsTrue(bf.SequenceEqual(clone)); Assert.IsTrue(bf.SequenceEqual(clone)); }
public void ConstructorIntTest() { ReadOnlyBitField bf2 = new ReadOnlyBitField(initialByteValues, initalValues.Length); Assert.IsTrue(bf.SequenceEqual(bf2), "#1"); Assert.AreEqual(initalValues.Count(b => b), bf2.TrueCount, "#1"); }
public void ToByteArray3() { ReadOnlyBitField first = new ReadOnlyBitField(new[] { true, false, true, false, true, false, true, true, true, false, false, true, false }); ReadOnlyBitField second = new ReadOnlyBitField(first.ToBytes(), first.Length); for (int i = 0; i < first.Length; i++) { Assert.AreEqual(first[i], second[i], "#" + i); } }
internal void From(ReadOnlyBitField value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } if (Length != value.Length) { throw new ArgumentException("BitFields are of different lengths", nameof(value)); } value.Span.CopyTo(Span); TrueCount = value.TrueCount; }
public void LongByteArrayTest() { List <byte> list = new List <byte> (initialByteValues); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); list.Add(byte.MaxValue); ReadOnlyBitField b = new ReadOnlyBitField(list.ToArray(), initalValues.Length); Assert.IsTrue(b.SequenceEqual(bf), "#1"); }
public int CountTrue(ReadOnlyBitField selector) { if (selector == null) { throw new ArgumentNullException(nameof(selector)); } if (selector.Length != Length) { throw new ArgumentException("The selector should be the same length as this bitfield", nameof(selector)); } int count = 0; var data = Span; var selectorData = selector.Span; for (int i = 0; i < data.Length && i < selectorData.Length; i++) { count += CountBits(data[i] & selectorData[i]); } return(count); }
public void Or() { ReadOnlyBitField bf2 = new ReadOnlyBitField(secondValues); bf.Or(bf2); Assert.IsTrue(new ReadOnlyBitField(secondValues).SequenceEqual(bf2), "#1: bf2 should be unmodified"); for (int i = 0; i < bf.Length; i++) { Assert.AreEqual(initalValues[i] || secondValues[i], bf[i], "#2"); } int count = 0; for (int i = 0; i < initalValues.Length; i++) { if (initalValues[i] || secondValues[i]) { count++; } } Assert.AreEqual(count, bf.TrueCount, "#3"); }