📄 test_crc32.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 + -