gmp 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+
3
+ class TC_Cmp < Test::Unit::TestCase
4
+ def setup
5
+ @a=GMP::Z.new(180)
6
+ @c=GMP::Q.new(2000,11) # ~181.82
7
+ @d=GMP::Q.new(3000,17) # ~176.47
8
+ @e=700
9
+ @f=2**32
10
+ @g=GMP::Q(360,2)
11
+ end
12
+
13
+ def test_cmp_q_q
14
+ assert_equal(@c > @d, true, "GMP::Q should compare correctly")
15
+ assert_equal(@c >= @d, true, "GMP::Q should compare correctly")
16
+ assert_equal(@c < @d, false, "GMP::Q should compare correctly")
17
+ assert_equal(@c <= @d, false, "GMP::Q should compare correctly")
18
+ assert_equal(@c == @d, false, "GMP::Q should == correctly")
19
+ assert_equal(@c == @c, true, "GMP::Q should == correctly")
20
+ assert_equal(@c != @d, true, "GMP::Q should != correctly")
21
+ assert_equal(@c != @c, false, "GMP::Q should != correctly")
22
+
23
+ assert_equal(@c <=> @d, 1, "GMP::Q should <=> correctly")
24
+ assert_equal(@c <=> @c, 0, "GMP::Q should <=> correctly")
25
+ assert_equal(@d <=> @c, -1, "GMP::Q should <=> correctly")
26
+ end
27
+
28
+ def test_cmp_q_z
29
+ assert_equal(@c > @a, true, "GMP::Q should compare correctly with GMP::Z")
30
+ assert_equal(@c >= @a, true, "GMP::Q should compare correctly with GMP::Z")
31
+ assert_equal(@c < @a, false, "GMP::Q should compare correctly with GMP::Z")
32
+ assert_equal(@c <= @a, false, "GMP::Q should compare correctly with GMP::Z")
33
+ assert_equal(@c == @a, false, "GMP::Q should == correctly with GMP::Z")
34
+ assert_equal(@c != @a, true, "GMP::Q should != correctly with GMP::Z")
35
+
36
+ assert_equal(@a < @c, true, "GMP::Z should compare correctly with GMP::Q")
37
+ assert_equal(@a <= @c, true, "GMP::Z should compare correctly with GMP::Q")
38
+ assert_equal(@a > @c, false, "GMP::Z should compare correctly with GMP::Q")
39
+ assert_equal(@a >= @c, false, "GMP::Z should compare correctly with GMP::Q")
40
+ assert_equal(@a == @c, false, "GMP::Z should == correctly with GMP::Q")
41
+ assert_equal(@a != @c, true, "GMP::Z should != correctly with GMP::Q")
42
+
43
+ assert_equal(@g == @a, true, "GMP::Q should == correctly with GMP::Z")
44
+ assert_equal(@g != @a, false, "GMP::Q should != correctly with GMP::Z")
45
+
46
+ assert_equal(@d > @a, false, "GMP::Q should compare correctly with GMP::Z")
47
+ assert_equal(@d >= @a, false, "GMP::Q should compare correctly with GMP::Z")
48
+ assert_equal(@d < @a, true, "GMP::Q should compare correctly with GMP::Z")
49
+ assert_equal(@d <= @a, true, "GMP::Q should compare correctly with GMP::Z")
50
+
51
+ assert_equal(@a < @d, false, "GMP::Z should compare correctly with GMP::Q")
52
+ assert_equal(@a <= @d, false, "GMP::Z should compare correctly with GMP::Q")
53
+ assert_equal(@a > @d, true, "GMP::Z should compare correctly with GMP::Q")
54
+ assert_equal(@a >= @d, true, "GMP::Z should compare correctly with GMP::Q")
55
+
56
+ assert_equal(@c <=> @a, 1, "GMP::Q should <=> correctly with GMP::Z")
57
+ assert_equal(@g <=> @a, 0, "GMP::Q should <=> correctly with GMP::Z")
58
+ assert_equal(@a <=> @c, -1, "GMP::Q should <=> correctly with GMP::Z")
59
+ end
60
+
61
+ def test_cmp_z_int
62
+ assert_equal(@a <=> @e, -1, "GMP::Z should <=> correctly with Fixnum")
63
+ assert_equal(@e <=> @a, 1, "Fixnum should <=> correctly with GMP::Z")
64
+ assert_equal(@a <=> @f, -1, "GMP::Z should <=> correctly with Bignum")
65
+ assert_equal(@f <=> @a, 1, "Bignum should <=> correctly with GMP::Z")
66
+ end
67
+
68
+ def test_cmp_q_int
69
+ assert_equal(@c <=> @e, -1, "GMP::Q should <=> correctly with Fixnum")
70
+ assert_equal(@e <=> @c, 1, "Fixnum should <=> correctly with GMP::Q")
71
+ assert_equal(@c <=> @f, -1, "GMP::Q should <=> correctly with Bignum")
72
+ assert_equal(@f <=> @c, 1, "Bignum should <=> correctly with GMP::Q")
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ class TC_fib_fac_nextprime < Test::Unit::TestCase
4
+ def setup
5
+ @z10 = GMP::Z.new(10)
6
+ @z7 = GMP::Z.new( 7)
7
+ @z8 = GMP::Z.new( 8)
8
+ @z11 = GMP::Z.new(11)
9
+ @z13 = GMP::Z.new(13)
10
+ @z17 = GMP::Z.new(17)
11
+ @z19 = GMP::Z.new(19)
12
+ end
13
+
14
+ def test_fib
15
+ assert_equal( 1, GMP::Z.fib( 1), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
16
+ assert_equal( 1, GMP::Z.fib( 2), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
17
+ assert_equal( 2, GMP::Z.fib( 3), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
18
+ assert_equal( 3, GMP::Z.fib( 4), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
19
+ assert_equal( 5, GMP::Z.fib( 5), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
20
+ assert_equal( 8, GMP::Z.fib( 6), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
21
+ assert_equal( 13, GMP::Z.fib( 7), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
22
+ assert_equal( 21, GMP::Z.fib( 8), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
23
+ assert_equal( 34, GMP::Z.fib( 9), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
24
+ assert_equal( 55, GMP::Z.fib( 10), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
25
+ assert_equal( 55, GMP::Z.fib(@z10), "GMP::Z::fib(x : GMP::Z) should be calculated correctly.")
26
+ assert_equal( 89, GMP::Z.fib( 11), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
27
+ assert_equal(144, GMP::Z.fib( 12), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
28
+ assert_equal(233, GMP::Z.fib( 13), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
29
+ assert_equal(377, GMP::Z.fib( 14), "GMP::Z::fib(x : Fixnum) should be calculated correctly.")
30
+ end
31
+
32
+ def test_fac
33
+ assert_equal( 1, GMP::Z.fac( 0), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
34
+ assert_equal( 1, GMP::Z.fac( 1), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
35
+ assert_equal( 2, GMP::Z.fac( 2), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
36
+ assert_equal( 6, GMP::Z.fac( 3), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
37
+ assert_equal( 24, GMP::Z.fac( 4), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
38
+ assert_equal( 120, GMP::Z.fac( 5), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
39
+ assert_equal( 720, GMP::Z.fac( 6), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
40
+ assert_equal(5040, GMP::Z.fac( 7), "GMP::Z::fac(x : Fixnum) should be calculated correctly.")
41
+ end
42
+
43
+ def test_nextprime
44
+ assert_equal(@z11, @z7.nextprime, "GMP::Z.nextprime should work.")
45
+ assert_equal(@z11, @z8.nextprime, "GMP::Z.nextprime should work.")
46
+ assert_equal(@z11, @z8.nextprime, "GMP::Z.nextprime should work.")
47
+ assert_equal(@z13, @z11.nextprime, "GMP::Z.nextprime should work.")
48
+ assert_equal(@z17, @z13.nextprime, "GMP::Z.nextprime should work.")
49
+ assert_equal(@z19, @z17.nextprime, "GMP::Z.nextprime should work.")
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class TC_floor_ceil_truncate < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Q.new(200,11)
6
+ @b = -@a
7
+ @c = GMP::Q.new(70,10)
8
+ end
9
+
10
+ def test_floor_ceil_truncate
11
+ assert_equal(@a.floor, 18, "GMP::Q should floor.")
12
+ assert_equal(@a.ceil, 19, "GMP::Q should ceil.")
13
+ assert_equal(@a.trunc, 18, "GMP::Q should truncate.")
14
+ assert_equal(@b.floor, -19, "GMP::Q (negative) should floor.")
15
+ assert_equal(@b.ceil, -18, "GMP::Q (negative) should ceil.")
16
+ assert_equal(@b.trunc, -18, "GMP::Q (negative) should truncate.")
17
+ assert_equal(@c.floor, 7, "GMP::Q (integer) should floor.")
18
+ assert_equal(@c.ceil, 7, "GMP::Q (integer) should ceil.")
19
+ assert_equal(@c.trunc, 7, "GMP::Q (integer) should truncate.")
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class TC_logical_roots < Test::Unit::TestCase
4
+ def setup
5
+ @a = GMP::Z.new(100)
6
+ @b = GMP::Z.new( 27)
7
+ @c = GMP::Z.new( 99)
8
+ end
9
+
10
+ def test_parity
11
+ assert @a.even?, "GMP::Z should even? correctly."
12
+ assert !@b.even?, "GMP::Z should even? correctly."
13
+ assert !@c.even?, "GMP::Z should even? correctly."
14
+ assert !@a.odd?, "GMP::Z should odd? correctly."
15
+ assert @b.odd?, "GMP::Z should odd? correctly."
16
+ assert @c.odd?, "GMP::Z should odd? correctly."
17
+ end
18
+
19
+ def test_square
20
+ assert @a.square?, "GMP::Z should square? correctly."
21
+ assert !@b.square?, "GMP::Z should square? correctly."
22
+ assert !@c.square?, "GMP::Z should square? correctly."
23
+ end
24
+
25
+ def test_power
26
+ assert @a.power?, "GMP::Z should power? correctly."
27
+ assert @b.power?, "GMP::Z should power? correctly."
28
+ assert !@c.power?, "GMP::Z should power? correctly."
29
+ end
30
+
31
+ def sqrtrem
32
+ assert_equal([10, 0], @a.sqrtrem, "GMP::Z should sqrtrem correctly.")
33
+ assert_equal([ 5, 2], @b.sqrtrem, "GMP::Z should sqrtrem correctly.")
34
+ assert_equal([ 9, 18], @c.sqrtrem, "GMP::Z should sqrtrem correctly.")
35
+ end
36
+
37
+ def sqrt
38
+ assert_equal(10, @a.sqrt, "GMP::Z should sqrt correctly.")
39
+ assert_equal( 5, @b.sqrt, "GMP::Z should sqrt correctly.")
40
+ assert_equal( 9, @c.sqrt, "GMP::Z should sqrt correctly.")
41
+ end
42
+
43
+ def root
44
+ assert_equal(4, @a.root(3), "GMP::Z should root correctly.")
45
+ assert_equal(3, @b.root(3), "GMP::Z should root correctly.")
46
+ assert_equal(4, @c.root(3), "GMP::Z should root correctly.")
47
+ end
48
+ end
@@ -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,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