summaryrefslogtreecommitdiff
path: root/spec/ruby/core/data/hash_spec.rb
blob: 324a2abca4e97589c832140dc6b8b6250ea8e971 (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
26
27
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.2" do
  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
end