diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-30 04:02:17 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-30 04:02:17 +0000 |
commit | d84d0f27b94a43d8dc15b1ff04b5739f01eb3d99 (patch) | |
tree | c01490cdbdd0044cbf2bcc016daa822556208aaf /test/ruby | |
parent | c249453c2a0217deb75ffb0803df118526e68a0c (diff) | |
download | ruby-d84d0f27b94a43d8dc15b1ff04b5739f01eb3d99.tar.gz |
test_range.rb: all assertions
* test/ruby/test_range.rb (test_range_bsearch_for_floats): test
all assertions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_range.rb | 109 |
1 files changed, 60 insertions, 49 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index bba7726112..cfd8b502ed 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -521,20 +521,22 @@ class TestRange < Test::Unit::TestCase assert_in_delta(7.0, (0.0..10).bsearch {|x| 7.0 - x }) end - def check_bsearch_values(range, search) + def check_bsearch_values(range, search, a) from, to = range.begin, range.end cmp = range.exclude_end? ? :< : :<= + r = nil - # (0) trivial test - r = Range.new(to, from, range.exclude_end?).bsearch do |x| - fail "#{to}, #{from}, #{range.exclude_end?}, #{x}" - end - assert_equal nil, r + a.for "(0) trivial test" do + r = Range.new(to, from, range.exclude_end?).bsearch do |x| + fail "#{to}, #{from}, #{range.exclude_end?}, #{x}" + end + assert_nil r - r = (to...to).bsearch do - fail + r = (to...to).bsearch do + fail + end + assert_nil r end - assert_equal nil, r # prepare for others yielded = [] @@ -543,46 +545,53 @@ class TestRange < Test::Unit::TestCase val >= search end - # (1) log test - max = case from - when Float then 65 - when Integer then Math.log(to-from+(range.exclude_end? ? 0 : 1), 2).to_i + 1 - end - assert_operator yielded.size, :<=, max - - # (2) coverage test - expect = if search < from - from - elsif search.send(cmp, to) - search - else - nil - end - assert_equal expect, r - - # (3) uniqueness test - assert_equal nil, yielded.uniq! - - # (4) end of range test - case - when range.exclude_end? - assert_not_include yielded, to - assert_not_equal r, to - when search >= to - assert_include yielded, to - assert_equal search == to ? to : nil, r + a.for "(1) log test" do + max = case from + when Float then 65 + when Integer then Math.log(to-from+(range.exclude_end? ? 0 : 1), 2).to_i + 1 + end + assert_operator yielded.size, :<=, max + end + + a.for "(2) coverage test" do + expect = case + when search < from + from + when search.send(cmp, to) + search + else + nil + end + assert_equal expect, r + end + + a.for "(3) uniqueness test" do + assert_nil yielded.uniq! + end + + a.for "(4) end of range test" do + case + when range.exclude_end? + assert_not_include yielded, to + assert_not_equal r, to + when search >= to + assert_include yielded, to + assert_equal search == to ? to : nil, r + end end - # start of range test - if search <= from - assert_include yielded, from - assert_equal from, r + a.for "(5) start of range test" do + if search <= from + assert_include yielded, from + assert_equal from, r + end end - # (5) out of range test - yielded.each do |val| - assert_operator from, :<=, val - assert_send [val, cmp, to] + a.for "(6) out of range test" do + yielded.each do |val| + assert_operator from, :<=, val + assert_send [val, cmp, to] + end end end @@ -590,10 +599,12 @@ class TestRange < Test::Unit::TestCase ints = [-1 << 100, -123456789, -42, -1, 0, 1, 42, 123456789, 1 << 100] floats = [-Float::INFINITY, -Float::MAX, -42.0, -4.2, -Float::EPSILON, -Float::MIN, 0.0, Float::MIN, Float::EPSILON, Math::PI, 4.2, 42.0, Float::MAX, Float::INFINITY] - [ints, floats].each do |values| - values.combination(2).to_a.product(values).each do |(from, to), search| - check_bsearch_values(from..to, search) - check_bsearch_values(from...to, search) + all_assertions do |a| + [ints, floats].each do |values| + values.combination(2).to_a.product(values).each do |(from, to), search| + check_bsearch_values(from..to, search, a) + check_bsearch_values(from...to, search, a) + end end end end |