fedora-migrator /vendor/gems/facets-2.4.5/test/more/test_interval.rb

Language Ruby Lines 152
MD5 Hash 6e87a528ed9d2ff3d95a60cc863c0285 Estimated Cost $2,738 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
  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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Test facets/interval.rb

require 'facets/interval.rb'

require 'test/unit'

class InclusiveTest < Test::Unit::TestCase

  def setup
    @a = Interval.new( 1, 10 )
    @b = Interval.new( 1, 10, true, false )
    @c = Interval.new( 1, 10, false, true )
    @d = Interval.new( 1, 10, true, true )
  end

  def test_001A ; assert_equal( false, @a.include?(0)  ) ; end
  def test_002A ; assert_equal( true,  @a.include?(1)  ) ; end
  def test_003A ; assert_equal( true,  @a.include?(2)  ) ; end
  def test_004A ; assert_equal( true,  @a.include?(9)  ) ; end
  def test_005A ; assert_equal( true,  @a.include?(10) ) ; end
  def test_006A ; assert_equal( false, @a.include?(11) ) ; end

  def test_001B ; assert_equal( false, @b.include?(0)  ) ; end
  def test_002B ; assert_equal( false, @b.include?(1)  ) ; end
  def test_003B ; assert_equal( true,  @b.include?(2)  ) ; end
  def test_004B ; assert_equal( true,  @b.include?(9)  ) ; end
  def test_005B ; assert_equal( true,  @b.include?(10) ) ; end
  def test_006B ; assert_equal( false, @b.include?(11) ) ; end

  def test_001C ; assert_equal( false, @c.include?(0)  ) ; end
  def test_002C ; assert_equal( true,  @c.include?(1)  ) ; end
  def test_003C ; assert_equal( true,  @c.include?(2)  ) ; end
  def test_004C ; assert_equal( true,  @c.include?(9)  ) ; end
  def test_005C ; assert_equal( false, @c.include?(10) ) ; end
  def test_006C ; assert_equal( false, @c.include?(11) ) ; end

  def test_001D ; assert_equal( false, @d.include?(0)  ) ; end
  def test_002D ; assert_equal( false, @d.include?(1)  ) ; end
  def test_003D ; assert_equal( true,  @d.include?(2)  ) ; end
  def test_004D ; assert_equal( true,  @d.include?(9)  ) ; end
  def test_005D ; assert_equal( false, @d.include?(10) ) ; end
  def test_006D ; assert_equal( false, @d.include?(11) ) ; end

end

class LrgNumericTest < Test::Unit::TestCase

  def setup
    @a = Interval.new(0,100000000)
    @b = Interval.new(0,100000000)
  end

  def test_001A ; assert_equal( true,  @a.include?(0)         ) ; end
  def test_002A ; assert_equal( true,  @a.include?(1000)      ) ; end
  def test_003A ; assert_equal( true,  @a.include?(1000000)   ) ; end
  def test_004A ; assert_equal( true,  @a.include?(100000000) ) ; end
  #def test_005A ; assert_equal( false, @a.include?(INFINITY)  ) ; end

  def test_001B ; assert_equal( true,  @b.include?(0)         ) ; end
  def test_002B ; assert_equal( true,  @b.include?(5)         ) ; end
  def test_003B ; assert_equal( true,  @b.include?(70007)     ) ; end
  def test_004B ; assert_equal( true,  @b.include?(5000005)   ) ; end
  #def test_005B ; assert_equal( false, @b.include?(INFINITY)  ) ; end

end

class TC_SelectTest < Test::Unit::TestCase

  def setup
    @a = Interval.new( 0,10 )
  end

  def test_001
    b = @a.collect( 2 ){ |n| n }
    assert_equal( [0,2,4,6,8,10], b )
  end

  def test_002
    b = @a.select{ |n| n % 2 == 0 }
    assert_equal( [0,2,4,6,8,10], b )
  end

  def test_003
    b = @a.collect( 1,2 ){ |n| n }
    assert_equal( [0,5,10], b )
  end

  def test_004
    b = @a.select( 1,2 ){ |n| n % 2 == 0 }
    assert_equal( [0,10], b )
  end

end

class ArrayTest < Test::Unit::TestCase

  def setup
    @a = Interval.new( 0,10 )
    @b = Interval.new( 0,1 )
  end

  def test_001A ; assert_equal( [0,5,10], @a.to_a(1,2) ) ; end

  def test_001B ; assert_equal( [0, 0.25, 0.5, 0.75, 1.0], @b.to_a(1,4) ) ; end

end


=begin
  class InfTest < Test::Unit::TestCase

    def setup
      @a = Interval.new( -INFINITY, -3 )
      @b = Interval.new( -INFINITY, -3, true, false )
      @c = Interval.new( -3, INFINITY )
      @d = Interval.new( -INFINITY, INFINITY )
      @e = Interval.new( -3, -2 )
    end

    def test_001A ; assert_equal( true,  @a.include?(-INFINITY) ) ; end
    def test_002A ; assert_equal( true,  @a.include?(-4)        ) ; end
    def test_003A ; assert_equal( true,  @a.include?(-3)        ) ; end
    def test_004A ; assert_equal( false, @a.include?(-2)        ) ; end
    def test_005A ; assert_equal( false, @a.include?(INFINITY)  ) ; end

    def test_001B ; assert_equal( true,  @b.include?(-INFINITY) ) ; end
    def test_002B ; assert_equal( true,  @b.include?(-4)        ) ; end
    def test_003B ; assert_equal( false, @b.include?(-3)        ) ; end
    def test_004B ; assert_equal( false, @b.include?(-2)        ) ; end
    def test_005B ; assert_equal( false, @b.include?(INFINITY)  ) ; end

    def test_001C ; assert_equal( false, @c.include?(-INFINITY) ) ; end
    def test_002C ; assert_equal( false, @c.include?(-4)        ) ; end
    def test_003C ; assert_equal( true,  @c.include?(-3)        ) ; end
    def test_004C ; assert_equal( true,  @c.include?(-2)        ) ; end
    def test_005C ; assert_equal( true,  @c.include?(INFINITY)  ) ; end

    def test_001D ; assert_equal( true,  @d.include?(-INFINITY) ) ; end
    def test_002D ; assert_equal( true,  @d.include?(-4)        ) ; end
    def test_003D ; assert_equal( true,  @d.include?(-3)        ) ; end
    def test_004D ; assert_equal( true,  @d.include?(-2)        ) ; end
    def test_005D ; assert_equal( true,  @d.include?(INFINITY)  ) ; end

    def test_001E ; assert_equal( false, @e.include?(-INFINITY) ) ; end
    def test_002E ; assert_equal( false, @e.include?(-4)        ) ; end
    def test_003E ; assert_equal( true,  @e.include?(-3)        ) ; end
    def test_004E ; assert_equal( true,  @e.include?(-2)        ) ; end
    def test_005E ; assert_equal( false, @e.include?(INFINITY)  ) ; end

  end
=end
Back to Top