summaryrefslogtreecommitdiff
path: root/spec/ruby/core/data/hash_spec.rb
blob: c23f08a71d61cccde05a1e08f7c20bc1537057c5 (plain)
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
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Data#hash" do
  it "returns the same integer for objects with the same content" do
    a = DataSpecs::Measure.new(42, "km")
    b = DataSpecs::Measure.new(42, "km")
    a.hash.should == b.hash
    a.hash.should be_an_instance_of(Integer)
  end

  it "returns different hashes for objects with different values" do
    a = DataSpecs::Measure.new(42, "km")
    b = DataSpecs::Measure.new(42, "ml")
    a.hash.should_not == b.hash

    a = DataSpecs::Measure.new(42, "km")
    b = DataSpecs::Measure.new(13, "km")
    a.hash.should_not == b.hash
  end

  it "returns different hashes for different classes" do
    Data.define(:x).new(1).hash.should != Data.define(:x).new(1).hash
  end
end