Sha256: 1df64374261129cada0272dd60d40734f4cd6dc8707e6d299bb9f45766fd36cb

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

describe Digest::MurmurHash do
  let :murmur do
    Digest::MurmurHash.new
  end

  it "initialize" do
    expect(Digest::MurmurHash.new).to be_a_kind_of(Digest::Base)
  end

  it "hexdigest" do
    expect(Digest::MurmurHash.hexdigest("a" * 1024)).to eq("a1522e5f")
  end

  it "update and reset and hexdigest" do
    murmur.update("m")
    murmur.update("u")
    murmur.update("r")
    murmur.update("m")
    murmur.update("u")
    murmur.update("r")
    murmur.update("hash")
    expect(murmur.hexdigest).to eq("c709abd5");
    expect(murmur.hexdigest).to eq("c709abd5");
    expect(murmur.hexdigest!).to eq("c709abd5");
    expect(murmur.hexdigest).to eq("00000000");
  end

  it "dup" do
    murmur1 = Digest::MurmurHash.new
    murmur2 = Digest::MurmurHash.new
    murmur1.update("murmur")
    murmur2 = murmur1.dup
    murmur2.update("hash")
    expect(murmur2.hexdigest).to eq("c709abd5")
  end

  it "==" do
    ["", "murmur", "murmurhash" * 1024].each do |str|
      murmur1 = Digest::MurmurHash.new
      murmur2 = Digest::MurmurHash.new
      expect(murmur1.update(str) == murmur2.update(str)).to be_true
    end
  end

  it "length" do
    expect(murmur.length).to eq(4);
  end

  it "block_length" do
    # MurmurHash don't use block.
    # Therefore `block_length` return chunk size for calculate MurmurHash (equal 4) 
    expect(murmur.block_length).to eq(4);
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
digest-murmurhash-0.0.1 spec/digest_spec.rb