Exemplo n.º 1
0
        public virtual void TestCRC32()
        {
            byte[] b = new byte[256];
            for (int i = 0; i < b.Length; i++)
                b[i] = (byte)i;

            IChecksum digest = new CRC32();
            digest.Update(b, 0, b.Length);

            Int64 expected = 688229491;
            Assert.AreEqual(expected, digest.Value);
        }
Exemplo n.º 2
0
        public virtual void TestRandom()
        {
            IChecksum c1 = new CRC32();
            IChecksum c2 = new BufferedChecksum(new CRC32());
            int iterations = AtLeast(10000);
            for (int i = 0; i < iterations; i++)
            {
                switch (Random().Next(4))
                {
                    case 0:
                        // update(byte[], int, int)
                        int length = Random().Next(1024);
                        byte[] bytes = new byte[length];
                        Random().NextBytes(bytes);
                        c1.Update(bytes, 0, bytes.Length);
                        c2.Update(bytes, 0, bytes.Length);
                        break;

                    case 1:
                        // update(int)
                        int b = Random().Next(256);
                        c1.Update(b);
                        c2.Update(b);
                        break;

                    case 2:
                        // reset()
                        c1.Reset();
                        c2.Reset();
                        break;

                    case 3:
                        // getValue()
                        Assert.AreEqual(c1.Value, c2.Value);
                        break;
                }
            }
            Assert.AreEqual(c1.Value, c2.Value);
        }