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

ruby-changes:32925

From: akr <ko1@a...>
Date: Sun, 16 Feb 2014 17:34:38 +0900 (JST)
Subject: [ruby-changes:32925] akr:r45004 (trunk): add tests.

akr	2014-02-16 17:34:33 +0900 (Sun, 16 Feb 2014)

  New Revision: 45004

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

  Log:
    add tests.

  Modified files:
    trunk/test/-ext-/bignum/test_pack.rb
Index: test/-ext-/bignum/test_pack.rb
===================================================================
--- test/-ext-/bignum/test_pack.rb	(revision 45003)
+++ test/-ext-/bignum/test_pack.rb	(revision 45004)
@@ -212,6 +212,30 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_pack.rb#L212
         }
       }
 
+      2.upto(16) {|wordsize|
+        w = wordsize
+        b = 8*wordsize-1
+        n = 2**b
+        assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], (-n-1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], (-n  ).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], (-n+1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+        assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], (+n-1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], (+n  ).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], (+n+1).test_pack(1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+      }
+
+      2.upto(16) {|wordsize|
+        w = wordsize
+        b = 8*wordsize-1
+        n = 2**b
+        assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], (-n-1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], (-n  ).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+        assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], (-n+1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+        assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], (+n-1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], (+n  ).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+        assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], (+n+1).test_pack(1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+      }
+
     end
 
     def test_unpack_zero

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

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