From 1210743cad827155f4e2d4da9adbb8c1569a93a6 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 7 Jul 2013 15:21:26 +0000 Subject: * bignum.c (bary_mul_karatsuba): Unreachable code removed. Remove several branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/bignum/test_mul.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/-ext-/bignum/test_mul.rb') diff --git a/test/-ext-/bignum/test_mul.rb b/test/-ext-/bignum/test_mul.rb index ad3b38febd..539b9cf138 100644 --- a/test/-ext-/bignum/test_mul.rb +++ b/test/-ext-/bignum/test_mul.rb @@ -6,6 +6,7 @@ class TestBignum < Test::Unit::TestCase SIZEOF_BDIGITS = Bignum::SIZEOF_BDIGITS BITSPERDIG = Bignum::BITSPERDIG + BDIGMAX = (1 << BITSPERDIG) - 1 def test_mul_normal x = (1 << BITSPERDIG) | 1 @@ -49,5 +50,47 @@ class TestBignum < Test::Unit::TestCase assert_equal(z, x.big_mul_karatsuba(y)) end + def test_mul_karatsuba_odd_y + x = (1 << BITSPERDIG) | 1 + y = (1 << (2*BITSPERDIG)) | 1 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_odd_xy + x = (1 << (2*BITSPERDIG)) | 1 + y = (1 << (2*BITSPERDIG)) | 1 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_x1_gt_x0 + x = (2 << BITSPERDIG) | 1 + y = (1 << BITSPERDIG) | 2 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_y1_gt_y0 + x = (1 << BITSPERDIG) | 2 + y = (2 << BITSPERDIG) | 1 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0 + x = (2 << BITSPERDIG) | 1 + y = (2 << BITSPERDIG) | 1 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_carry2 + x = (1 << BITSPERDIG) | BDIGMAX + y = (1 << BITSPERDIG) | BDIGMAX + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + + def test_mul_karatsuba_borrow + x = (BDIGMAX << BITSPERDIG) | 1 + y = (BDIGMAX << BITSPERDIG) | 1 + assert_equal(x.big_mul_normal(y), x.big_mul_karatsuba(y)) + end + end end -- cgit v1.2.3