Beispiel #1
0
        void unpack_check <S, T>()
            where S : unmanaged
            where T : unmanaged
        {
            for (var j = 0; j < SampleSize; j++)
            {
                var      src = Random.Next <S>();
                Span <T> dst = stackalloc T[bitsize <S>()];
                gbits.unpack(src, dst);
                var bs = BitString.FromScalar(src);
                for (var i = 0; i < bs.Length; i++)
                {
                    var expect = bs[i] ? one <T>() : zero <T>();
                    var actual = dst[i];
                    Claim.eq(expect, actual);
                }
            }

            var      x  = Random.Span <S>(SampleSize);
            Span <T> y1 = new T[x.Length * bitsize <S>()];

            gbits.unpack(x, y1);
            var y2 = BitString.FromScalars(x);

            for (var i = 0; i < y1.Length; i++)
            {
                var expect = y2[i] ? one <T>() : zero <T>();
                var actual = y1[i];
                Claim.yea(gmath.eq(expect, actual));
            }
        }