Sha256: 73d4b0cb91fb6f55cca8f998006e8d9216a505c7390c793404f37e7168e71889
Contents?: true
Size: 949 Bytes
Versions: 1
Compression:
Stored size: 949 Bytes
Contents
require 'spec_helper' sum_expectations = { [] => 0, # see http://en.wikipedia.org/wiki/Empty_sum [1] => 1, [1.0] => 1.0, [1, -1] => 0, [1, 2, 3] => 6, [1, 2, 3.0] => 6.0, (0...0) => 0, # see http://en.wikipedia.org/wiki/Empty_sum (1..1) => 1, (0..3) => 6, [BigDecimal("0.0")] => BigDecimal("0.0"), [3, BigDecimal("1.0")] => BigDecimal("4.0") } describe Enumerable do describe "#sum" do sum_expectations.each do |data, expected| it "is #{expected.inspect} for #{data.inspect}" do sum = data.sum sum.should == expected sum.class.should == expected.class end end it "calls map first if a block is given" do f = Struct.new(:x) data = [f.new(4), f.new(1), f.new(6)] data.sum(&:x).should == 11 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
simple_stats-1.1.0 | spec/enumerable/sum_spec.rb |