Sha256: 9bcedb50c58d315c2a8ebce4b6d0faa75b70bcb11bc7b8e972ecc89ca32a7db0

Contents?: true

Size: 856 Bytes

Versions: 10

Compression:

Stored size: 856 Bytes

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)

describe "Hash#invert" do
  it "returns a new hash where keys are values and vice versa" do
    new_hash(1 => 'a', 2 => 'b', 3 => 'c').invert.should ==
      new_hash('a' => 1, 'b' => 2, 'c' => 3)
  end

  it "handles collisions by overriding with the key coming later in keys()" do
    h = new_hash(:a => 1, :b => 1)
    override_key = h.keys.last
    h.invert[1].should == override_key
  end

  it "compares new keys with eql? semantics" do
    h = new_hash(:a => 1.0, :b => 1)
    i = h.invert
    i[1.0].should == :a
    i[1].should == :b
  end

  it "does not return subclass instances for subclasses" do
    MyHash[1 => 2, 3 => 4].invert.class.should == ruby_hash_class
    MyHash[].invert.class.should == ruby_hash_class
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jactive_support-2.1.2 spec/java_ext/map/invert_spec.rb
jactive_support-3.0.0 spec/java_ext/map/invert_spec.rb
jactive_support-3.0.0.pre2 spec/java_ext/map/invert_spec.rb
jactive_support-3.0.0.pre1 spec/java_ext/map/invert_spec.rb
jactive_support-2.1.1 spec/java_ext/map/invert_spec.rb
jactive_support-2.1.0 spec/java_ext/map/invert_spec.rb
jactive_support-2.0.0 spec/java_ext/map/invert_spec.rb
jactive_support-1.0.2 spec/java_ext/map/invert_spec.rb
jactive_support-1.0.1-universal-java-1.6 spec/java_ext/map/invert_spec.rb
jactive_support-1.0.0-universal-java-1.6 spec/java_ext/map/invert_spec.rb