[前][次][番号順一覧][スレッド一覧]

ruby-changes:44223

From: nobu <ko1@a...>
Date: Fri, 30 Sep 2016 13:02:27 +0900 (JST)
Subject: [ruby-changes:44223] nobu:r56295 (trunk): test_range.rb: all assertions

nobu	2016-09-30 13:02:17 +0900 (Fri, 30 Sep 2016)

  New Revision: 56295

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56295

  Log:
    test_range.rb: all assertions
    
    * test/ruby/test_range.rb (test_range_bsearch_for_floats): test
      all assertions.

  Modified files:
    trunk/test/ruby/test_range.rb
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 56294)
+++ test/ruby/test_range.rb	(revision 56295)
@@ -521,20 +521,22 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L521
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L545
       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
-    end
-
-    # start of range test
-    if search <= from
-      assert_include yielded, from
-      assert_equal from, r
-    end
-
-    # (5) out of range test
-    yielded.each do |val|
-      assert_operator from, :<=, val
-      assert_send [val, cmp, to]
+    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
+
+    a.for "(5) start of range test" do
+      if search <= from
+        assert_include yielded, from
+        assert_equal from, r
+      end
+    end
+
+    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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L599
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]