public virtual void TestSimple()
 {
     IChecksum c = new BufferedChecksum(new CRC32());
     c.Update(1);
     c.Update(2);
     c.Update(3);
     Assert.AreEqual(1438416925L, c.Value);
 }
        public virtual void TestSimple()
        {
            IChecksum c = new BufferedChecksum(new CRC32());

            c.Update(1);
            c.Update(2);
            c.Update(3);
            Assert.AreEqual(1438416925L, c.Value);
        }
Example #3
0
 public override void WriteByte(byte b)
 {
     if (BufferPosition == BufferLength)
     {
         CurrentBufferIndex++;
         SwitchCurrentBuffer();
     }
     Crc.Update(b);
     CurrentBuffer[BufferPosition++] = b;
 }
Example #4
0
 public override void WriteByte(byte b)
 {
     if (bufferPosition == bufferLength)
     {
         currentBufferIndex++;
         SwitchCurrentBuffer();
     }
     crc.Update(b);
     currentBuffer[bufferPosition++] = b;
 }
        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);
        }
        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);
        }