[270] | 1 |
|
---|
| 2 | assert('Comparable#<', '15.3.3.2.1') do
|
---|
| 3 | class Foo
|
---|
| 4 | include Comparable
|
---|
| 5 | def <=>(x)
|
---|
| 6 | x
|
---|
| 7 | end
|
---|
| 8 | end
|
---|
| 9 | assert_false(Foo.new < 0)
|
---|
| 10 | assert_false(Foo.new < 1)
|
---|
| 11 | assert_true(Foo.new < -1)
|
---|
| 12 | assert_raise(ArgumentError){ Foo.new < nil }
|
---|
| 13 | end
|
---|
| 14 |
|
---|
| 15 | assert('Comparable#<=', '15.3.3.2.2') do
|
---|
| 16 | class Foo
|
---|
| 17 | include Comparable
|
---|
| 18 | def <=>(x)
|
---|
| 19 | x
|
---|
| 20 | end
|
---|
| 21 | end
|
---|
| 22 | assert_true(Foo.new <= 0)
|
---|
| 23 | assert_false(Foo.new <= 1)
|
---|
| 24 | assert_true(Foo.new <= -1)
|
---|
| 25 | assert_raise(ArgumentError){ Foo.new <= nil }
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | assert('Comparable#==', '15.3.3.2.3') do
|
---|
| 29 | class Foo
|
---|
| 30 | include Comparable
|
---|
| 31 | def <=>(x)
|
---|
| 32 | 0
|
---|
| 33 | end
|
---|
| 34 | end
|
---|
| 35 |
|
---|
| 36 | assert_true(Foo.new == Foo.new)
|
---|
| 37 | end
|
---|
| 38 |
|
---|
| 39 | assert('Comparable#>', '15.3.3.2.4') do
|
---|
| 40 | class Foo
|
---|
| 41 | include Comparable
|
---|
| 42 | def <=>(x)
|
---|
| 43 | x
|
---|
| 44 | end
|
---|
| 45 | end
|
---|
| 46 | assert_false(Foo.new > 0)
|
---|
| 47 | assert_true(Foo.new > 1)
|
---|
| 48 | assert_false(Foo.new > -1)
|
---|
| 49 | assert_raise(ArgumentError){ Foo.new > nil }
|
---|
| 50 | end
|
---|
| 51 |
|
---|
| 52 | assert('Comparable#>=', '15.3.3.2.5') do
|
---|
| 53 | class Foo
|
---|
| 54 | include Comparable
|
---|
| 55 | def <=>(x)
|
---|
| 56 | x
|
---|
| 57 | end
|
---|
| 58 | end
|
---|
| 59 | assert_true(Foo.new >= 0)
|
---|
| 60 | assert_true(Foo.new >= 1)
|
---|
| 61 | assert_false(Foo.new >= -1)
|
---|
| 62 | assert_raise(ArgumentError){ Foo.new >= nil }
|
---|
| 63 | end
|
---|
| 64 |
|
---|
| 65 | assert('Comparable#between?', '15.3.3.2.6') do
|
---|
| 66 | class Foo
|
---|
| 67 | include Comparable
|
---|
| 68 | def <=>(x)
|
---|
| 69 | x
|
---|
| 70 | end
|
---|
| 71 | end
|
---|
| 72 |
|
---|
| 73 | c = Foo.new
|
---|
| 74 |
|
---|
| 75 | assert_false(c.between?(-1, 1))
|
---|
| 76 | assert_false(c.between?(-1, -1))
|
---|
| 77 | assert_false(c.between?( 1, 1))
|
---|
| 78 | assert_true(c.between?( 1, -1))
|
---|
| 79 | assert_true(c.between?(0, 0))
|
---|
| 80 | end
|
---|