File: tally_spec.rb

package info (click to toggle)
ruby2.7 2.7.4-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,576 kB
  • sloc: ruby: 849,454; ansic: 697,834; yacc: 45,100; xml: 25,367; pascal: 10,051; javascript: 6,575; sh: 3,848; makefile: 759; cpp: 713; asm: 333; python: 295; lisp: 97; sed: 94; perl: 62; awk: 36
file content (35 lines) | stat: -rw-r--r-- 1,155 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
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "2.7" do
  describe "Enumerable#tally" do
    before :each do
      ScratchPad.record []
    end

    it "returns a hash with counts according to the value" do
      enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
      enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
    end

    it "returns a hash without default" do
      hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
      hash.default_proc.should be_nil
      hash.default.should be_nil
    end

    it "returns an empty hash for empty enumerables" do
      EnumerableSpecs::Empty.new.tally.should == {}
    end

    it "counts values as gathered array when yielded with multiple arguments" do
      EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
    end

    it "does not call given block" do
      enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
      enum.tally { |v| ScratchPad << v }
      ScratchPad.recorded.should == []
    end
  end
end