Sha256: 2e3d657196b0c1bdda59f3815bc5c17d2c2448df091ed43d415673afbc7c0415

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'

describe Enumerable do
  describe "#sorted_frequencies" do
    it "returns #frequencies sorted by [frequency, value]" do
      enumerable = (0...0)
      enumerable.stub(:frequencies) do
        {
          "White-breasted Nuthatch" => 1,
          "Red-breasted Nuthatch"   => 1,
          "Brown Creeper"           => 1,
          "Squirrel"                => 1,
          "Marmelade"               => 1000,
          :yeah                     => 3,
          :man                      => 3,
          11                        => 12
        }
      end

      enumerable.sorted_frequencies.should == [
        ["Marmelade", 1000],
        [11, 12],
        [:man, 3],
        [:yeah, 3],
        ["Brown Creeper", 1],
        ["Red-breasted Nuthatch", 1],
        ["Squirrel", 1],
        ["White-breasted Nuthatch", 1]
      ]
    end

    it "calls map first if a block is given" do
      f = Struct.new(:x)
      data = [f.new(:a), f.new(:b), f.new(:b)]
      data.sorted_frequencies(&:x).should == [[:b, 2], [:a, 1]]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_stats-1.1.0 spec/enumerable/sorted_frequencies_spec.rb