summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-24 13:38:01 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-24 13:38:01 +0000
commit46d58ecbe324c9ac2d057f9b262d0e14528a5b25 (patch)
treee297d827bf25831de28a0258a1c6398d952a84e0 /test/ruby
parent7dc0e63f6a4108825839285f024c6cc59aa0b1bd (diff)
downloadruby-46d58ecbe324c9ac2d057f9b262d0e14528a5b25.tar.gz
ruby-46d58ecbe324c9ac2d057f9b262d0e14528a5b25.tar.xz
ruby-46d58ecbe324c9ac2d057f9b262d0e14528a5b25.zip
* test/ruby/test_comparable.rb: new tests for Comparable, to achieve
100% test coverage of compar.c. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_comparable.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb
new file mode 100644
index 000000000..e558b190f
--- /dev/null
+++ b/test/ruby/test_comparable.rb
@@ -0,0 +1,66 @@
+require 'test/unit'
+
+class TestComparable < Test::Unit::TestCase
+ def setup
+ @o = Object.new
+ @o.extend(Comparable)
+ end
+
+ def test_equal
+ def @o.<=>(x); 0; end
+ assert_equal(true, @o == nil)
+ def @o.<=>(x); 1; end
+ assert_equal(false, @o == nil)
+ def @o.<=>(x); raise; end
+ assert_equal(false, @o == nil)
+ end
+
+ def test_gt
+ def @o.<=>(x); 1; end
+ assert_equal(true, @o > nil)
+ def @o.<=>(x); 0; end
+ assert_equal(false, @o > nil)
+ def @o.<=>(x); -1; end
+ assert_equal(false, @o > nil)
+ end
+
+ def test_ge
+ def @o.<=>(x); 1; end
+ assert_equal(true, @o >= nil)
+ def @o.<=>(x); 0; end
+ assert_equal(true, @o >= nil)
+ def @o.<=>(x); -1; end
+ assert_equal(false, @o >= nil)
+ end
+
+ def test_lt
+ def @o.<=>(x); 1; end
+ assert_equal(false, @o < nil)
+ def @o.<=>(x); 0; end
+ assert_equal(false, @o < nil)
+ def @o.<=>(x); -1; end
+ assert_equal(true, @o < nil)
+ end
+
+ def test_le
+ def @o.<=>(x); 1; end
+ assert_equal(false, @o <= nil)
+ def @o.<=>(x); 0; end
+ assert_equal(true, @o <= nil)
+ def @o.<=>(x); -1; end
+ assert_equal(true, @o <= nil)
+ end
+
+ def test_between
+ def @o.<=>(x); 0 <=> x end
+ assert_equal(false, @o.between?(1, 2))
+ assert_equal(false, @o.between?(-2, -1))
+ assert_equal(true, @o.between?(-1, 1))
+ assert_equal(true, @o.between?(0, 0))
+ end
+
+ def test_err
+ assert_raise(ArgumentError) { 1.0 < nil }
+ assert_raise(ArgumentError) { 1.0 < Object.new }
+ end
+end