Skip to content

Commit 450307e

Browse files
committed
* enum.c (nmin_run): max(n) and max_by(n) returns an array in
descending order. [ruby-core:65452] Suggested by David Grayson. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 63fa57e commit 450307e

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Tue Oct 14 01:27:54 2014 Tanaka Akira <akr@fsij.org>
2+
3+
* enum.c (nmin_run): max(n) and max_by(n) returns an array in
4+
descending order.
5+
[ruby-core:65452] Suggested by David Grayson.
6+
17
Mon Oct 13 20:44:49 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
28

39
* common.mk (update-gems): chdir to the target directory and then

enum.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,9 @@ nmin_run(VALUE obj, VALUE num, int by, int rev)
12841284
ruby_qsort(RARRAY_PTR(result), RARRAY_LEN(result), sizeof(VALUE),
12851285
data.cmpfunc, (void *)&data);
12861286
}
1287+
if (rev) {
1288+
rb_ary_reverse(result);
1289+
}
12871290
*((VALUE *)&RBASIC(result)->klass) = rb_cArray;
12881291
return result;
12891292

test/ruby/test_enum.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ def test_max
245245
assert_equal("horse", ary.max)
246246
assert_equal("albatross", ary.max {|a,b| a.length <=> b.length })
247247
assert_equal(1, [3,2,1].max{|a,b| b <=> a })
248-
assert_equal(%w[dog horse], ary.max(2))
249-
assert_equal(%w[horse albatross],
248+
assert_equal(%w[horse dog], ary.max(2))
249+
assert_equal(%w[albatross horse],
250250
ary.max(2) {|a,b| a.length <=> b.length })
251251
end
252252

@@ -278,7 +278,7 @@ def test_max_by
278278
a = %w(albatross dog horse)
279279
assert_equal("albatross", a.max_by {|x| x.length })
280280
assert_equal(1, [2,3,1].max_by {|x| -x })
281-
assert_equal(%w[horse albatross], a.max_by(2) {|x| x.length })
281+
assert_equal(%w[albatross horse], a.max_by(2) {|x| x.length })
282282
end
283283

284284
def test_minmax_by

test/ruby/test_range.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def test_max
8181
assert_equal(0, (0..0).max)
8282
assert_equal(nil, (0...0).max)
8383

84-
assert_equal([8,9,10], (0..10).max(3))
85-
assert_equal([7,8,9], (0...10).max(3))
84+
assert_equal([10,9,8], (0..10).max(3))
85+
assert_equal([9,8,7], (0...10).max(3))
8686
end
8787

8888
def test_initialize_twice

0 commit comments

Comments
 (0)