diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-11 07:24:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-11 07:24:25 +0000 |
commit | 90bc4136ac1de574a78fb3d1b0cfe2e5049446e2 (patch) | |
tree | 270ff42cf910d737720c5d8f4fd3c9b43f0e5249 /test | |
parent | 81c1b12a37fbbe97a7dc17a7a9ede2cbef13b094 (diff) | |
download | ruby-90bc4136ac1de574a78fb3d1b0cfe2e5049446e2.tar.gz |
Comparable#clamp
* compar.c (cmp_clamp): Introduce Comparable#clamp. [Feature #10594]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_comparable.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb index 7624ef2bd3..f35719a9cb 100644 --- a/test/ruby/test_comparable.rb +++ b/test/ruby/test_comparable.rb @@ -76,6 +76,20 @@ class TestComparable < Test::Unit::TestCase assert_equal(true, @o.between?(0, 0)) end + def test_clamp + cmp->(x) do 0 <=> x end + assert_equal(1, @o.clamp(1, 2)) + assert_equal(-1, @o.clamp(-2, -1)) + assert_equal(0, @o.clamp(-1, 3)) + + assert_equal(1, @o.clamp(1, 1)) + assert_equal(0, @o.clamp(0, 0)) + + assert_raise_with_message(ArgumentError, 'min argument must be smaller than max argument') { + @o.clamp(2, 1) + } + end + def test_err assert_raise(ArgumentError) { 1.0 < nil } assert_raise(ArgumentError) { 1.0 < Object.new } |