2015-12-16 05:07:31 +00:00
|
|
|
# frozen_string_literal: false
|
2013-09-04 16:10:06 +00:00
|
|
|
require 'test/unit'
|
|
|
|
require "-test-/bignum"
|
|
|
|
|
2018-03-13 06:29:02 +00:00
|
|
|
class Test_Bignum < Test::Unit::TestCase
|
2013-09-04 16:10:06 +00:00
|
|
|
class TestDiv < Test::Unit::TestCase
|
|
|
|
|
2021-01-08 19:07:16 +09:00
|
|
|
SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
|
|
|
|
BITSPERDIG = Bug::Bignum::BITSPERDIG
|
2013-09-04 16:10:06 +00:00
|
|
|
BDIGMAX = (1 << BITSPERDIG) - 1
|
|
|
|
|
|
|
|
def test_divrem_normal
|
|
|
|
x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
|
|
|
|
y = (1 << BITSPERDIG) | 1
|
|
|
|
q = (1 << BITSPERDIG) | 1
|
|
|
|
r = 2
|
2021-01-08 19:07:16 +09:00
|
|
|
assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
|
2013-09-04 16:10:06 +00:00
|
|
|
end
|
2013-09-04 23:22:27 +00:00
|
|
|
|
|
|
|
def test_divrem_gmp
|
|
|
|
x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
|
|
|
|
y = (1 << BITSPERDIG) | 1
|
|
|
|
q = (1 << BITSPERDIG) | 1
|
|
|
|
r = 2
|
2021-01-08 19:07:16 +09:00
|
|
|
assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
|
2013-09-04 23:22:27 +00:00
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
2013-09-04 16:10:06 +00:00
|
|
|
end
|
|
|
|
end
|