2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-09-02 23:50:15 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require "-test-/bignum"
|
|
|
|
|
2018-03-13 02:29:02 -04:00
|
|
|
class Test_Bignum < Test::Unit::TestCase
|
2013-09-02 23:50:15 -04:00
|
|
|
class TestStr2big < Test::Unit::TestCase
|
|
|
|
|
2021-01-08 05:07:16 -05:00
|
|
|
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
|
|
|
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
2013-09-02 23:50:15 -04:00
|
|
|
BDIGMAX = (1 << BITSPERDIG) - 1
|
|
|
|
|
|
|
|
def test_str2big_poweroftwo
|
|
|
|
s = "1" + "0" * 1000
|
|
|
|
n = 16 ** 1000
|
2021-01-08 05:07:16 -05:00
|
|
|
assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
|
2013-09-02 23:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_str2big_normal
|
|
|
|
s = "1" + "0" * 1000
|
|
|
|
n = 10 ** 1000
|
2021-01-08 05:07:16 -05:00
|
|
|
assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
|
2013-09-02 23:50:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_str2big_karatsuba
|
|
|
|
s = "1" + "0" * 1000
|
|
|
|
n = 10 ** 1000
|
2021-01-08 05:07:16 -05:00
|
|
|
assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
|
2013-09-02 23:50:15 -04:00
|
|
|
end
|
|
|
|
|
2013-09-03 07:20:02 -04:00
|
|
|
def test_str2big_gmp
|
|
|
|
s = "1" + "0" * 1000
|
|
|
|
n = 10 ** 1000
|
2021-01-08 05:07:16 -05:00
|
|
|
assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
|
2013-09-03 07:20:02 -04:00
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
|
2013-09-02 23:50:15 -04:00
|
|
|
end
|
|
|
|
end
|