public void Test4() { byte[] d1 = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; byte[] d2 = (byte[])d1.Clone(); Assert.AreEqual(d1, d2); d1[0] = 0; Assert.AreNotEqual(d1, d2); d1[0] = 0x01; BoolCollection bits = new BoolCollection(d1); Assert.IsTrue(bits[0]); bits[0] = false; Assert.IsFalse(bits[0]); d2[0] = 0; Assert.AreEqual(d1, d2); bits[7] = true; Assert.IsFalse(bits[0]); Assert.IsTrue(bits[7]); d2[0] = 0x80; Assert.AreEqual(d1, d2); bits[63] = false; Assert.IsFalse(bits[63]); d2[7] =0; Assert.AreEqual(d1, d2); }
/// <summary> /// Converts this rectangular array of bools into a jagged array, for the purposes /// of Data Contract (DC) serialization. /// </summary> public static BoolCollection Jaggedize_DC(this bool[,] input) { BoolCollection output = new BoolCollection(); output.AddRange(new BoolList[input.GetLength(0)].AsEnumerable()); for (int i = 0; i < input.GetLength(0); i++) { output[i] = new BoolList(); output[i].AddRange(new bool[input.GetLength(1)].AsEnumerable()); for (int j = 0; j < input.GetLength(1); j++) { output[i][j] = input[i, j]; } } return(output); }
public void Test1() { List<byte> input = new List<byte>(); List<bool> check = new List<bool>(); for (int i = 0; i < 256; i++) { input.Add((byte)i); check.Add((i & (1 << 0)) != 0); check.Add((i & (1 << 1)) != 0); check.Add((i & (1 << 2)) != 0); check.Add((i & (1 << 3)) != 0); check.Add((i & (1 << 4)) != 0); check.Add((i & (1 << 5)) != 0); check.Add((i & (1 << 6)) != 0); check.Add((i & (1 << 7)) != 0); } BoolCollection bc = new BoolCollection(input.ToArray(), 0, 256); for (int i = 0; i < check.Count; i++) { Assert.AreEqual(check[i], bc[i], string.Format("COUNT[{0}] UNMATCH", i)); } }
public static bool[,] UnJaggedize(this BoolCollection input) { foreach (BoolList ary in input) { if (null == ary || input[0].Count != ary.Count) { throw new ArgumentException("Can't un-jaggedize a jagged jagged array"); } } bool[,] output = new bool[input.Count, input[0].Count]; for (int i = 0; i < input.Count; i++) { for (int j = 0; j < input[0].Count; j++) { output[i, j] = input[i][j]; } } return(output); }