Пример #1
0
        public void Encode32 <TEnum>(TEnum value, EnumBitEncoder32 <TEnum> encoder)
            where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            Contract.Requires <ArgumentNullException>(encoder != null);

            encoder.BitEncode(value, ref mBits.u64, ref mBitIndex);
        }
Пример #2
0
        void TestNone32Helper <TEnum>(TEnum value, TEnum noneValue)
            where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            var ebe = new EnumBitEncoder32 <TEnum>();

            Assert.IsTrue(ebe.HasNone);

            uint bits;
            int  bit_index;

            {             // Test by-value encoding
                bits = 0; bit_index = 0;
                bits = ebe.BitEncode(value, bits, bit_index);
                Assert.AreEqual(value, ebe.BitDecode(bits, bit_index));
            }

            const int bit_index_offset = 5;
            {             // Test indexed by-value encoding
                bits = 0; bit_index = bit_index_offset;
                bits = ebe.BitEncode(value, bits, bit_index);
                Assert.AreEqual(value, ebe.BitDecode(bits, bit_index));
            }

            {             // Test by-value encoding
                bits = 0; bit_index = 0;
                bits = ebe.BitEncode(noneValue, bits, bit_index);
                Assert.AreEqual(noneValue, ebe.BitDecode(bits, bit_index));
            }
        }
Пример #3
0
        void Test32Helper <TEnum, TEnumInformal>(TEnum value)
            where TEnum : struct, IComparable, IFormattable, IConvertible
            where TEnumInformal : struct, IComparable, IFormattable, IConvertible
        {
            var ebe_formal   = new EnumBitEncoder32 <TEnum>();
            var ebe_informal = new EnumBitEncoder32 <TEnumInformal>();

            // Test that informal calculations correlate with that taken from
            // formal enum types (which use a konstant member)
            Assert.AreEqual(ebe_formal.BitCountTrait, ebe_informal.BitCountTrait);
            Assert.AreEqual(ebe_formal.BitmaskTrait, ebe_informal.BitmaskTrait);

            Assert.IsFalse(ebe_formal.HasNone);
            Assert.IsFalse(ebe_informal.HasNone);

            uint bits;
            int  bit_index;

            {             // Test by-value encoding
                bits = 0; bit_index = 0;
                bits = ebe_formal.BitEncode(value, bits, bit_index);
                Assert.AreEqual(value, ebe_formal.BitDecode(bits, bit_index));
            }
            {             // Test by-reference encoding
                bits = 0; bit_index = 0;
                ebe_formal.BitEncode(value, ref bits, ref bit_index);
                // Test if anything was actually encoded
                Assert.AreNotEqual(0, bits);
                // Test for the proper increment of the cursor
                Assert.AreEqual(EnumBitEncoder32 <TEnum> .kBitCount, bit_index);

                bit_index = 0;
                // Test for the proper decoding of the enum value
                Assert.AreEqual(value, ebe_formal.BitDecode(bits, ref bit_index));
                // Test for the proper increment of the cursor
                Assert.AreEqual(EnumBitEncoder32 <TEnum> .kBitCount, bit_index);
            }

            const int bit_index_offset = 5;
            {             // Test indexed by-value encoding
                bits = 0; bit_index = bit_index_offset;
                bits = ebe_formal.BitEncode(value, bits, bit_index);
                Assert.AreEqual(value, ebe_formal.BitDecode(bits, bit_index));
            }
            {             // Test indexed by-reference encoding
                bits = 0; bit_index = bit_index_offset;
                ebe_formal.BitEncode(value, ref bits, ref bit_index);
                // Test if anything was actually encoded
                Assert.AreNotEqual(0, bits);
                // Test for the proper increment of the cursor
                Assert.AreEqual(bit_index_offset + EnumBitEncoder32 <TEnum> .kBitCount, bit_index);

                bit_index = bit_index_offset;
                // Test for the proper decoding of the enum value
                Assert.AreEqual(value, ebe_formal.BitDecode(bits, ref bit_index));
                // Test for the proper increment of the cursor
                Assert.AreEqual(bit_index_offset + EnumBitEncoder32 <TEnum> .kBitCount, bit_index);
            }
        }