aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-06-24 16:14:59 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-06-24 16:14:59 +0000
commitfd0eaaa407fb8fd704967be2734c1b094ac630d9 (patch)
treee6b8d271e1f70ab38a15faafde16f80abd6e1322 /activesupport/test
parent8b89bd779a1ddc78da63de295574b8519c3e94c8 (diff)
downloadrails-fd0eaaa407fb8fd704967be2734c1b094ac630d9.tar.gz
rails-fd0eaaa407fb8fd704967be2734c1b094ac630d9.tar.bz2
rails-fd0eaaa407fb8fd704967be2734c1b094ac630d9.zip
Added Enumerable#sum for calculating a sum from the elements [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4489 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index df14200e42..882111cd79 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -1,8 +1,9 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/enumerable'
+Payment = Struct.new(:price)
+
class EnumerableTests < Test::Unit::TestCase
-
def test_group_by
names = %w(marcel sam david jeremy)
klass = Class.new
@@ -17,4 +18,10 @@ class EnumerableTests < Test::Unit::TestCase
assert group.all? {|person| person.name == name}
end
end
+
+ def test_sums
+ payments = [ Payment.new(5), Payment.new(15), Payment.new(10) ]
+ assert_equal 30, payments.sum(&:price)
+ assert_equal 60, payments.sum { |p| p.price * 2 }
+ end
end