Sha256: e316f8bf87e7698c6d9efc793122b6f2b79177021890222a40ab1c8d337dbb2c

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

covers 'facets/hash/collate'

test_case Hash do

  setup do
    @a = { :a=>1, :b=>2, :z=>26, :all=>%w|a b z|, :stuff1=>%w|foo bar|, :whee=>%w|a b| }
    @b = { :a=>1, :b=>4, :c=>9,  :all=>%w|a b c|, :stuff2=>%w|jim jam|, :whee=>%w|a b| }
    @c = { :a=>1, :b=>8, :c=>27 }
  end

  method :collate do

    test do
      collated = @a.collate(@b)

      collated.keys.length.assert == 8

      collated[:a].assert == [1,1]
      collated[:b].assert == [2,4]
      collated[:c].assert == [9]
      collated[:z].assert == [26]

      collated[:all].assert == %w|a b z a b c|
      collated[:stuff1].assert == %w|foo bar|
      collated[:stuff2].assert == %w|jim jam|
      collated[:whee].assert == %w|a b a b|
    end

    test "multiple times" do
      collated = @a.collate(@b).collate(@c)

      collated[:a].assert == [1,1,1]
      collated[:b].assert == [2,4,8]
      collated[:c].assert == [9,27]
    end

  end

  method :collate! do

    test "in place variant of #collate" do
      collated = @a.dup
      collated.collate!(@b)

      collated.keys.length.assert == 8

      collated[:a].assert == [1,1]
      collated[:b].assert == [2,4]
      collated[:c].assert == [9]
      collated[:z].assert == [26]

      collated[:all].assert == %w|a b z a b c|
      collated[:stuff1].assert == %w|foo bar|
      collated[:stuff2].assert == %w|jim jam|
      collated[:whee].assert == %w|a b a b|
    end

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 test/core/hash/test_collate.rb
facets-3.1.0 test/core/hash/test_collate.rb
facets-3.0.0 test/core/hash/test_collate.rb
facets-2.9.3 test/core/hash/test_collate.rb
facets-2.9.2 test/core/hash/test_collate.rb