PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/-ext-/bignum/test_div.rb

http://github.com/ruby/ruby
Ruby | 29 lines | 24 code | 4 blank | 1 comment | 0 complexity | 79419d973e5f5b04b1aa591953b61694 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-3.0
  1. # frozen_string_literal: false
  2. require 'test/unit'
  3. require "-test-/bignum"
  4. class Test_Bignum < Test::Unit::TestCase
  5. class TestDiv < Test::Unit::TestCase
  6. SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
  7. BITSPERDIG = Integer::BITSPERDIG
  8. BDIGMAX = (1 << BITSPERDIG) - 1
  9. def test_divrem_normal
  10. x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
  11. y = (1 << BITSPERDIG) | 1
  12. q = (1 << BITSPERDIG) | 1
  13. r = 2
  14. assert_equal([q, r], x.big_divrem_normal(y))
  15. end
  16. def test_divrem_gmp
  17. x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
  18. y = (1 << BITSPERDIG) | 1
  19. q = (1 << BITSPERDIG) | 1
  20. r = 2
  21. assert_equal([q, r], x.big_divrem_gmp(y))
  22. rescue NotImplementedError
  23. end
  24. end
  25. end