summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 07:24:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-11 07:24:25 +0000
commitd5a0b8e3cc48632d0cb99553a7aaf233b22a1eac (patch)
tree270ff42cf910d737720c5d8f4fd3c9b43f0e5249 /test
parentb8ad953501420d60cb820bda157dbe095a9469d0 (diff)
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.rb14
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 }