diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-07 12:04:49 +0000 |
commit | 95e8c48dd3348503a8c7db5d0498894a1b676395 (patch) | |
tree | 9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/library/zlib/crc32_spec.rb | |
parent | ed7d803500de38186c74bce94d233e85ef51e503 (diff) |
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
These files can therefore be updated like any other file in MRI.
Instructions are provided in spec/README.
[Feature #13156] [ruby-core:79246]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/library/zlib/crc32_spec.rb')
-rw-r--r-- | spec/rubyspec/library/zlib/crc32_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/rubyspec/library/zlib/crc32_spec.rb b/spec/rubyspec/library/zlib/crc32_spec.rb new file mode 100644 index 0000000000..22d1dac28b --- /dev/null +++ b/spec/rubyspec/library/zlib/crc32_spec.rb @@ -0,0 +1,52 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'zlib' + +describe "Zlib.crc32" do + it "calculates CRC checksum for string" do + Zlib.crc32("").should == 0 + Zlib.crc32(" ").should == 3916222277 + Zlib.crc32("123456789").should == 3421780262 + Zlib.crc32("!@#\{$\}%^&**()").should == 2824518887 + Zlib.crc32("to be or not to be" * 22).should == 1832379978 + Zlib.crc32("0").should == 4108050209 + Zlib.crc32((2**32).to_s).should == 3267533297 + Zlib.crc32((2**64).to_s).should == 653721760 + end + + it "calculates CRC checksum for string and initial CRC value" do + test_string = "This is a test string! How exciting!%?" + # Zlib.crc32(test_string, -2**28).should == 3230195786 + # Zlib.crc32(test_string, -2**20).should == 2770207303 + # Zlib.crc32(test_string, -2**16).should == 2299432960 + # Zlib.crc32(test_string, -2**8).should == 861809849 + # Zlib.crc32(test_string, -1).should == 2170124077 + Zlib.crc32(test_string, 0).should == 3864990561 + Zlib.crc32(test_string, 1).should == 1809313411 + Zlib.crc32(test_string, 2**8).should == 1722745982 + Zlib.crc32(test_string, 2**16).should == 1932511220 + lambda { Zlib.crc32(test_string, 2**128) }.should raise_error(RangeError) + end + + it "calculates the CRC checksum for string and initial CRC value for Bignums" do + test_string = "This is a test string! How exciting!%?" + # Zlib.crc32(test_string, -2**30).should == 277228695 + Zlib.crc32(test_string, 2**30).should == 46597132 + end + + it "assumes that the initial value is given to crc, if crc is omitted" do + orig_crc = Zlib.crc32 + Zlib.crc32("").should == Zlib.crc32("", orig_crc) + Zlib.crc32(" ").should == Zlib.crc32(" ", orig_crc) + Zlib.crc32("123456789").should == Zlib.crc32("123456789", orig_crc) + Zlib.crc32("!@#\{$\}%^&**()").should == Zlib.crc32("!@#\{$\}%^&**()", orig_crc) + Zlib.crc32("to be or not to be" * 22).should == Zlib.crc32("to be or not to be" * 22, orig_crc) + Zlib.crc32("0").should == Zlib.crc32("0", orig_crc) + Zlib.crc32((2**32).to_s).should == Zlib.crc32((2**32).to_s, orig_crc) + Zlib.crc32((2**64).to_s).should == Zlib.crc32((2**64).to_s, orig_crc) + end + + it "it returns the CRC initial value, if string is omitted" do + Zlib.crc32.should == 0 + end + +end |