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

ruby-changes:4351

From: ko1@a...
Date: Wed, 26 Mar 2008 00:57:03 +0900 (JST)
Subject: [ruby-changes:4351] mame - Ruby:r15841 (trunk): * test/ruby/test_rand.rb: add tests to achieve over 95% test coverage

mame	2008-03-26 00:56:36 +0900 (Wed, 26 Mar 2008)

  New Revision: 15841

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_rand.rb

  Log:
    * test/ruby/test_rand.rb: add tests to achieve over 95% test coverage
      of random.c.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_rand.rb?r1=15841&r2=15840&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15841&r2=15840&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15840)
+++ ChangeLog	(revision 15841)
@@ -1,3 +1,8 @@
+Wed Mar 26 00:55:28 2008  Yusuke Endoh  <mame@t...>
+
+	* test/ruby/test_rand.rb: add tests to achieve over 95% test coverage
+	  of random.c.
+
 Wed Mar 26 00:28:55 2008  Yusuke Endoh  <mame@t...>
 
 	* test/ruby/test_rational.rb: add tests to achieve over 90% test
Index: test/ruby/test_rand.rb
===================================================================
--- test/ruby/test_rand.rb	(revision 15840)
+++ test/ruby/test_rand.rb	(revision 15841)
@@ -128,4 +128,40 @@
     ws.each {|w| assert_equal(w.to_i, rand(-0x10000)) }
   end
 
+  def test_types
+    srand(0)
+    assert_equal(44, rand(100.0))
+    assert_equal(1245085576965981900420779258691, rand((2**100).to_f))
+    assert_equal(914679880601515615685077935113, rand(-(2**100).to_f))
+
+    srand(0)
+    assert_equal(997707939797331598305742933184, rand(2**100))
+    assert_in_delta(0.602763376071644, rand((2**100).coerce(0).first),
+                    0.000000000000001)
+
+    srand(0)
+    assert_in_delta(0.548813503927325, rand(nil),
+                    0.000000000000001)
+    srand(0)
+    o = Object.new
+    def o.to_i; 100; end
+    assert_equal(44, rand(o))
+    assert_equal(47, rand(o))
+    assert_equal(64, rand(o))
+  end
+
+  def test_srand
+    srand
+    assert_kind_of(Integer, rand(2))
+
+    srand(2**100)
+    %w(3258412053).each {|w|
+      assert_equal(w.to_i, rand(0x100000000))
+    }
+  end
+
+  def test_shuffle
+    srand(0)
+    assert_equal([1,4,2,5,3], [1,2,3,4,5].shuffle)
+  end
 end

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

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