File: adler32_spec.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (46 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require_relative '../../spec_helper'
require 'zlib'

describe "Zlib.adler32" do
  it "calculates Adler checksum for string" do
    Zlib.adler32("").should == 1
    Zlib.adler32(" ").should == 2162721
    Zlib.adler32("123456789").should == 152961502
    Zlib.adler32("!@#\{$\}%^&**()").should == 365495023
    Zlib.adler32("to be or not to be" * 22).should == 3979904837
    Zlib.adler32("0").should == 3211313
    Zlib.adler32((2**32).to_s).should == 193331739
    Zlib.adler32((2**64).to_s).should == 723452953
  end

  it "calculates Adler checksum for string and initial Adler value" do
    test_string = "This is a test string! How exciting!%?"
    Zlib.adler32(test_string, 0).should == 63900955
    Zlib.adler32(test_string, 1).should == 66391324
    Zlib.adler32(test_string, 2**8).should == 701435419
    Zlib.adler32(test_string, 2**16).should == 63966491
    -> { Zlib.adler32(test_string, 2**128) }.should raise_error(RangeError)
  end

  it "calculates the Adler checksum for string and initial Adler value for Integers" do
    test_string = "This is a test string! How exciting!%?"
    Zlib.adler32(test_string, 2**30).should == 1137642779
  end

  it "assumes that the initial value is given to adler, if adler is omitted" do
    orig_crc = Zlib.adler32
    Zlib.adler32("").should == Zlib.adler32("", orig_crc)
    Zlib.adler32(" ").should == Zlib.adler32(" ", orig_crc)
    Zlib.adler32("123456789").should == Zlib.adler32("123456789", orig_crc)
    Zlib.adler32("!@#\{$\}%^&**()").should == Zlib.adler32("!@#\{$\}%^&**()", orig_crc)
    Zlib.adler32("to be or not to be" * 22).should == Zlib.adler32("to be or not to be" * 22, orig_crc)
    Zlib.adler32("0").should == Zlib.adler32("0", orig_crc)
    Zlib.adler32((2**32).to_s).should == Zlib.adler32((2**32).to_s, orig_crc)
    Zlib.adler32((2**64).to_s).should == Zlib.adler32((2**64).to_s, orig_crc)
  end

  it "it returns the CRC initial value, if string is omitted" do
    Zlib.adler32.should == 1
  end

end