예제 #1
0
        public void ToBytes_UInt16_InvalidBitLength_Throws()
        {
            UInt16 value = 0;

            foreach (var invalidBitLength in new[] { int.MinValue, short.MinValue, -1, 0, 17, short.MaxValue, int.MaxValue })
            {
                Assert.Equal("bitLength",
                             Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                         value.ToBytes(invalidBitLength))
                             .ParamName);
            }
        }
예제 #2
0
        public void ToBytes_UInt16_Works()
        {
            UInt16 value          = 0xf6e1;
            var    expectedValues = new Dictionary <int, UInt16>()
            {
                { 1, 0x01 }, { 9, 0x00e1 },
                { 2, 0x01 }, { 10, 0x02e1 },
                { 3, 0x01 }, { 11, 0x06e1 },
                { 4, 0x01 }, { 12, 0x06e1 },
                { 5, 0x01 }, { 13, 0x16e1 },
                { 6, 0x21 }, { 14, 0x36e1 },
                { 7, 0x61 }, { 15, 0x76e1 },
                { 8, 0xe1 }, { 16, 0xf6e1 },
            };

            foreach (var expectedValue in expectedValues)
            {
                Assert.Equal(
                    BitConverter.GetBytes(expectedValue.Value).Take((expectedValue.Key + 7) / 8),
                    value.ToBytes(expectedValue.Key));
            }
        }
예제 #3
0
 public static void Write(this BufferSlice buffer, UInt16 value, int offset)
 {
     value.ToBytes(buffer.Array, buffer.Offset + offset);
 }
예제 #4
0
 public void Put(UInt16 value)
 {
     Put(value.ToBytes(_endianness));
 }