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

ruby-changes:33996

From: akr <ko1@a...>
Date: Sat, 24 May 2014 18:46:06 +0900 (JST)
Subject: [ruby-changes:33996] akr:r46077 (trunk): * test/benchmark/test_benchmark.rb: Use test/unit.

akr	2014-05-24 18:46:02 +0900 (Sat, 24 May 2014)

  New Revision: 46077

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46077

  Log:
    * test/benchmark/test_benchmark.rb: Use test/unit.

  Modified files:
    trunk/ChangeLog
    trunk/test/benchmark/test_benchmark.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46076)
+++ ChangeLog	(revision 46077)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May 24 18:45:30 2014  Tanaka Akira  <akr@f...>
+
+	* test/benchmark/test_benchmark.rb: Use test/unit.
+
 Sat May 24 16:20:59 2014  Eric Wong  <e@8...>
 
 	* process.c (proc_getgroups, proc_setgroups): use ALLOCV_N
Index: test/benchmark/test_benchmark.rb
===================================================================
--- test/benchmark/test_benchmark.rb	(revision 46076)
+++ test/benchmark/test_benchmark.rb	(revision 46077)
@@ -1,10 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/test/benchmark/test_benchmark.rb#L1
-require 'minitest/spec'
+require 'test/unit'
 require 'benchmark'
 
-MiniTest::Unit.autorun
-
-describe Benchmark do
-  bench_for_times_upto = lambda do |x|
+class TestBenchmark < Test::Unit::TestCase
+  BENCH_FOR_TIMES_UPTO = lambda do |x|
     n = 1000
     tf = x.report("for:")   { for _ in 1..n; '1'; end }
     tt = x.report("times:") { n.times do   ; '1'; end }
@@ -12,7 +10,7 @@ describe Benchmark do https://github.com/ruby/ruby/blob/trunk/test/benchmark/test_benchmark.rb#L10
     [tf+tt+tu, (tf+tt+tu)/3]
   end
 
-  bench_for_times_upto_no_label = lambda do |x|
+  BENCH_FOR_TIMES_UPTO_NO_LABEL = lambda do |x|
     n = 1000
     x.report { for _ in 1..n; '1'; end }
     x.report { n.times do   ; '1'; end }
@@ -43,25 +41,23 @@ describe Benchmark do https://github.com/ruby/ruby/blob/trunk/test/benchmark/test_benchmark.rb#L41
     capture_output { bench(type, *args, &block) }
   end
 
-  describe 'Tms' do
-    it 'outputs nicely' do
-      Benchmark::Tms.new.to_s.must_equal            "  0.000000   0.000000   0.000000 (  0.000000)\n"
-      Benchmark::Tms.new(1,2,3,4,5).to_s.must_equal "  1.000000   2.000000  10.000000 (  5.000000)\n"
-      Benchmark::Tms.new(1,2,3,4,5,'label').format('%u %y %U %Y %t %r %n').must_equal \
-        "1.000000 2.000000 3.000000 4.000000 10.000000 (5.000000) label"
-      Benchmark::Tms.new(1).format('%u %.3f', 2).must_equal "1.000000 2.000"
-      Benchmark::Tms.new(100, 150, 0, 0, 200).to_s.must_equal \
-        "100.000000 150.000000 250.000000 (200.000000)\n"
-    end
-
-    it 'wont modify the format String given' do
-      format = "format %u"
-      Benchmark::Tms.new.format(format)
-      format.must_equal "format %u"
-    end
+  def test_tms_outputs_nicely
+    assert_equal("  0.000000   0.000000   0.000000 (  0.000000)\n", Benchmark::Tms.new.to_s)
+    assert_equal("  1.000000   2.000000  10.000000 (  5.000000)\n", Benchmark::Tms.new(1,2,3,4,5).to_s)
+    assert_equal("1.000000 2.000000 3.000000 4.000000 10.000000 (5.000000) label",
+                 Benchmark::Tms.new(1,2,3,4,5,'label').format('%u %y %U %Y %t %r %n'))
+    assert_equal("1.000000 2.000", Benchmark::Tms.new(1).format('%u %.3f', 2))
+    assert_equal("100.000000 150.000000 250.000000 (200.000000)\n",
+                 Benchmark::Tms.new(100, 150, 0, 0, 200).to_s)
+  end
+
+  def test_tms_wont_modify_the_format_String_given
+    format = "format %u"
+    Benchmark::Tms.new.format(format)
+    assert_equal("format %u", format)
   end
 
-  benchmark_output_with_total_avg = <<BENCH
+  BENCHMARK_OUTPUT_WITH_TOTAL_AVG = <<BENCH
               user     system      total        real
 for:      --time--   --time--   --time-- (  --time--)
 times:    --time--   --time--   --time-- (  --time--)
@@ -70,64 +66,61 @@ upto:     --time--   --time--   --time-- https://github.com/ruby/ruby/blob/trunk/test/benchmark/test_benchmark.rb#L66
 >avg:     --time--   --time--   --time-- (  --time--)
 BENCH
 
-  describe 'benchmark' do
-    it 'does not print any space if the given caption is empty' do
-      capture_bench_output(:benchmark).must_equal <<-BENCH
+  def test_benchmark_does_not_print_any_space_if_the_given_caption_is_empty
+    assert_equal(<<-BENCH, capture_bench_output(:benchmark))
 first  --time--   --time--   --time-- (  --time--)
 second  --time--   --time--   --time-- (  --time--)
 third  --time--   --time--   --time-- (  --time--)
 BENCH
-    end
+  end
 
-    it 'makes extra calcultations with an Array at the end of the benchmark and show the result' do
+  def test_benchmark_makes_extra_calcultations_with_an_Array_at_the_end_of_the_benchmark_and_show_the_result
+    assert_equal(BENCHMARK_OUTPUT_WITH_TOTAL_AVG,
       capture_bench_output(:benchmark,
         Benchmark::CAPTION, 7,
         Benchmark::FORMAT, ">total:", ">avg:",
-        &bench_for_times_upto).must_equal benchmark_output_with_total_avg
-    end
+        &BENCH_FOR_TIMES_UPTO))
   end
 
-  describe 'bm' do
-    it "returns an Array of the times with the labels" do
-      [:bm, :bmbm].each do |meth|
-        capture_io do
-          results = bench(meth)
-          results.must_be_instance_of Array
-          results.size.must_equal labels.size
-          results.zip(labels).each { |tms, label|
-            tms.must_be_instance_of Benchmark::Tms
-            tms.label.must_equal label
-          }
-        end
+  def test_bm_returns_an_Array_of_the_times_with_the_labels
+    [:bm, :bmbm].each do |meth|
+      capture_io do
+        results = bench(meth)
+        assert_instance_of(Array, results)
+        assert_equal(labels.size, results.size)
+        results.zip(labels).each { |tms, label|
+          assert_instance_of(Benchmark::Tms, tms)
+          assert_equal(label, tms.label)
+        }
       end
     end
+  end
 
-    it 'correctly output when the label width is given' do
-      capture_bench_output(:bm, 6).must_equal <<-BENCH
+  def test_bm_correctly_output_when_the_label_width_is_given
+    assert_equal(<<-BENCH, capture_bench_output(:bm, 6))
              user     system      total        real
 first    --time--   --time--   --time-- (  --time--)
 second   --time--   --time--   --time-- (  --time--)
 third    --time--   --time--   --time-- (  --time--)
 BENCH
-    end
+  end
 
-    it 'correctly output when no label is given' do
-      capture_bench_output(:bm, &bench_for_times_upto_no_label).must_equal <<-BENCH
+  def test_bm_correctly_output_when_no_label_is_given
+    assert_equal(<<-BENCH, capture_bench_output(:bm, &BENCH_FOR_TIMES_UPTO_NO_LABEL))
        user     system      total        real
    --time--   --time--   --time-- (  --time--)
    --time--   --time--   --time-- (  --time--)
    --time--   --time--   --time-- (  --time--)
 BENCH
-    end
+  end
 
-    it 'can make extra calcultations with an array at the end of the benchmark' do
+  def test_bm_can_make_extra_calcultations_with_an_array_at_the_end_of_the_benchmark
+    assert_equal(BENCHMARK_OUTPUT_WITH_TOTAL_AVG,
       capture_bench_output(:bm, 7, ">total:", ">avg:",
-        &bench_for_times_upto).must_equal benchmark_output_with_total_avg
-    end
+        &BENCH_FOR_TIMES_UPTO))
   end
 
-  describe 'bmbm' do
-    bmbm_output = <<BENCH
+  BMBM_OUTPUT = <<BENCH
 Rehearsal ------------------------------------------
 first    --time--   --time--   --time-- (  --time--)
 second   --time--   --time--   --time-- (  --time--)
@@ -140,30 +133,23 @@ second   --time--   --time--   --time-- https://github.com/ruby/ruby/blob/trunk/test/benchmark/test_benchmark.rb#L133
 third    --time--   --time--   --time-- (  --time--)
 BENCH
 
-    it 'correctly guess the label width even when not given' do
-      capture_bench_output(:bmbm).must_equal bmbm_output
-    end
+  def test_bmbm_correctly_guess_the_label_width_even_when_not_given
+    assert_equal(BMBM_OUTPUT, capture_bench_output(:bmbm))
+  end
 
-    it 'correctly output when the label width is given (bmbm ignore it, but it is a frequent mistake)' do
-      capture_bench_output(:bmbm, 6).must_equal bmbm_output
-    end
+  def test_bmbm_correctly_output_when_the_label_width_is_given__bmbm_ignore_it__but_it_is_a_frequent_mistake
+    assert_equal(BMBM_OUTPUT, capture_bench_output(:bmbm, 6))
   end
 
-  describe 'Report' do
-    describe '#item' do
-      it 'shows the title, even if not a string' do
-        capture_bench_output(:bm) { |x| x.report(:title) {} }.must_include 'title'
-        capture_bench_output(:bmbm) { |x| x.report(:title) {} }.must_include 'title'
-      end
-    end
+  def test_report_item_shows_the_title__even_if_not_a_string
+    assert_operator(capture_bench_output(:bm) { |x| x.report(:title) {} }, :include?, 'title')
+    assert_operator(capture_bench_output(:bmbm) { |x| x.report(:title) {} }, :include?, 'title')
   end
 
-  describe 'Bugs' do
-    it '[ruby-dev:40906] can add in-place the time of execution of the block given' do
-      t = Benchmark::Tms.new
-      t.real.must_equal 0
-      t.add! { sleep 0.1 }
-      t.real.wont_equal 0
-    end
+  def test_bugs_ruby_dev_40906_can_add_in_place_the_time_of_execution_of_the_block_given
+    t = Benchmark::Tms.new
+    assert_equal(0, t.real)
+    t.add! { sleep 0.1 }
+    assert_not_equal(0, t.real)
   end
 end

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

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