Class: Interval::TestMethods

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
Assertions
Defined in:
lib/interval.rb

Overview

Tests other Interval methods.

Instance Method Summary collapse

Methods included from Assertions

#assert_fuzzy, #assert_include, #assert_outside, #assert_sharp, #assert_solution, #assert_subset

Instance Method Details

#test_conversion_from_rangeObject



1013
1014
1015
1016
1017
1018
# File 'lib/interval.rb', line 1013

def test_conversion_from_range
  assert_equal(Interval[1.2, 5.3], (1.2 .. 5.3).to_interval)
  assert_equal(Interval[1, 4], (1 .. 4).to_interval)
  assert_equal(Interval[1, 3], (1 ... 4).to_interval)
  assert_raise(NoMethodError){ (1 ... 3.1).to_interval }
end

#test_empty?Boolean

Returns:

  • (Boolean)


984
985
986
987
988
# File 'lib/interval.rb', line 984

def test_empty?
  assert(!Interval[1,2].empty?)
  assert(!Interval[[1,2],[4,3]].empty?)
  assert(Interval[].empty?)
end

#test_hullObject



1007
1008
1009
1010
1011
# File 'lib/interval.rb', line 1007

def test_hull
  assert_equal(Interval[1,4], Interval[[1,2],[3,4]].hull)
  assert_equal(Interval[1,4], Interval[1,4].hull)
  assert_equal(Interval[], Interval[].hull)
end

#test_include?Boolean

Returns:

  • (Boolean)


971
972
973
974
975
976
977
# File 'lib/interval.rb', line 971

def test_include?
  assert_include(Interval[1,2], 1.5)
  assert_include(Interval[1,2], 1)
  assert_include(Interval[1,2], 2)
  assert_outside(Interval[1,2], 0)
  assert_outside(Interval[1,2], 4)
end

#test_sharp?Boolean

Returns:

  • (Boolean)


990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
# File 'lib/interval.rb', line 990

def test_sharp?
  assert_sharp(Interval[5,5])
  assert_sharp(Interval[[1],[2]])
  assert_fuzzy(Interval[[1],[2,3]])
  assert_fuzzy(Interval[5,6])
  assert_fuzzy(Interval[1.1,1.2])
  assert_fuzzy(Interval[Struct::Float[-1,0,1].to_f,Struct::Float[+1,0,1].to_f])
  assert_sharp(Interval[Struct::Float[1,1022,2**52-1].to_f,1])
  assert_sharp(Interval[Struct::Float[1,1029,2**52-1].to_f,128])
  assert_sharp(Interval[-0.0,0.0])
  assert_sharp(Interval[0.0,Struct::Float[1,0,1].to_f])
  assert_sharp(Interval[6369051672525772, 6369051672525773] * 2.0 ** -52)
  assert_sharp(Interval[6369051672525772, 6369051672525772] * 2.0 ** -52)
  assert_fuzzy(Interval[6369051672525771, 6369051672525773] * 2.0 ** -52)
  assert_fuzzy(Interval[6369051672525771, 6369051672525785] * 2.0 ** -52)
end

#test_simple?Boolean

Returns:

  • (Boolean)


979
980
981
982
# File 'lib/interval.rb', line 979

def test_simple?
  assert(Interval[1,2].simple?)
  assert(!Interval[[1,2],[3,4]].simple?)
end