Esempio n. 1
0
        public void TestUInt16()
        {
            UInt16 v1  = 0b1001_1001;
            UInt16 i1  = 0b0000_0010;
            UInt16 a1  = 0b1001_0001;
            var    v1b = v1;
            var    v1a = v1.PackCopy(5, 2, i1);

            Assert.Equal(v1b, v1);
            Assert.Equal(a1.ToBitStringPadded(), v1a.ToBitStringPadded());

            for (var i = 0; i < Iterations; i++)
            {
                var v  = _rnd.NextUInt16();
                var sv = _rnd.NextUInt16();
                for (var offset = 1; offset < sizeof(UInt16) * 8; offset++)
                {
                    for (var len = 1; len < offset; len++)
                    {
                        var ov = v;
                        v = v.PackCopy(offset, len, sv);

                        var ss = sv.ToBitStringPadded();
                        ss = ss.Substring(ss.Length - len, len);
                        var ovs = ov.ToBitStringPadded();
                        ovs = ovs.Substring(0, ovs.Length - offset)
                              + ss
                              + ovs.Substring(ovs.Length - offset + len);
                        Assert.Equal(v.ToBitStringPadded(), ovs);
                        //_outputHelper.WriteLine(ovs);
                    }
                }
            }
        }