示例#1
0
        public void BitsOccuplied()
        {
            Assert.AreEqual(0, BitBuffer.BitsOccupied(0));
            for (int i = 0; i < 32; i++)
            {
                Assert.AreEqual(i + 1, BitBuffer.BitsOccupied(1u << i));
            }

            Assert.AreEqual(0, BitBuffer.BitsOccupied(0ul));
            for (int i = 0; i < 64; i++)
            {
                Assert.AreEqual(i + 1, BitBuffer.BitsOccupied(1ul << i));
            }
        }
示例#2
0
        public void TestRangedFloat()
        {
            BitBuffer b = new BitBuffer(new byte[1200]);

            int MIN = -5;
            int MAX = 5;

            int minBits = BitBuffer.BitsOccupied((uint)(MAX - MIN));

            for (int absOffset = 0; absOffset < 8; absOffset++)
            {
                b.absOffset = absOffset;
                for (int bits = 32; bits >= minBits; bits--)
                {
                    for (float min = MIN; min < MAX; min++)
                    {
                        for (float max = min; max < MAX; max++)
                        {
                            for (float f = min; f <= max; f++)
                            {
                                for (int pos = 0; pos < 8; pos++)
                                {
                                    b.Position = pos;
                                    var bWrite = b;
                                    var bRead  = b;
                                    bWrite.PutRanged(f, min, max, bits);
                                    float expected = bRead.GetRangedFloat(min, max, bits);

                                    Assert.AreEqual(f, Math.Round(expected), "expected=" + f + " actual=" + expected + "\n" +
                                                    "bits=" + bits + "\n" +
                                                    "absOffset=" + absOffset + "\n" +
                                                    "pos=" + pos + "\n" +
                                                    "min=" + min + "\n" +
                                                    "max=" + max);
                                }
                            }
                        }
                    }
                }
            }
        }