Sha256: a595bb3d4958d4567c455f11559002faac757e27a193e57163955bb3ed237a26

Contents?: true

Size: 1.24 KB

Versions: 29

Compression:

Stored size: 1.24 KB

Contents

describe "Hash#flatten" do
  before(:each) do
    @h = {:plato => :greek,
          :witgenstein => [:austrian, :british],
          :russell => :welsh}
  end

  it "returns an Array" do
    {}.flatten.should be_kind_of(Array)
  end

  it "returns an empty Array for an empty Hash" do
    {}.flatten.should == []
  end

  it "sets each even index of the Array to a key of the hash" do
    a = @h.flatten
    a[0].should == :plato
    a[2].should == :witgenstein
    a[4].should == :russell
  end

  it "sets each odd index of the Array to the value corresponding to the previous element" do
    a = @h.flatten
    a[1].should == :greek
    a[3].should == [:austrian, :british]
    a[5].should == :welsh
  end

  it "does not recursively flatten Array values when called without arguments" do
    a = @h.flatten
    a[3].should == [:austrian, :british]
  end

  it "does not recursivley flatten Hash values when called without arguments" do
    @h[:russell] = {:born => :wales, :influenced_by => :mill}
    a = @h.flatten
    a[5].should_not == {:born => :wales, :influenced_by => :mill}.flatten
  end

  it "recursively flattens Array values when called with an argument >= 2" do
    a = @h.flatten(2)
    a[3].should == :austrian
    a[4].should == :british
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
opal-0.4.4 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.4.3 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.4.2 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.4.1 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.4.0 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.3.44 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.3.43 spec/rubyspec/core/hash/flatten_spec.rb
opal-0.3.42 spec/core/hash/flatten_spec.rb
opal-0.3.41 spec/core/hash/flatten_spec.rb
opal-0.3.40 spec/core/hash/flatten_spec.rb
opal-0.3.39 spec/core/hash/flatten_spec.rb
opal-0.3.38 spec/core/hash/flatten_spec.rb
opal-0.3.37 spec/core/hash/flatten_spec.rb
opal-0.3.36 spec/core/hash/flatten_spec.rb
opal-0.3.35 spec/core/hash/flatten_spec.rb
opal-0.3.34 spec/core/hash/flatten_spec.rb
opal-0.3.33 spec/core/hash/flatten_spec.rb
opal-0.3.32 spec/core/hash/flatten_spec.rb
opal-0.3.31 spec/core/hash/flatten_spec.rb
opal-0.3.30 spec/core/hash/flatten_spec.rb