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