gmp 0.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGELOG +109 -0
  2. data/INSTALL +4 -0
  3. data/README.rdoc +357 -0
  4. data/benchmark/COPYING +674 -0
  5. data/benchmark/README +75 -0
  6. data/benchmark/divide +34 -0
  7. data/benchmark/gcd +38 -0
  8. data/benchmark/gexpr +0 -0
  9. data/benchmark/gexpr.c +359 -0
  10. data/benchmark/multiply +44 -0
  11. data/benchmark/rsa +93 -0
  12. data/benchmark/runbench +147 -0
  13. data/benchmark/version +1 -0
  14. data/ext/extconf.rb +30 -0
  15. data/ext/gmp.c +197 -0
  16. data/ext/gmpbench_timing.c +80 -0
  17. data/ext/gmpf.c +595 -0
  18. data/ext/gmpf.h +144 -0
  19. data/ext/gmpq.c +780 -0
  20. data/ext/gmpq.h +12 -0
  21. data/ext/gmprandstate.c +224 -0
  22. data/ext/gmpz.c +1968 -0
  23. data/ext/gmpz.h +20 -0
  24. data/ext/libgmp-10.dll +0 -0
  25. data/ext/ruby_gmp.h +243 -0
  26. data/ext/takeover.h +36 -0
  27. data/manual.pdf +0 -0
  28. data/manual.tex +804 -0
  29. data/test/README +34 -0
  30. data/test/tc_cmp.rb +74 -0
  31. data/test/tc_division.rb +109 -0
  32. data/test/tc_f_arithmetics_coersion.rb +71 -0
  33. data/test/tc_f_precision.rb +48 -0
  34. data/test/tc_fib_fac_nextprime.rb +51 -0
  35. data/test/tc_floor_ceil_truncate.rb +21 -0
  36. data/test/tc_logical_roots.rb +48 -0
  37. data/test/tc_q.rb +27 -0
  38. data/test/tc_q_basic.rb +41 -0
  39. data/test/tc_random.rb +54 -0
  40. data/test/tc_sgn_neg_abs.rb +47 -0
  41. data/test/tc_swap.rb +19 -0
  42. data/test/tc_z.rb +71 -0
  43. data/test/tc_z_basic.rb +35 -0
  44. data/test/tc_z_exponentiation.rb +22 -0
  45. data/test/tc_z_gcd_lcm_invert.rb +57 -0
  46. data/test/tc_z_jac_leg_rem.rb +73 -0
  47. data/test/tc_z_logic.rb +54 -0
  48. data/test/tc_z_shifts_last_bits.rb +22 -0
  49. data/test/tc_z_to_d_to_i.rb +24 -0
  50. data/test/tc_zerodivisionexceptions.rb +17 -0
  51. data/test/test-12.rb +14 -0
  52. data/test/test-19.rb +13 -0
  53. data/test/test-20.rb +29 -0
  54. data/test/test-21.rb +37 -0
  55. data/test/test-22.rb +12 -0
  56. data/test/test-23.rb +11 -0
  57. data/test/test_helper.rb +8 -0
  58. data/test/unit_tests.rb +39 -0
  59. metadata +115 -0
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Q < Test::Unit::TestCase
4
+ def test_init_null
5
+ assert_equal(GMP::Q.new(), 0, "GMP::Q.new() should initialize to 0")
6
+ end
7
+
8
+ def test_init_fixnum
9
+ assert_equal(GMP::Q.new(1), 1, "GMP::Q.new(x : Fixnum) should initialize to 0")
10
+ end
11
+
12
+ def test_init_fixnum2
13
+ assert_equal(GMP::Q.new(1, 2).to_s, "1/2", "GMP::Q.new(num : Fixnum, den : Fixnum) should initialize to num/den")
14
+ assert_equal(GMP::Q.new(1, 3).to_s, "1/3", "GMP::Q.new(num : Fixnum, den : Fixnum) should initialize to num/den")
15
+ assert_equal(GMP::Q.new(2, 4).to_s, "1/2", "GMP::Q.new(num : Fixnum, den : Fixnum) should initialize to num/den")
16
+ end
17
+
18
+ def test_init_string
19
+ assert_equal(GMP::Q.new("1/2").to_s, "1/2", "GMP::Q.new(x : String) should initialize to x")
20
+ assert_equal(GMP::Q.new("1/3").to_s, "1/3", "GMP::Q.new(x : String) should initialize to x")
21
+ end
22
+
23
+ def test_init_q
24
+ a = GMP::Q.new(1,2)
25
+ assert_equal(GMP::Q.new(a), a, "GMP::Q.new(x : Q) should initialize to x")
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ # [Q op Q, Q op Z, Z op Q, Q op FixNum, Q op BigNum, FixNum op Q, BigNum op Q]
4
+ class TC_Q_Basic < Test::Unit::TestCase
5
+ def setup
6
+ @a=GMP::Q.new(100,11)
7
+ @b=GMP::Q.new(200,17)
8
+ @c=GMP::Z.new(40)
9
+ @d=2**32
10
+ end
11
+
12
+ def test_add
13
+ assert_equal(@a + @b, GMP::Q(3900, 187), "GMP::Q should add GMP::Q correctly")
14
+ assert_equal(@a + @c, GMP::Q(540, 11), "GMP::Q should add GMP::Z correctly")
15
+ assert_equal(@c + @a, GMP::Q(540, 11), "GMP::Z should add GMP::Q correctly")
16
+ assert_equal(@a + 2, GMP::Q(122, 11), "GMP::Z should add Fixnum correctly")
17
+ assert_equal(@a + @d, GMP::Q(47244640356, 11), "GMP::Z should add Bignum correctly")
18
+ assert_equal( 2 + @a, GMP::Q(122, 11), "Fixnum should add GMP::Q correctly")
19
+ assert_equal(@d + @a, GMP::Q(47244640356, 11), "Bignum should add GMP::Q correctly")
20
+ end
21
+
22
+ def test_sub
23
+ assert_equal(@a - @b, GMP::Q(-500, 187), "GMP::Q should subtract GMP::Q correctly")
24
+ assert_equal(@a - @c, GMP::Q(-340, 11), "GMP::Q should subtract GMP::Z correctly")
25
+ assert_equal(@c - @a, GMP::Q(340, 11), "GMP::Z should subtract GMP::Q correctly")
26
+ assert_equal(@a - 2, GMP::Q(78, 11), "GMP::Z should subtract Fixnum correctly")
27
+ assert_equal(@a - @d, GMP::Q(-47244640156, 11),"GMP::Z should subtract Bignum correctly")
28
+ assert_equal( 2 - @a, GMP::Q(-78, 11), "Fixnum should subtract GMP::Q correctly")
29
+ assert_equal(@d - @a, GMP::Q(47244640156, 11), "Bignum should subtract GMP::Q correctly")
30
+ end
31
+
32
+ def test_mul
33
+ assert_equal(@a * @b, GMP::Q(20000, 187), "GMP::Q should multiply GMP::Q correctly")
34
+ assert_equal(@a * @c, GMP::Q(4000, 11), "GMP::Q should multiply GMP::Z correctly")
35
+ assert_equal(@c * @a, GMP::Q(4000, 11), "GMP::Z should multiply GMP::Q correctly")
36
+ assert_equal(@a * 2, GMP::Q(200, 11), "GMP::Z should multiply Fixnum correctly")
37
+ # assert_equal(@a * @d, GMP::Q(429496729600, 11),"GMP::Z should multiply Bignum correctly") # SEGFAULT
38
+ assert_equal( 2 * @a, GMP::Q(200, 11), "Fixnum should multiply GMP::Q correctly")
39
+ # assert_equal(@d * @a, GMP::Q(429496729600, 11),"Bignum should multiply GMP::Q correctly") # SEGFAULT
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Random < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def test_urandomb
8
+ @a = GMP::RandState.new
9
+ @a.seed(13579)
10
+ g1 = [ 392, 507, 1657, 3963, 2275, 1264, 2370, 2152, 3282, 407,
11
+ 1746, 2488, 1753, 1639, 721, 3291, 3697, 2258, 3990, 1019]
12
+ g1.size.times do |i|
13
+ assert_equal(g1[i], @a.urandomb(12), "GMP::RandState should urandomb predictably.")
14
+ end
15
+
16
+ @b = GMP::RandState.new
17
+ @b.seed(314159)
18
+ g2 = [ 20, 5, 40, 228, 223, 205, 1750, 690, 5794, 13752,
19
+ 31377, 49064, 37010, 187285, 489973, 312091, 550520, 916752, 3213943, 1561294]
20
+ g2.size.times do |i|
21
+ assert_equal(g2[i], @b.urandomb(i+5), "GMP::RandState should urandomb predictably.")
22
+ end
23
+ end
24
+
25
+ def test_reseed
26
+ @c = GMP::RandState.new
27
+ @c.seed(1000)
28
+ assert_equal( 6461, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
29
+ assert_equal(42961, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
30
+ assert_equal(44699, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
31
+ @c.seed(1000)
32
+ assert_equal( 6461, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
33
+ assert_equal(42961, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
34
+ assert_equal(44699, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
35
+ @c.seed(1000)
36
+ assert_equal( 6461, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
37
+ assert_equal(42961, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
38
+ assert_equal(44699, @c.urandomb(16), "GMP::RandState should re-seed correctly.")
39
+ end
40
+
41
+ def test_random_independent_states
42
+ @d = GMP::RandState.new
43
+ @d.seed(13579)
44
+ @e = GMP::RandState.new
45
+ @e.seed(13579)
46
+
47
+ assert_equal( 392, @d.urandomb(12), "GMP::RandState should be independent correctly.")
48
+ assert_equal( 507, @d.urandomb(12), "GMP::RandState should be independent correctly.")
49
+ assert_equal( 392, @e.urandomb(12), "GMP::RandState should be independent correctly.")
50
+ assert_equal( 507, @e.urandomb(12), "GMP::RandState should be independent correctly.")
51
+ assert_equal(1657, @d.urandomb(12), "GMP::RandState should be independent correctly.")
52
+ assert_equal(1657, @e.urandomb(12), "GMP::RandState should be independent correctly.")
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ class TC_sgn_neg_abs < Test::Unit::TestCase
4
+ def setup
5
+ @a=GMP::Z.new(10)
6
+ @b=GMP::Z.new()
7
+ @c=GMP::Z.new(-10)
8
+ @d=GMP::Q.new(10)
9
+ @e=GMP::Q.new()
10
+ @f=GMP::Q.new(-10)
11
+ @k=GMP::Z.new(10)
12
+ @l=GMP::Z.new()
13
+ @m=GMP::Z.new(-10)
14
+ @n=GMP::Q.new(10)
15
+ @o=GMP::Q.new()
16
+ @p=GMP::Q.new(-10)
17
+ end
18
+
19
+ def test_sgn
20
+ assert_equal([1, 0, 1, 0], [@a.sgn, @b.sgn, @d.sgn, @e.sgn], "GMP::Z, GMP::Q should calculate sgn correctly")
21
+ assert_equal([-1, -1], [@c.sgn, @f.sgn], "GMP::Z, GMP::Q should calculate sgn correctly")
22
+ end
23
+
24
+ def test_neg
25
+ assert_equal(-@a, @c, "-(x : GMP::Z) should be calculated correctly.")
26
+ assert_equal(-@c, @a, "-(x : GMP::Z) should be calculated correctly.")
27
+ assert_equal(-@b, @b, "-GMP::Z.new() should equal GMP::Z.new().")
28
+ assert_equal(-@d, @f, "-(x : GMP::Q) should be calculated correctly.")
29
+ assert_equal(-@f, @d, "-(x : GMP::Q) should be calculated correctly.")
30
+ assert_equal(-@e, @e, "-GMP::Q.new() should equal GMP::Q.new().")
31
+ @k.neg!; @l.neg!; @m.neg!; @n.neg!; @o.neg!; @p.neg!
32
+ assert_equal(@k, @c, "(x : GMP::Z).neg! should be calculated correctly.")
33
+ assert_equal(@l, @b, "(x : GMP::Z).neg! should be calculated correctly.")
34
+ assert_equal(@m, @a, "GMP::Z.new().neg! should equal GMP::Z.new().")
35
+ assert_equal(@n, @f, "(x : GMP::Q).neg! should be calculated correctly.")
36
+ assert_equal(@o, @e, "(x : GMP::Q).neg! should be calculated correctly.")
37
+ assert_equal(@p, @d, "GMP::Q.new().neg! should equal GMP::Q.new().")
38
+ end
39
+
40
+ def test_abs
41
+ assert_equal([10, 0, 10], [@a.abs, @b.abs, @c.abs], "(x : GMP::Z).abs should be calculated correctly.")
42
+ assert_equal([10, 0, 10], [@d.abs, @e.abs, @f.abs], "(x : GMP::Q).abs should be calculated correctly.")
43
+ @a.abs!; @b.abs!; @c.abs!; @d.abs!; @e.abs!; @f.abs!
44
+ assert_equal([10, 0, 10], [@a, @b, @c], "(x : GMP::Z).abs! should be calculated correctly.")
45
+ assert_equal([10, 0, 10], [@d, @e, @f], "(x : GMP::Q).abs! should be calculated correctly.")
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class TC_swap < Test::Unit::TestCase
4
+ def setup
5
+ @a=GMP::Z.new(100)
6
+ @b=GMP::Z.new(200)
7
+ @c=GMP::Q.new(100,11)
8
+ @d=GMP::Q.new(200,17)
9
+ end
10
+
11
+ def test_swap
12
+ @a.swap @b
13
+ @c.swap @d
14
+ assert_equal(@a, 200, "GMP::Z should swap with GMP::Z.")
15
+ assert_equal(@b, 100, "GMP::Z should swap with GMP::Z.")
16
+ assert_equal(@c, GMP::Q.new(200,17), "GMP::Z should swap with GMP::Z.")
17
+ assert_equal(@d, GMP::Q.new(100,11), "GMP::Z should swap with GMP::Z.")
18
+ end
19
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Z < Test::Unit::TestCase
4
+ def test_init_null
5
+ assert_equal(GMP::Z.new(), 0, "GMP::Z.new() should initialize to 0")
6
+ end
7
+
8
+ def test_init_fixnum
9
+ assert_equal(GMP::Z.new(1), 1, "GMP::Z.new(x : Fixnum) should initialize to x")
10
+ end
11
+
12
+ def test_init_z
13
+ b = GMP::Z.new(1)
14
+ assert_equal(GMP::Z.new(b), b, "GMP::Z.new(x : GMP::Z) should initialize to x")
15
+ end
16
+
17
+ def test_init_string
18
+ assert_equal(GMP::Z.new("1"), 1, "GMP::Z.new(x : String) should initialize to x")
19
+ end
20
+
21
+ def test_init_bignum
22
+ assert_equal(GMP::Z.new(2**32), 2**32, "GMP::Z.new(x : Bignum) should initialize to x")
23
+ end
24
+
25
+ def test_cmp_z
26
+ a = GMP::Z.new(2)
27
+ b = GMP::Z.new(1)
28
+ assert_equal(a > b, true, "GMP::Z should compare correctly with GMP::Z")
29
+ assert_equal(a > a, false, "GMP::Z should compare correctly with GMP::Z")
30
+ assert_equal(b > a, false, "GMP::Z should compare correctly with GMP::Z")
31
+
32
+ assert_equal(a >= b, true, "GMP::Z should compare correctly with GMP::Z")
33
+ assert_equal(a >= a, true, "GMP::Z should compare correctly with GMP::Z")
34
+ assert_equal(b >= a, false, "GMP::Z should compare correctly with GMP::Z")
35
+
36
+ assert_equal(a <= b, false, "GMP::Z should compare correctly with GMP::Z")
37
+ assert_equal(a <= a, true, "GMP::Z should compare correctly with GMP::Z")
38
+ assert_equal(b <= a, true, "GMP::Z should compare correctly with GMP::Z")
39
+
40
+ assert_equal(a < b, false, "GMP::Z should compare correctly with GMP::Z")
41
+ assert_equal(a < a, false, "GMP::Z should compare correctly with GMP::Z")
42
+ assert_equal(b < a, true, "GMP::Z should compare correctly with GMP::Z")
43
+
44
+ assert_equal(a == b, false, "GMP::Z should == correctly with GMP::Z")
45
+ assert_equal(a == a, true, "GMP::Z should == correctly with GMP::Z")
46
+
47
+ assert_equal(a != b, true, "GMP::Z should != correctly with GMP::Z")
48
+ assert_equal(a != a, false, "GMP::Z should != correctly with GMP::Z")
49
+
50
+ assert_equal(a <=> b, 1, "GMP::Z should <=> correctly with GMP::Z")
51
+ assert_equal(a <=> a, 0, "GMP::Z should <=> correctly with GMP::Z")
52
+ assert_equal(b <=> a, -1, "GMP::Z should <=> correctly with GMP::Z")
53
+ end
54
+
55
+ def test_to_s
56
+ assert_equal("1", GMP::Z.new(1).to_s, "Z(1).to_s should equal '1'")
57
+ assert_equal("-1", GMP::Z.new(-1).to_s, "Z(1).to_s should equal '-1'")
58
+ assert_equal("1234567890", GMP::Z.new(1234567890).to_s, "GMP::Z should to_s correctly.")
59
+ assert_equal("100000", GMP::Z.new(32).to_s( 2), "GMP::Z should to_s( 2) correctly.")
60
+ assert_equal("200", GMP::Z.new(32).to_s( 4), "GMP::Z should to_s( 4) correctly.")
61
+ assert_equal("40", GMP::Z.new(32).to_s( 8), "GMP::Z should to_s( 8) correctly.")
62
+ assert_equal("32", GMP::Z.new(32).to_s( 10), "GMP::Z should to_s( 10) correctly.")
63
+ assert_equal("20", GMP::Z.new(32).to_s( 16), "GMP::Z should to_s( 16) correctly.")
64
+ assert_equal("a", GMP::Z.new(10).to_s( 16), "GMP::Z should to_s( 16) correctly.")
65
+ assert_equal("A", GMP::Z.new(10).to_s( -16), "GMP::Z should to_s( -16) correctly.")
66
+ assert_equal("11111111", GMP::Z.new(255).to_s(:bin), "GMP::Z should to_s(:bin) correctly.")
67
+ assert_equal("377", GMP::Z.new(255).to_s(:oct), "GMP::Z should to_s(:oct) correctly.")
68
+ assert_equal("255", GMP::Z.new(255).to_s(:dec), "GMP::Z should to_s(:dec) correctly.")
69
+ assert_equal("ff", GMP::Z.new(255).to_s(:hex), "GMP::Z should to_s(:hex) correctly.")
70
+ end
71
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ # Tested: [Z op Z, Z op FixNum, Z op BigNum, FixNum op Z, BigNum op Z]
4
+ # Things are tested both ways because the implementation is asymetrical
5
+ class TC_Z_Basic < Test::Unit::TestCase
6
+ def setup
7
+ @a=GMP::Z.new(100)
8
+ @b=GMP::Z.new(200)
9
+ @c=2**32
10
+ end
11
+
12
+ def test_add
13
+ assert_equal(@a + @b, 100 + 200, "GMP::Z should add correctly")
14
+ assert_equal(@a + 2, 100 + 2, "GMP::Z should add correctly")
15
+ assert_equal(@a + @c, 100 + 2**32, "GMP::Z should add correctly")
16
+ assert_equal( 2 + @a, 2 + 100, "GMP::Z should add correctly")
17
+ assert_equal(@c + @a, 2**32 + 100, "GMP::Z should add correctly")
18
+ end
19
+
20
+ def test_sub
21
+ assert_equal(@a - @b, 100 - 200, "GMP::Z should subtract correctly")
22
+ assert_equal(@a - 2, 100 - 2, "GMP::Z should subtract correctly")
23
+ assert_equal(@a - @c, 100 - 2**32, "GMP::Z should subtract correctly")
24
+ assert_equal( 2 - @a, 2 - 100, "GMP::Z should subtract correctly")
25
+ assert_equal(@c - @a, 2**32 - 100, "GMP::Z should subtract correctly")
26
+ end
27
+
28
+ def test_mul
29
+ assert_equal(@a * @b, 100 * 200, "GMP::Z should multiply correctly")
30
+ assert_equal(@a * 2, 100 * 2, "GMP::Z should multiply correctly")
31
+ assert_equal(@a * @c, 100 * 2**32, "GMP::Z should multiply correctly")
32
+ assert_equal( 2 * @a, 2 * 100, "GMP::Z should multiply correctly")
33
+ assert_equal(@c * @a, 2**32 * 100, "GMP::Z should multiply correctly")
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Z_Exponentiation < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Z.new(100)
6
+ @b = GMP::Z.new(16)
7
+ @c = @a**5
8
+ end
9
+
10
+ def test_exponentiation
11
+ assert_equal(GMP::Z(10000000000), @a**5, "GMP::Z should **(Fixnum) correctly")
12
+ assert_equal(GMP::Z("100000000000000000000000000000000"), @a**@b, "GMP::Z should **(GMP::Z) correctly")
13
+ assert_equal(GMP::Z(65536), 2**@b, "Fixnum should **(GMP::Z) correctly")
14
+ end
15
+
16
+ def test_powmod
17
+ assert_equal(GMP::Z(16), @a.powmod(2,256), "(a : GMP::Z).powmod((b : Fixnum), (c : Fixnum)) should work correctly")
18
+ assert_equal(GMP::Z(76), @b.powmod(10,@a), "(a : GMP::Z).powmod((b : Fixnum), (c : GMP::Z)) should work correctly")
19
+ assert_equal(GMP::Z(0), @a.powmod(@b,256), "(a : GMP::Z).powmod((b : GMP::Z), (c : Fixnum)) should work correctly")
20
+ assert_equal(GMP::Z(0), @a.powmod(@b,@c), "(a : GMP::Z).powmod((b : GMP::Z), (c : GMP::Z)) should work correctly")
21
+ end
22
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Z_GCD_LCM_Invert < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Z( 24) # 2^3 * 3
6
+ @b = GMP::Z( 8) # 2^3
7
+ @c = GMP::Z( 3) # 3
8
+ @d = GMP::Z( 7) # 7
9
+ @e = GMP::Z( 11) # 11
10
+ @f = GMP::Z( 25) # 25
11
+ @g = GMP::Z(720) # 2^4 * 3^2 * 5 = 1*2*3*4*5*6
12
+ end
13
+
14
+ def test_gcd
15
+ assert_equal(GMP::Z( 8), @a.gcd(@b), "GMP::Z should gcd correctly")
16
+ assert_equal(GMP::Z( 3), @a.gcd(@c), "GMP::Z should gcd correctly")
17
+ assert_equal(GMP::Z( 1), @c.gcd(@d), "GMP::Z should gcd correctly")
18
+ assert_equal(GMP::Z( 1), @a.gcd(@f), "GMP::Z should gcd correctly")
19
+ assert_equal(GMP::Z(24), @a.gcd(@g), "GMP::Z should gcd correctly")
20
+ end
21
+
22
+ def test_gcd2
23
+ assert_equal(GMP::Z( 8), (-@a).gcd(@b), "GMP::Z should gcd negatives correctly")
24
+ assert_equal(GMP::Z( 3), (-@a).gcd(@c), "GMP::Z should gcd negatives correctly")
25
+ assert_equal(GMP::Z( 1), (-@c).gcd(@d), "GMP::Z should gcd correctly")
26
+ assert_equal(GMP::Z(24), (-@a).gcd(@g), "GMP::Z should gcd correctly")
27
+
28
+ assert_equal(GMP::Z( 8), @a.gcd(-@b), "GMP::Z should gcd negatives correctly")
29
+ assert_equal(GMP::Z( 3), @a.gcd(-@c), "GMP::Z should gcd negatives correctly")
30
+ assert_equal(GMP::Z( 1), @c.gcd(-@d), "GMP::Z should gcd correctly")
31
+ assert_equal(GMP::Z(24), @a.gcd(-@g), "GMP::Z should gcd correctly")
32
+
33
+ assert_equal(GMP::Z( 8), (-@a).gcd(-@b), "GMP::Z should gcd negatives correctly")
34
+ assert_equal(GMP::Z( 3), (-@a).gcd(-@c), "GMP::Z should gcd negatives correctly")
35
+ assert_equal(GMP::Z( 1), (-@c).gcd(-@d), "GMP::Z should gcd correctly")
36
+ assert_equal(GMP::Z(24), (-@a).gcd(-@g), "GMP::Z should gcd correctly")
37
+ end
38
+
39
+ def test_invert
40
+ assert_equal(GMP::Z( 1), GMP::Z( 1).invert(@e), "GMP::Z should invert correctly")
41
+ assert_equal(GMP::Z( 6), GMP::Z( 2).invert(@e), "GMP::Z should invert correctly")
42
+ assert_equal(GMP::Z( 4), GMP::Z( 3).invert(@e), "GMP::Z should invert correctly")
43
+ assert_equal(GMP::Z( 3), GMP::Z( 4).invert(@e), "GMP::Z should invert correctly")
44
+ assert_equal(GMP::Z( 9), GMP::Z( 5).invert(@e), "GMP::Z should invert correctly")
45
+ assert_equal(GMP::Z( 2), GMP::Z( 6).invert(@e), "GMP::Z should invert correctly")
46
+ assert_equal(GMP::Z( 8), GMP::Z( 7).invert(@e), "GMP::Z should invert correctly")
47
+ assert_equal(GMP::Z( 7), GMP::Z( 8).invert(@e), "GMP::Z should invert correctly")
48
+ assert_equal(GMP::Z( 5), GMP::Z( 9).invert(@e), "GMP::Z should invert correctly")
49
+ assert_equal(GMP::Z(10), GMP::Z(10).invert(@e), "GMP::Z should invert correctly")
50
+ assert_equal(GMP::Z( 0), GMP::Z(11).invert(@e), "GMP::Z should invert correctly")
51
+
52
+ assert_equal(GMP::Z( 1), GMP::Z(12).invert(@e), "GMP::Z should invert correctly")
53
+ assert_equal(GMP::Z( 6), GMP::Z(13).invert(@e), "GMP::Z should invert correctly")
54
+ assert_equal(GMP::Z( 4), GMP::Z(14).invert(@e), "GMP::Z should invert correctly")
55
+ assert_equal(GMP::Z( 3), GMP::Z(15).invert(@e), "GMP::Z should invert correctly")
56
+ end
57
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Z_Jacobi_Legendre_Remove < Test::Unit::TestCase
4
+ def setup
5
+ @one = GMP::Z(1)
6
+ @two = GMP::Z(2)
7
+ @three = GMP::Z(3)
8
+ @four = GMP::Z(4)
9
+ @five = GMP::Z(5)
10
+ @nine = GMP::Z(9)
11
+ @forty_five = GMP::Z(45)
12
+ @neg_one = GMP::Z(-1)
13
+ end
14
+
15
+ # I don't actually know the Jacobi symbol, so these are just from Wolfram Alpha.
16
+ def test_jacobi
17
+ assert_equal(@one.jacobi(@one), 1, "GMP::Z should jacobi(GMP::Z) correctly")
18
+ assert_equal(@two.jacobi(@one), 1, "GMP::Z should jacobi(GMP::Z) correctly")
19
+ assert_equal(@forty_five.jacobi(@one), 1, "GMP::Z should jacobi(GMP::Z) correctly")
20
+ assert_equal(@one.jacobi(@three), 1, "GMP::Z should jacobi(GMP::Z) correctly")
21
+ assert_equal(@two.jacobi(@three), -1, "GMP::Z should jacobi(GMP::Z) correctly")
22
+ assert_equal(@three.jacobi(@three), 0, "GMP::Z should jacobi(GMP::Z) correctly")
23
+ assert_equal(@forty_five.jacobi(@three), 0, "GMP::Z should jacobi(GMP::Z) correctly")
24
+
25
+ assert_equal(GMP::Z.jacobi(@one, @one), 1, "GMP::Z should jacobi(GMP::Z, GMP::Z) correctly")
26
+ assert_equal(GMP::Z.jacobi(@four, @one), 1, "GMP::Z should jacobi(GMP::Z, GMP::Z) correctly")
27
+ assert_equal(GMP::Z.jacobi(@two, @three), -1, "GMP::Z should jacobi(GMP::Z, GMP::Z) correctly")
28
+ assert_equal(GMP::Z.jacobi(@three, @three), 0, "GMP::Z should jacobi(GMP::Z, GMP::Z) correctly")
29
+
30
+ assert_equal(GMP::Z.jacobi(1, @one), 1, "GMP::Z should jacobi(Fixnum, GMP::Z) correctly")
31
+ assert_equal(GMP::Z.jacobi(4, @one), 1, "GMP::Z should jacobi(Fixnum, GMP::Z) correctly")
32
+ assert_equal(GMP::Z.jacobi(2, @three), -1, "GMP::Z should jacobi(Fixnum, GMP::Z) correctly")
33
+ assert_equal(GMP::Z.jacobi(3, @three), 0, "GMP::Z should jacobi(Fixnum, GMP::Z) correctly")
34
+
35
+ assert_equal(GMP::Z.jacobi(@one, 1), 1, "GMP::Z should jacobi(GMP::Z, Fixnum) correctly")
36
+ assert_equal(GMP::Z.jacobi(@four, 1), 1, "GMP::Z should jacobi(GMP::Z, Fixnum) correctly")
37
+ assert_equal(GMP::Z.jacobi(@two, 3), -1, "GMP::Z should jacobi(GMP::Z, Fixnum) correctly")
38
+ assert_equal(GMP::Z.jacobi(@three, 3), 0, "GMP::Z should jacobi(GMP::Z, Fixnum) correctly")
39
+
40
+ assert_equal(GMP::Z.jacobi(1, 1), 1, "GMP::Z should jacobi(Fixnum, Fixnum) correctly")
41
+ assert_equal(GMP::Z.jacobi(4, 1), 1, "GMP::Z should jacobi(Fixnum, Fixnum) correctly")
42
+ assert_equal(GMP::Z.jacobi(2, 3), -1, "GMP::Z should jacobi(Fixnum, Fixnum) correctly")
43
+ assert_equal(GMP::Z.jacobi(3, 3), 0, "GMP::Z should jacobi(Fixnum, Fixnum) correctly")
44
+
45
+ assert_raise(RangeError) { @two.jacobi(@two) }
46
+ assert_raise(RangeError) { @three.jacobi(@neg_one) }
47
+ assert_raise(RangeError) { GMP::Z.jacobi(@two, @two) }
48
+ assert_raise(RangeError) { GMP::Z.jacobi(@three, @neg_one) }
49
+ assert_raise(RangeError) { GMP::Z.jacobi(@two, 2) }
50
+ assert_raise(RangeError) { GMP::Z.jacobi(3, @neg_one) }
51
+ assert_raise(RangeError) { GMP::Z.jacobi(3, -1) }
52
+ end
53
+
54
+ def test_legendre
55
+ assert_equal(@one.legendre(@three), 1, "GMP::Z should legendre(GMP::Z) correctly")
56
+ assert_equal(@two.legendre(@three), -1, "GMP::Z should legendre(GMP::Z) correctly")
57
+
58
+ assert_raise(RangeError) { @one.legendre(@one) }
59
+ assert_raise(RangeError) { @one.legendre(@two) }
60
+ assert_raise(RangeError) { @one.legendre(@neg_one) }
61
+ assert_raise(RangeError) { @one.legendre(@four) }
62
+ assert_raise(RangeError) { @one.legendre(@nine) }
63
+ end
64
+
65
+ def test_remove
66
+ assert_equal(@nine, @forty_five.remove(5)[0], "GMP::Z should remove(GMP::Z) correctly.")
67
+ assert_equal(@nine, @forty_five.remove(@five)[0], "GMP::Z should remove(GMP::Z) correctly.")
68
+ assert_equal(@five, @forty_five.remove(@three)[0], "GMP::Z should remove(GMP::Z) correctly.")
69
+ assert_equal(1, @forty_five.remove(5)[1], "GMP::Z should remove(GMP::Z) correctly.")
70
+ assert_equal(1, @forty_five.remove(@five)[1], "GMP::Z should remove(GMP::Z) correctly.")
71
+ assert_equal(2, @forty_five.remove(@three)[1], "GMP::Z should remove(GMP::Z) correctly.")
72
+ end
73
+ end