From 29634bca310c32b8f8dacd6e9bd8304388b30d17 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 7 Jul 2013 14:01:40 +0000 Subject: * internal.h (rb_big_mul_normal): Declared. (rb_big_mul_balance): Ditto. (rb_big_mul_karatsuba): Ditto. * bignum.c (rb_big_mul_normal): New function for tests. (rb_big_mul_balance): Ditto. (rb_big_mul_karatsuba): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/bignum/test_mul.rb | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/-ext-/bignum/test_mul.rb (limited to 'test/-ext-/bignum') diff --git a/test/-ext-/bignum/test_mul.rb b/test/-ext-/bignum/test_mul.rb new file mode 100644 index 0000000000..ad3b38febd --- /dev/null +++ b/test/-ext-/bignum/test_mul.rb @@ -0,0 +1,53 @@ +require 'test/unit' +require "-test-/bignum" + +class TestBignum < Test::Unit::TestCase + class TestMul < Test::Unit::TestCase + + SIZEOF_BDIGITS = Bignum::SIZEOF_BDIGITS + BITSPERDIG = Bignum::BITSPERDIG + + def test_mul_normal + x = (1 << BITSPERDIG) | 1 + y = (1 << BITSPERDIG) | 1 + z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1 + assert_equal(z, x.big_mul_normal(y)) + end + + def test_mul_normal_zero_in_x + x = (1 << (2*BITSPERDIG)) | 1 + y = (1 << BITSPERDIG) | 1 + z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1 + assert_equal(z, x.big_mul_normal(y)) + end + + def test_mul_normal_zero_in_y + x = (1 << BITSPERDIG) | 1 + y = (1 << (2*BITSPERDIG)) | 1 + z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1 + assert_equal(z, x.big_mul_normal(y)) + end + + def test_mul_normal_max_max + x = (1 << (2*BITSPERDIG)) - 1 + y = (1 << (2*BITSPERDIG)) - 1 + z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1 + assert_equal(z, x.big_mul_normal(y)) + end + + def test_mul_balance + x = (1 << BITSPERDIG) | 1 + y = (1 << BITSPERDIG) | 1 + z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1 + assert_equal(z, x.big_mul_balance(y)) + end + + def test_mul_karatsuba + x = (1 << BITSPERDIG) | 1 + y = (1 << BITSPERDIG) | 1 + z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1 + assert_equal(z, x.big_mul_karatsuba(y)) + end + + end +end -- cgit v1.2.3