PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/test/-ext-/bignum/test_str2big.rb

http://github.com/ruby/ruby
Ruby | 38 lines | 30 code | 7 blank | 1 comment | 0 complexity | 82b40403e1dbfacca50e4827b0398c19 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 TestStr2big < Test::Unit::TestCase
  6. SIZEOF_BDIGIT = Integer::SIZEOF_BDIGIT
  7. BITSPERDIG = Integer::BITSPERDIG
  8. BDIGMAX = (1 << BITSPERDIG) - 1
  9. def test_str2big_poweroftwo
  10. s = "1" + "0" * 1000
  11. n = 16 ** 1000
  12. assert_equal(n, s.str2big_poweroftwo(16, true))
  13. end
  14. def test_str2big_normal
  15. s = "1" + "0" * 1000
  16. n = 10 ** 1000
  17. assert_equal(n, s.str2big_normal(10, true))
  18. end
  19. def test_str2big_karatsuba
  20. s = "1" + "0" * 1000
  21. n = 10 ** 1000
  22. assert_equal(n, s.str2big_karatsuba(10, true))
  23. end
  24. def test_str2big_gmp
  25. s = "1" + "0" * 1000
  26. n = 10 ** 1000
  27. assert_equal(n, s.str2big_gmp(10, true))
  28. rescue NotImplementedError
  29. end
  30. end
  31. end