コード例 #1
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);
        }