spec/digest_spec.rb in digest-murmurhash-1.0.0 vs spec/digest_spec.rb in digest-murmurhash-1.1.0

- old
+ new

@@ -1,8 +1,8 @@ require 'spec_helper' -describe Digest::MurmurHash do +describe "Digest::MurmurHash" do it "seed" do all_classes.each do |c| m = c.new expect(c::DEFAULT_SEED).to eq(m.seed) end @@ -11,11 +11,11 @@ it "seed=" do all_classes.each do |c| m = c.new m.update "murmurhash" before_digest = m.hexdigest - m.seed = (c::DEFAULT_SEED.length == 4) ? seed32 : seed64 + m.seed = seed_str(c) expect(c::DEFAULT_SEED).not_to eq(m.seed) expect(before_digest).not_to eq(m.hexdigest) end end @@ -23,49 +23,63 @@ all_classes.each do |c| expect(c.new).to be_a_kind_of(Digest::Class) end end - it "digest and hexdigest" do - expect(Digest::MurmurHash1.hexdigest("abc")).to eq("dc5f5755") + context "static hexdigest" do + it { expect(Digest::MurmurHash1.hexdigest("abc")).to eq("dc5f5755") } + it { expect(Digest::MurmurHash2.hexdigest("abc")).to eq("9b7c5713") } + it { expect(Digest::MurmurHash2A.hexdigest("abc")).to eq("679f5811") } + it { expect(Digest::MurmurHash64A.hexdigest("abc")).to eq("fb5ea99834c3c99c") } + it { expect(Digest::MurmurHash64B.hexdigest("abc")).to eq("9d595cce51420da6") } + it { expect(Digest::MurmurHashAligned2.hexdigest("abc")).to eq("9b7c5713") } + it { expect(Digest::MurmurHashNeutral2.hexdigest("abc")).to eq("9b7c5713") } + it { expect(Digest::MurmurHash3_x86_32.hexdigest("abc")).to eq("fa93ddb3") } + it { expect(Digest::MurmurHash3_x86_128.hexdigest("abc")).to eq("a506b0a2a506b0a2a506b0a2d1c6cd75") } + it { expect(Digest::MurmurHash3_x64_128.hexdigest("abc")).to eq("4174a23b522dca263f3f96b46778ad3f") } + end + + context "digest and hexdigest" do all_classes.each do |c| [:digest, :hexdigest].each do |method| str = "a" * 1024 d = c.send(method, str) - d2 = c.send(method, str, (c::DEFAULT_SEED.length == 4) ? seed32 : seed64) - expect(d).to be_a_kind_of(String) - expect(d2).to be_a_kind_of(String) - expect(d.length).to be > 0 - expect(d2.length).to be > 0 - expect(d != d2).to be_truthy + d2 = c.send(method, str, seed_str(c)) + it ("#{c}##{method}") do + expect(d).to be_a_kind_of(String) + expect(d2).to be_a_kind_of(String) + expect(d.length).to be > 0 + expect(d2.length).to be > 0 + expect(d != d2).to be_truthy + end end end end - it "rawdigest" do + describe "rawdigest" do all_classes.each do |c| str = "a" * 1024 + seed = seed_str(c) d = c.rawdigest str - d2 = c.rawdigest str, (c::DEFAULT_SEED.length == 4) ? seed32 : seed64 - expect(d).to be_a_kind_of(Integer) - expect(d2).to be_a_kind_of(Integer) - expect(d).to be > 0 - expect(d2).to be > 0 - expect(d != d2).to be_truthy + d2 = c.rawdigest str, seed + it(c) do + expect(d != d2).to be_truthy + end end end - it "update and reset and hexdigest(32bit)" do + describe "update and reset and hexdigest" do all_classes.each do |c| murmur = c.new murmur.update("m").update("u").update("r") murmur << "m" << "u" << "r" murmur << "hash" hex = murmur.hexdigest - expect(murmur.hexdigest! == hex).to be true - reset_str = "0" * ((c::DEFAULT_SEED.length == 4) ? 8 : 16) - expect(murmur.hexdigest).to eq(reset_str) + it(c) do + expect(murmur.hexdigest! == hex).to be true + expect(murmur.hexdigest).to eq("0" * (murmur.digest_length*2)) + end end end it "==" do all_classes.each do |c| @@ -87,17 +101,15 @@ murmur2.update(("murmurhash" * 100) * 10) expect(murmur1).to eq(murmur2) end end - it "length" do + it "reset" do all_classes.each do |c| - expect(c.new.length == c::DEFAULT_SEED.length).to be_truthy - end - end - - it "to_i" do - all_classes.each do |c| - expect(c.new.update("murmurhash").to_i).to be_a_kind_of(Integer) + m1 = c.new + m2 = c.new + m1.update("murmurhash") + m1.seed = seed_str(c) + expect(m1.reset).to eq(m2) end end end