⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_crc32.rb

📁 CRC校验采用多项式编码方法。多项式乘除法运算过程与普通代数多项式的乘除法相同。多项式的加减法运算以2为模
💻 RB
字号:
require 'test/unit'

require 'digest/crc32_in_c'
require 'digest/crc32_in_ruby'

module TestCRC32
  def test_01_simple
    # check against some values calculated by crc32 algorithm in ffv.exe
    # from http://www.geocities.com/SiliconValley/Heights/3222/ffv/
    assert_equal("00000000", @c.new.hexdigest)
    assert_equal("83dcefb7", @c.new("1").hexdigest)
    assert_equal("e8b7be43", @c.new("a").hexdigest)
    assert_equal("006278f6", @c.new("0000000000").hexdigest)
    assert_equal("3981703a", @c.new("abcdefghij").hexdigest)
  end
end

class CRC32InCTest < Test::Unit::TestCase
  include TestCRC32

  def setup
    @c = Digest::CRC32InC
  end
end

class CRC32InRuby < Test::Unit::TestCase
  include TestCRC32

  def setup
    @c = Digest::CRC32InRuby
  end
end

class CompareCRC32InCAndRubyTest < Test::Unit::TestCase
  def random_string
    s = ""
    (1 + rand(100)).times {s << rand(256).chr}
    s
  end

  def test_01_random_string_compare
    500.times do 
      str = random_string
      inc, inr = Digest::CRC32InC.new(str), Digest::CRC32InRuby.new(str)
      assert_equal(inc.digest, inr.digest)
      assert_equal(inc.hexdigest, inr.hexdigest)
    end
  end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -