Exemple #1
0
        public void Slice()
        {
            for (int i = 0; i < NetBitArray.BitsPerElement * (64 + 1) + 1; i++)
            {
                NetBitArray array1 = new NetBitArray(i);

                NetBitArray array2 = array1[..array1.Length];
Exemple #2
0
        public NetReliableUnorderedReceiver(NetConnection connection, int windowSize)
            : base(connection)
        {
            LidgrenException.AssertIsPowerOfTwo((ulong)windowSize, nameof(windowSize));

            _windowSize    = windowSize;
            _earlyReceived = new NetBitArray(windowSize);
        }
Exemple #3
0
        public void Equality()
        {
            NetBitArray array1 = new NetBitArray(1);
            NetBitArray array2 = new NetBitArray(2);

            Assert.True(array1.Equals(array1));
            Assert.False(array1.Equals(array2));
            Assert.False(array2.Equals(array1));

            array1[0] = true;
            array2[0] = true;

            Assert.True(array1.Equals(array1));
            Assert.False(array1.Equals(array2));
            Assert.False(array2.Equals(array1));
        }
Exemple #4
0
        public static void Run()
        {
            NetBitArray v = new NetBitArray(256);

            for (int i = 224; i < 256; i++)
            {
                v.Clear();
                if (i > 42 && i < 65)
                {
                    v = new NetBitArray(256);
                }

                if (!v.IsZero)
                {
                    throw new LidgrenException("bit vector fail 1");
                }

                v.Set(i, true);

                if (!v.Get(i))
                {
                    throw new LidgrenException("bit vector fail 2");
                }

                if (v.IsZero)
                {
                    throw new LidgrenException("bit vector fail 3");
                }

                if (i != 79 && v.Get(79))
                {
                    throw new LidgrenException("bit vector fail 4");
                }

                int f = v.IndexOf(true);
                if (f != i)
                {
                    throw new LidgrenException("bit vector fail 5");
                }
            }

            v = new NetBitArray(9);
            v.Clear();
            v.Set(3, true);
            if (v.ToString() != "[000001000]")
            {
                throw new LidgrenException("NetBitVector.RotateDown failed");
            }
            v.RotateDown();
            if (v.Get(3) == true || v.Get(2) == false || v.Get(4) == true)
            {
                throw new LidgrenException("NetBitVector.RotateDown failed 2");
            }
            if (v.ToString() != "[000000100]")
            {
                throw new LidgrenException("NetBitVector.RotateDown failed 3");
            }

            v.Set(0, true);
            v.RotateDown();
            if (v.ToString() != "[100000010]")
            {
                throw new LidgrenException("NetBitVector.RotateDown failed 4");
            }

            v = new NetBitArray(38);
            v.Set(0, true);
            v.Set(1, true);
            v.Set(31, true);

            if (v.ToString() != "[00000010000000000000000000000000000011]")
            {
                throw new LidgrenException("NetBitVector.RotateDown failed 5");
            }

            v.RotateDown();

            if (v.ToString() != "[10000001000000000000000000000000000001]")
            {
                throw new LidgrenException("NetBitVector.RotateDown failed 5");
            }

            Console.WriteLine("NetBitVector tests OK");
        }