abst 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'abst'
4
+
5
+ class TC_PrimeMPQS < MiniTest::Unit::TestCase
6
+ def test_primes_list
7
+ test = lambda do |n|
8
+ factor = Abst.mpqs(n)
9
+ assert(1 < factor && factor < n)
10
+ assert_equal(0, n % factor)
11
+ end
12
+
13
+ test.call(23916353875143281737)
14
+ test.call(56428599095241190007)
15
+ test.call(24559500716705748943)
16
+ test.call(43381522922949440477)
17
+ test.call(19238749214625480671)
18
+ test.call(25498058878476331907)
19
+ test.call(9530738504299322287)
20
+ test.call(18193861945465859131)
21
+ test.call(79670656009259581439)
22
+ test.call(19256936255213267029)
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'abst'
4
+
5
+ class TC_Rational < MiniTest::Unit::TestCase
6
+ def test_to_rds
7
+ assert_equal("0.5", Rational(1, 2).to_rds)
8
+ assert_equal("0.(3)", Rational(1, 3).to_rds)
9
+ assert_equal("0.25", Rational(1, 4).to_rds)
10
+ assert_equal("0.2", Rational(1, 5).to_rds)
11
+ assert_equal("0.1(6)", Rational(1, 6).to_rds)
12
+ assert_equal("0.(142857)", Rational(1, 7).to_rds)
13
+ assert_equal("0.125", Rational(1, 8).to_rds)
14
+ assert_equal("0.(1)", Rational(1, 9).to_rds)
15
+ assert_equal("0.1", Rational(1, 10).to_rds)
16
+ assert_equal("0.1005e3", Rational(201, 2).to_rds(10))
17
+ assert_equal("0.(10)", Rational(2, 3).to_rds(2))
18
+ end
19
+
20
+ def test_to_ds
21
+ assert_equal("0.5", Rational(1, 2).to_ds)
22
+ assert_equal("0." + "3" * 15, Rational(1, 3).to_ds(15))
23
+ assert_equal("0.25", Rational(1, 4).to_ds)
24
+ assert_equal("0.2", Rational(1, 5).to_ds)
25
+ assert_equal("0.1" + "6" * 31, Rational(1, 6).to_ds(32))
26
+ assert_equal("0." + "142857" * 10, Rational(1, 7).to_ds(60, 10))
27
+ assert_equal("0.125", Rational(1, 8).to_ds)
28
+ assert_equal("0.11111", Rational(1, 9).to_ds(5))
29
+ assert_equal("0.1", Rational(1, 10).to_ds)
30
+ assert_equal("0.1005e3", Rational(201, 2).to_ds(10))
31
+ assert_equal("0." + "10" * 15, Rational(2, 3).to_ds(30, 2))
32
+ end
33
+ end
@@ -0,0 +1,55 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'abst'
4
+
5
+ class TC_Fundamental < MiniTest::Unit::TestCase
6
+ def test_fibonacci
7
+ assert_equal(1, Abst.fibonacci(1))
8
+ assert_equal(1, Abst.fibonacci(2))
9
+ assert_equal(2, Abst.fibonacci(3))
10
+ assert_equal(3, Abst.fibonacci(4))
11
+ assert_equal(5, Abst.fibonacci(5))
12
+ assert_equal(12586269025, Abst.fibonacci(50))
13
+ assert_equal(354224848179261915075, Abst.fibonacci(100))
14
+ end
15
+
16
+ def test_triangle
17
+ assert_equal(1, Abst.triangle(1))
18
+ assert_equal(3, Abst.triangle(2))
19
+ assert_equal(6, Abst.triangle(3))
20
+ assert_equal(10, Abst.triangle(4))
21
+ assert_equal(15, Abst.triangle(5))
22
+ end
23
+
24
+ def test_pentagonal
25
+ assert_equal(1, Abst.pentagonal(1))
26
+ assert_equal(5, Abst.pentagonal(2))
27
+ assert_equal(12, Abst.pentagonal(3))
28
+ assert_equal(22, Abst.pentagonal(4))
29
+ assert_equal(35, Abst.pentagonal(5))
30
+ end
31
+
32
+ def test_hexagonal
33
+ assert_equal(1, Abst.hexagonal(1))
34
+ assert_equal(6, Abst.hexagonal(2))
35
+ assert_equal(15, Abst.hexagonal(3))
36
+ assert_equal(28, Abst.hexagonal(4))
37
+ assert_equal(45, Abst.hexagonal(5))
38
+ end
39
+
40
+ def test_heptagonal
41
+ assert_equal(1, Abst.heptagonal(1))
42
+ assert_equal(7, Abst.heptagonal(2))
43
+ assert_equal(18, Abst.heptagonal(3))
44
+ assert_equal(34, Abst.heptagonal(4))
45
+ assert_equal(55, Abst.heptagonal(5))
46
+ end
47
+
48
+ def test_octagonal
49
+ assert_equal(1, Abst.octagonal(1))
50
+ assert_equal(8, Abst.octagonal(2))
51
+ assert_equal(21, Abst.octagonal(3))
52
+ assert_equal(40, Abst.octagonal(4))
53
+ assert_equal(65, Abst.octagonal(5))
54
+ end
55
+ end
@@ -0,0 +1,36 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'abst'
4
+
5
+ class TC_Set < MiniTest::Unit::TestCase
6
+ def test_add
7
+ assert_equal(Set.new([1, 2, 3]), Set.new([1, 3]).add(2))
8
+ assert_equal(Set.new([2, 1, 2, 3]), Set.new([1, 2, 3]).add(2))
9
+ assert_equal(Set.new([3, 1, 2, 3, 5]), Set.new([5, 2, 3, 1]).add(2))
10
+ end
11
+
12
+ def test_dup
13
+ s1 = Set.new([1, 2, 3])
14
+ s2 = s1.dup
15
+ s2.add(4)
16
+
17
+ assert_equal(Set.new([1, 2, 3]), s1)
18
+ end
19
+ end
20
+
21
+ class TC_SortableSet < MiniTest::Unit::TestCase
22
+ def test_add
23
+ assert_equal(SortableSet.new([1, 2, 3]), SortableSet.new([1, 3]).add(2))
24
+ assert_equal(SortableSet.new([2, 1, 2, 3]), SortableSet.new([1, 2, 3]).add(2))
25
+ assert_equal(SortableSet.new([3, 1, 2, 3, 5]), SortableSet.new([5, 2, 3, 1]).add(2))
26
+ end
27
+
28
+ def test_dup
29
+ s1 = SortableSet.new([1, 2, 3]){|a, b| b <=> a}
30
+ s2 = s1.dup
31
+ assert_equal(s1.to_a, s2.to_a)
32
+
33
+ s2.add(4)
34
+ assert_equal(Set.new([1, 2, 3]), s1)
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'abst'
4
+
5
+ class TC_Vector < MiniTest::Unit::TestCase
6
+ def test_Vector
7
+ vector = Abst::Vector(Rational, 3)
8
+ assert_equal("Rational", vector.coef_class.name)
9
+ assert_equal(3, vector.size)
10
+
11
+ v = Abst::Vector(Rational, [2, 3, 4])
12
+ assert_equal([2, 3, 4], v.to_a)
13
+ end
14
+
15
+ def test_add
16
+ vector = Abst::Vector(Integer, 4)
17
+ v1 = vector.new([3, 4, 5, 6])
18
+ v2 = vector.new([1, 1, 1, 3])
19
+
20
+ assert_equal([4, 5, 6, 9], (v1 + v2).to_a)
21
+ end
22
+
23
+ def test_sub
24
+ vector = Abst::Vector(Integer, 4)
25
+ v1 = vector.new([3, 4, 5, 6])
26
+ v2 = vector.new([1, 1, 1, 3])
27
+
28
+ assert_equal([2, 3, 4, 3], (v1 - v2).to_a)
29
+ end
30
+
31
+ def test_squared_length
32
+ vector = Abst::Vector(Integer, 4)
33
+ v = vector.new([3, 4, 5, 6])
34
+
35
+ assert_equal(9 + 16 + 25 + 36, v.squared_length)
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: abst
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yasunori Miyamoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: prime,matrix, polynomial,etc
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/abst.rb
21
+ - lib/config.rb
22
+ - lib/include/array.rb
23
+ - lib/include/bisect.rb
24
+ - lib/include/cache.rb
25
+ - lib/include/compatibility.rb
26
+ - lib/include/complex.rb
27
+ - lib/include/float.rb
28
+ - lib/include/fundamental.rb
29
+ - lib/include/graph.rb
30
+ - lib/include/group.rb
31
+ - lib/include/integer.rb
32
+ - lib/include/matrix.rb
33
+ - lib/include/polynomial.rb
34
+ - lib/include/prime.rb
35
+ - lib/include/prime_mpqs.rb
36
+ - lib/include/rational.rb
37
+ - lib/include/residue.rb
38
+ - lib/include/ring.rb
39
+ - lib/include/sequence.rb
40
+ - lib/include/set.rb
41
+ - lib/include/vector.rb
42
+ - test/test_all.rb
43
+ - test/test_array.rb
44
+ - test/test_bisect.rb
45
+ - test/test_combination.rb
46
+ - test/test_float.rb
47
+ - test/test_fundamental.rb
48
+ - test/test_group.rb
49
+ - test/test_integer.rb
50
+ - test/test_matrix.rb
51
+ - test/test_polynomial.rb
52
+ - test/test_prime.rb
53
+ - test/test_prime_mpqs.rb
54
+ - test/test_rational.rb
55
+ - test/test_sequence.rb
56
+ - test/test_set.rb
57
+ - test/test_vector.rb
58
+ homepage:
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.11
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Ruby based algebraic number theory system
82
+ test_files:
83
+ - test/test_all.rb
84
+ - test/test_array.rb
85
+ - test/test_bisect.rb
86
+ - test/test_combination.rb
87
+ - test/test_float.rb
88
+ - test/test_fundamental.rb
89
+ - test/test_group.rb
90
+ - test/test_integer.rb
91
+ - test/test_matrix.rb
92
+ - test/test_polynomial.rb
93
+ - test/test_prime.rb
94
+ - test/test_prime_mpqs.rb
95
+ - test/test_rational.rb
96
+ - test/test_sequence.rb
97
+ - test/test_set.rb
98
+ - test/test_vector.rb