Beispiel #1
0
        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]); }
        }
Beispiel #2
0
        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]); }
        }
Beispiel #3
0
        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 */ }
        }