diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-03-26 16:29:21 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-26 16:29:21 +0900 |
commit | 9143d21b1bf2f16b1e847d569a588510726d8860 (patch) | |
tree | 8e2d3e939c64a5bd29c26e4416e753b89cfb5333 /spec/ruby/core | |
parent | 6a352e275bfdad84bec479b84dd2bc6d76697226 (diff) | |
download | ruby-9143d21b1bf2f16b1e847d569a588510726d8860.tar.gz |
Enumerable#tally with the resulting hash [Feature #17744]
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/enumerable/tally_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb index 363b3def21..1367453f44 100644 --- a/spec/ruby/core/enumerable/tally_spec.rb +++ b/spec/ruby/core/enumerable/tally_spec.rb @@ -33,3 +33,31 @@ ruby_version_is "2.7" do end end end + +ruby_version_is "3.1" do + describe "Enumerable#tally with a hash" 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({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} + end + + it "ignores the default value" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} + end + + it "ignores the default proc" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + enum.tally(Hash.new {100}).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1} + end + + it "needs the values counting each elements to be an integer" do + enum = EnumerableSpecs::Numerous.new('foo') + -> { enum.tally({ 'foo' => 'bar' }) }.should raise_error(TypeError) + end + end +end |