public void Test00Indexer() { BitTuple bt = new BitTuple(8); Assert.AreEqual(8, bt.Length); for (int i = 0; i < 8; i++) { Assert.AreEqual(false, bt[i]); } for (int i = 0; i < 8; i++) { bt[i] = (i % 2) == 0; Assert.AreEqual((i % 2) == 0, bt[i]); } }
public void TestIndexerBounds() { BitTuple bt = new BitTuple(8); Assert.AreEqual(8, bt.Length); try { bool t = bt[9]; Assert.Fail("should have thrown ArgumentException"); } catch (ArgumentException) { /* ignore */ } try { bool t = bt[-1]; Assert.Fail("should have thrown ArgumentException"); } catch (ArgumentException) { /* ignore */ } }
public void Test1AddAll() { BitTuple bt = new BitTuple(bits); bt.AddAll(bits); Assert.AreEqual(2 * bits.Length, bt.Length); for (int i = 0; i < bt.Length; i++) { Assert.AreEqual(bits[i % bits.Length], bt[i]); } }
public void TestToBitArray() { BitTuple bt = new BitTuple(0); bt.AddAll(bits); Assert.AreEqual(bits.Length, bt.Length); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bits[i], bt[i]); } BitArray t = bt.ToBitArray(); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bt[i], t[i]); } t = new BitArray(bt.ToArray()); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bt[i], t[i]); } t = new BitArray(bits); bt = new BitTuple(t); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bt[i], t[i]); } }
public void TestToArray2() { BitTuple bt = new BitTuple(bits); Assert.AreEqual(bits.Length, bt.Length); bt = new BitTuple(bt.ToArray(), bt.Length); Assert.AreEqual(bits.Length, bt.Length); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bits[i], bt[i]); } bt = new BitTuple(bt.ToArray()); Assert.LessOrEqual(bits.Length, bt.Length); for (int i = 0; i < bits.Length; i++) { Assert.AreEqual(bits[i], bt[i]); } }
public void TestToArray() { BitTuple bt = new BitTuple(8); Assert.AreEqual(8, bt.Length); for (int i = 0; i < 8; i++) { Assert.AreEqual(false, bt[i]); } byte[] bytes = bt.ToArray(); Assert.AreEqual(1, bytes.Length); Assert.AreEqual(0, bytes[0]); bt.Add(true); Assert.AreEqual(9, bt.Length); for (int i = 0; i < 8; i++) { Assert.AreEqual(false, bt[i]); } Assert.AreEqual(true, bt[8]); bytes = bt.ToArray(); Assert.AreEqual(2, bytes.Length); Assert.AreEqual(0, bytes[0]); Assert.AreEqual(1, bytes[1]); try { bool t = bt[9]; Assert.Fail("should have thrown ArgumentException"); } catch (ArgumentException) { /* ignore */ } }
public void TestSubset() { BitTuple bt = new BitTuple(bits, 8); Assert.AreEqual(8, bt.Length); for (int i = 0; i < bt.Length; i++) { Assert.AreEqual(bits[i], bt[i]); } }