File: test_comparable.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (71 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'test/unit'


class TestComparable < Test::Unit::TestCase

  class C
    include Comparable
    attr :val
    def initialize(val)
      @val = val
    end
    def <=>(other)
      @val <=> other.val
    end
  end

  def setup
    @a = C.new(1)
    @b = C.new(2)
    @c = C.new(1)
    @d = C.new(3)
  end

  def test_00_sanity
    assert_equal( 0, @a <=> @a)
    assert_equal( 0, @a <=> @c)
    assert_equal(-1, @a <=> @b)
    assert_equal( 1, @b <=> @a)
  end

  def test_EQUAL # '=='
    assert(  @a == @a)
    assert(  @a == @c)
    assert(!(@a == @b))
    assert(  @a != @b)
  end

  def test_GE # '>='
    assert(!(@a >= @b))
    assert( (@a >= @a))
    assert( (@b >= @a))
  end

  def test_GT # '>'
    assert(!(@a > @b))
    assert(!(@a > @a))
    assert( (@b > @a))
  end

  def test_LE # '<='
    assert( (@a <= @b))
    assert( (@a <= @a))
    assert(!(@b <= @a))
  end

  def test_LT # '<'
    assert( (@a < @b))
    assert(!(@a < @a))
    assert(!(@b < @a))
  end

  def test_between?
    assert( @a.between?(@a, @c))
    assert(!@a.between?(@b, @c))
    assert( @b.between?(@a, @b))
    assert( @b.between?(@a, @d))
    assert(!@d.between?(@a, @b))
    assert(!@d.between?(@b, @b))
  end

end