Exemplo n.º 1
0
        public void TestArraysPackedDiff()
        {
            // Values changed test
            var longOutDiffData = new long[]
            {
                1,
                2,
                13,
                29,
                44,
                15
            };
            var longOutData = new long[]
            {
                1,
                2,
                13,
                37,
                69
            };

            // No change test
            var intOutDiffData = new int[]
            {
                1337,
                69420,
                12345,
                0,
                0,
                5
            };
            var intOutData = new int[]
            {
                1337,
                69420,
                12345,
                0,
                0,
                5
            };

            // Array resize test
            var doubleOutDiffData = new double[]
            {
                0.2,
                6,
                1E39
            };
            var doubleOutData = new double[]
            {
                0.02,
                0.06,
                1E40,
                256.0
            };

            // Serialize
            var outNetworkBuffer = new NetworkBuffer();
            var outNetworkWriter = new NetworkWriter(outNetworkBuffer);

            outNetworkWriter.WriteLongArrayPackedDiff(longOutData, longOutDiffData);
            outNetworkWriter.WriteIntArrayPackedDiff(intOutData, intOutDiffData);
            outNetworkWriter.WriteDoubleArrayPackedDiff(doubleOutData, doubleOutDiffData);

            // Deserialize
            var inNetworkBuffer = new NetworkBuffer(outNetworkBuffer.GetBuffer());
            var inNetworkReader = new NetworkReader(inNetworkBuffer);
            var longInData      = inNetworkReader.ReadLongArrayPackedDiff(longOutDiffData);
            var intInData       = inNetworkReader.ReadIntArrayPackedDiff(intOutDiffData);
            var doubleInData    = inNetworkReader.ReadDoubleArrayPackedDiff(doubleOutDiffData);

            // Compare
            Assert.That(longInData, Is.EqualTo(longOutData));
            Assert.That(intInData, Is.EqualTo(intOutData));
            Assert.That(doubleInData, Is.EqualTo(doubleOutData));
        }