示例#1
0
        public void TestNoise()
        {
            var random = new Random();
            var bytes  = new byte[1024];

            random.NextBytes(bytes);
            var bytes2 = new byte[1024];

            bytes.CopyTo(bytes2, 0);

            for (var i = 0; i < bytes2.Length; i++)
            {
                if (random.NextDouble() > 0.5)
                {
                    bytes2[i] = (byte)random.Next();
                }
            }

            using (var patch = Bsdiff.GenerateBzip2Diff(bytes, bytes2))
                using (var result = Bsdiff.ApplyBzip2Patch(bytes, patch.ToArray()))
                {
                    bool equals = result.ToArray().OrderBy(a => a).SequenceEqual(bytes2.OrderBy(a => a));
                    Assert.True(equals);
                }
        }
示例#2
0
        public void TestMethod()
        {
            var bytes  = new byte[] { 0, 1, 2, 3, 5 };
            var bytes2 = new byte[] { 0, 1, 2, 3, 10 };

            using (var patch = Bsdiff.GenerateBzip2Diff(bytes, bytes2))
                using (var result = Bsdiff.ApplyBzip2Patch(bytes, patch.ToArray()))
                {
                    bool equals = result.ToArray().OrderBy(a => a).SequenceEqual(bytes2.OrderBy(a => a));
                    Assert.True(equals);
                }
        }
        static void Main(string[] args)
        {
            var bytes  = new byte[] { 0, 1, 2, 3, 5 };
            var bytes2 = new byte[] { 0, 1, 2, 3, 10 };

            var patch  = Bsdiff.GenerateBzip2Diff(bytes, bytes2);
            var result = Bsdiff.ApplyBzip2Patch(bytes, patch);

            bool equals = result.OrderBy(a => a).SequenceEqual(bytes2.OrderBy(a => a));

            Console.WriteLine(equals ? "YES" : "NO");
            Console.ReadLine();
        }