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