File: frequencies_spec.rb

package info (click to toggle)
ruby-powerpack 0.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 492 kB
  • sloc: ruby: 819; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'spec_helper'

unless Enumerable.method_defined? :frequencies
  describe 'Enumerable#frequencies' do
    context 'empty collection' do
      it 'evaluates to an empty hash' do
        expect([].frequencies).to eql({})
      end
    end

    context 'populated collection' do
      it 'counts the number of ocurrences and returns a hash in the form value => count' do
        expect([1, 1, :symbol, 3, 1, :symbol, 'string'].frequencies).to eql(
          1        => 3,
          3        => 1,
          'string' => 1,
          :symbol  => 2
        )
      end
    end
  end
end