continued_fractions 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 833e0f015fc2902302f744f7c1c4901b8b77e51f
4
- data.tar.gz: 65ca91e63bfa5adac66a77529de915d9d3bb6145
3
+ metadata.gz: 20796325ed2f95282a02bd81c21b78fd95c21d31
4
+ data.tar.gz: c0ea003c4ec0d7f2109e7a3084147aedf2b2975a
5
5
  SHA512:
6
- metadata.gz: 9267372f711ade8ce6da446a79bd8e3e869361a96f47cd16286ae5a3a22e2be848979da6e0188b959dd8dc1aaaf9de5d0b2ab539fdf65cf0a281e8a35fe73944
7
- data.tar.gz: f332b7f14cef53dc9e84f1eef4eacd5bb62aac97f06e9e62ea39a3b274e48bf66e1c67d5ae853b6af2bd5102e8de45f9c91761d98ca3985e046fca8f50054946
6
+ metadata.gz: f00f4c5449144a099abcd4a0f01a04c3302724f4246af9d766f8168767fdf71b6409af806601a4a58889bd60d71bc12ade5ecf49a2f252cf89e924f3d174f4c4
7
+ data.tar.gz: 7b84d72a3c6a4648fce6a5e3db00ff760e901e0ec1e0386a577148a119055c9ac77468e7cbf8129d532e3e6f9fdb671030428987543585f6238036c53131d4da
data/Gemfile CHANGED
@@ -1,11 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Declare your gem's dependencies in digital_measures.gemspec.
4
- # Bundler will treat runtime dependencies like base dependencies, and
5
- # development dependencies will be added by default to the :development group.
3
+ # Specify your gem's dependencies in continued_fractions.gemspec
6
4
  gemspec
7
-
8
- # Declare any dependencies that are still in development here instead of in
9
- # your gemspec. These might include edge Rails or gems from your path or
10
- # Git. Remember to move these dependencies to your gemspec before releasing
11
- # your gem to rubygems.org.
data/Rakefile CHANGED
@@ -1,21 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
4
3
 
5
- Echoe.new('continued_fractions', '1.6.0') do |config|
6
- config.summary = 'Generate continued fractions'
7
- config.description = 'Class for working with continued fractions'
8
-
9
- config.ruby_version = ">=2.2.2"
10
- config.licenses = 'MIT'
11
-
12
- config.author = 'Jose Hales-Garcia'
13
- config.email = 'jolohaga@me.com'
14
- config.url = 'http://jolohaga.github.io/continued_fractions'
15
-
16
- config.ignore_pattern = ["tmp/*",".hg/*", ".pkg/*", ".git/*"]
4
+ RSpec::Core::RakeTask.new(:spec)
17
5
 
18
- config.development_dependencies = ['rspec ~>3.2.0','echoe ~>4.6.6']
19
- end
20
-
21
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|ext| load ext}
6
+ task :default => :spec
@@ -1,38 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: continued_fractions 1.6.0 ruby lib
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'continued_fractions/version'
3
5
 
4
- Gem::Specification.new do |s|
5
- s.name = "continued_fractions"
6
- s.version = "1.6.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "continued_fractions"
8
+ spec.version = ContinuedFractions::VERSION
7
9
 
8
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
9
- s.require_paths = ["lib"]
10
- s.authors = ["Jose Hales-Garcia"]
11
- s.date = "2015-05-10"
12
- s.description = "Class for working with continued fractions"
13
- s.email = "jolohaga@me.com"
14
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "lib/continued_fractions.rb"]
15
- s.files = ["CHANGELOG", "Gemfile", "History.txt", "LICENSE", "Manifest", "README.md", "Rakefile", "continued_fractions.gemspec", "lib/continued_fractions.rb", "spec/continued_fractions/continued_fraction_spec.rb", "spec/spec_helper.rb"]
16
- s.homepage = "http://jolohaga.github.io/continued_fractions"
17
- s.licenses = ["MIT"]
18
- s.rdoc_options = ["--line-numbers", "--title", "Continued_fractions", "--main", "README.md"]
19
- s.required_ruby_version = Gem::Requirement.new(">= 2.2.2")
20
- s.rubyforge_project = "continued_fractions"
21
- s.rubygems_version = "2.4.5"
22
- s.summary = "Generate continued fractions"
10
+ spec.required_rubygems_version = Gem::Requirement.new(">= 1.2") if spec.respond_to? :required_rubygems_version=
11
+ spec.require_paths = ["lib"]
12
+ spec.authors = ["Jose Hales-Garcia"]
13
+ spec.date = "2016-10-26"
14
+ spec.description = "Class for working with continued fractions"
15
+ spec.email = "jolohaga@me.com"
16
+ spec.extra_rdoc_files = ["LICENSE", "README.md", "lib/continued_fractions.rb"]
17
+ spec.files = ["Gemfile", "LICENSE", "README.md", "Rakefile", "continued_fractions.gemspec", "lib/continued_fractions.rb", "spec/continued_fractions/continued_fraction_spec.rb", "spec/spec_helper.rb"]
18
+ spec.homepage = "http://jolohaga.github.io/continued_fractions"
19
+ spec.licenses = ["MIT"]
20
+ spec.rdoc_options = ["--line-numbers", "--title", "Continued_fractions", "--main", "README.md"]
21
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.2.2")
22
+ spec.rubyforge_project = "continued_fractions"
23
+ spec.rubygems_version = "2.5.1"
24
+ spec.summary = "Generate continued fractions"
23
25
 
24
- if s.respond_to? :specification_version then
25
- s.specification_version = 4
26
+ if spec.respond_to? :specification_version then
27
+ spec.specification_version = 4
26
28
 
27
29
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
- s.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
29
- s.add_development_dependency(%q<echoe>, ["~> 4.6.6"])
30
+ spec.add_development_dependency(%q<rspec>, ["~> 3.2"])
30
31
  else
31
- s.add_dependency(%q<rspec>, ["~> 3.2.0"])
32
- s.add_dependency(%q<echoe>, ["~> 4.6.6"])
32
+ spec.add_dependency(%q<rspec>, ["~> 3.2"])
33
33
  end
34
34
  else
35
- s.add_dependency(%q<rspec>, ["~> 3.2.0"])
36
- s.add_dependency(%q<echoe>, ["~> 4.6.6"])
35
+ spec.add_dependency(%q<rspec>, ["~> 3.2"])
37
36
  end
38
37
  end
@@ -112,11 +112,11 @@ class ContinuedFraction
112
112
  def number_of(n) #:nodoc:
113
113
  num = nil
114
114
  prec = nil
115
- case n.class.name
116
- when "Fixnum","Integer"
115
+ case n
116
+ when Fixnum, Integer
117
117
  num = n
118
118
  prec = limit
119
- when "ContinuedFraction"
119
+ when ContinuedFraction
120
120
  num = n.number
121
121
  prec = [n.limit,limit].max
122
122
  end
@@ -151,4 +151,4 @@ class ContinuedFraction
151
151
  conv_mat[0][0],conv_mat[1][1] = 0,0
152
152
  conv_mat
153
153
  end
154
- end
154
+ end
@@ -3,88 +3,103 @@ require File.join(File.dirname(__FILE__), "/../spec_helper")
3
3
  describe ContinuedFraction do
4
4
  let(:cf) { described_class.new(number,10) }
5
5
  let(:number) { rand }
6
-
7
- it "returns an array of convergents" do
8
- expect(cf.convergents).to be_kind_of(Array)
9
- end
10
-
11
- it "preserves the number input" do
12
- expect(cf.number).to eq number
13
- end
14
-
15
- it "adds a number on the right-hand-side with a continued fraction and returns a continued fraction" do
16
- expect((cf + 3)).to be_kind_of(ContinuedFraction)
17
- end
18
-
19
- it "subtracts a number on the right-hand-side from a continued fraction and returns a continued fraction" do
20
- expect((cf - 3)).to be_kind_of(ContinuedFraction)
21
- end
22
-
23
- it "multiplies a number on the right-hand-side with a continued fraction and returns a continued fraction" do
24
- expect((cf * 3)).to be_kind_of(ContinuedFraction)
25
- end
26
-
27
- it "divides a number on the right-hand-side with a continued fraction and returns a continued fraction" do
28
- expect((cf / 3)).to be_kind_of(ContinuedFraction)
29
- end
30
-
31
- it "adds a continued fraction with another continued fraction and returns a continued fraction" do
32
- c = described_class.new(rand,20)
33
- expect((cf + c)).to be_kind_of(ContinuedFraction)
34
- end
35
-
36
- it "subtracts a continued fraction with another continued fraction and returns a continued fraction" do
37
- c = described_class.new(rand,20)
38
- expect((cf - c)).to be_kind_of(ContinuedFraction)
39
- end
40
-
41
- it "multiplies a continued fraction with another continued fraction and returns a continued fraction" do
42
- c = described_class.new(rand,20)
43
- expect((cf * c)).to be_kind_of(ContinuedFraction)
44
- end
45
-
46
- it "divides a continued fraction with another continued fraction and returns a continued fraction" do
47
- c = described_class.new(rand,20)
48
- expect((cf / c)).to be_kind_of(ContinuedFraction)
49
- end
50
-
51
- it "assigns the resulting continued fraction of a binary operation the max limit of the two operands" do
52
- c = described_class.new(rand,20)
53
- result = cf + c
54
- expect(result.limit).to eq [cf.limit,c.limit].max
55
- end
56
-
57
- context 'with irrational numbers' do
58
- it "accurately calculates the convergents" do
59
- # First 10 convergents of PI are...
60
- convs = ['3/1', '22/7', '333/106', '355/113', '103993/33102', '104348/33215', '208341/66317', '312689/99532', '833719/265381', '1146408/364913'].map{|c| Rational(c)}
61
- cf = described_class.new(Math::PI,10)
62
- expect((cf.convergents_as_rationals - convs)).to be_empty
6
+
7
+ describe '#convergents' do
8
+ it "returns an array" do
9
+ expect(cf.convergents).to be_kind_of(Array)
63
10
  end
64
-
65
- it "contains convergents approaching the number" do
66
- 0.upto(cf.convergents.length-2) do |i|
67
- convergent_rational_i_plus1, convergent_rational_i = cf.convergent_to_rational(cf.convergents[i+1]), cf.convergent_to_rational(cf.convergents[i])
68
- expect(((convergent_rational_i_plus1 - cf.number).abs <= (convergent_rational_i - cf.number).abs)).to be true
11
+
12
+ context 'with irrational numbers' do
13
+ it "accurately calculates the convergents" do
14
+ # First 10 convergents of PI are...
15
+ convs = ['3/1', '22/7', '333/106', '355/113', '103993/33102', '104348/33215', '208341/66317', '312689/99532', '833719/265381', '1146408/364913'].map(&:to_r)
16
+ cf = described_class.new(Math::PI,10)
17
+ expect((cf.convergents_as_rationals - convs)).to be_empty
18
+ end
19
+
20
+ it "contains convergents approaching the number" do
21
+ 0.upto(cf.convergents.length-2) do |i|
22
+ convergent_rational_i_plus1, convergent_rational_i = cf.convergent_to_rational(cf.convergents[i+1]), cf.convergent_to_rational(cf.convergents[i])
23
+ expect(((convergent_rational_i_plus1 - cf.number).abs <= (convergent_rational_i - cf.number).abs)).to be true
24
+ end
25
+ end
26
+
27
+ it "contains convergents which are expressed in lowest terms" do
28
+ 1.upto(cf.convergents.length-1) do |i|
29
+ convergent_rational_i, convergent_rational_i_plus1 = cf.convergent_to_rational(cf.convergent(i)), cf.convergent_to_rational(cf.convergent(i+1))
30
+ expect((convergent_rational_i.numerator*convergent_rational_i_plus1.denominator - convergent_rational_i_plus1.numerator*convergent_rational_i.denominator)).to eq (-1)**(i)
31
+ end
69
32
  end
70
33
  end
34
+
35
+ context 'with rational numbers' do
36
+ it 'changes the limit to the number of convergents calculated' do
37
+ expect(described_class.new(1.5, 10).limit).to be 2
38
+ end
71
39
 
72
- it "contains convergents which are expressed in lowest terms" do
73
- 1.upto(cf.convergents.length-1) do |i|
74
- convergent_rational_i, convergent_rational_i_plus1 = cf.convergent_to_rational(cf.convergent(i)), cf.convergent_to_rational(cf.convergent(i+1))
75
- expect((convergent_rational_i.numerator*convergent_rational_i_plus1.denominator - convergent_rational_i_plus1.numerator*convergent_rational_i.denominator)).to eq (-1)**(i)
40
+ it 'calculates the convergents' do
41
+ convs = [ '1/1', '3/2' ].map(&:to_r)
42
+ expect(described_class.new(1.5, 10).convergents_as_rationals - convs).to be_empty
76
43
  end
77
44
  end
78
45
  end
79
-
80
- context 'with rational numbers' do
81
- it 'changes the limit to the number of convergents calculated' do
82
- expect(described_class.new(1.5, 10).limit).to be 2
46
+
47
+ describe '#number' do
48
+ it "preserves the number input" do
49
+ expect(cf.number).to eq number
83
50
  end
84
-
85
- it 'calculates the convergents' do
86
- convs = [ '1/1', '3/2' ].map{|c| Rational(c)}
87
- expect(described_class.new(1.5, 10).convergents_as_rationals - convs).to be_empty
51
+ end
52
+
53
+ describe 'operators' do
54
+
55
+ it "assigns the resulting continued fraction of a binary operation the max limit of the two operands" do
56
+ c = described_class.new(rand,20)
57
+ result = cf + c
58
+ expect(result.limit).to eq [cf.limit,c.limit].max
59
+ end
60
+
61
+ describe '+' do
62
+ it "adds a number on the right-hand-side with a continued fraction and returns a continued fraction" do
63
+ expect((cf + 3)).to be_kind_of(ContinuedFraction)
64
+ end
65
+
66
+ it "adds a continued fraction with another continued fraction and returns a continued fraction" do
67
+ c = described_class.new(rand,20)
68
+ expect((cf + c)).to be_kind_of(ContinuedFraction)
69
+ end
70
+ end
71
+
72
+ describe '-' do
73
+ it "subtracts a number on the right-hand-side from a continued fraction and returns a continued fraction" do
74
+ expect((cf - 3)).to be_kind_of(ContinuedFraction)
75
+ end
76
+
77
+ it "subtracts a continued fraction with another continued fraction and returns a continued fraction" do
78
+ c = described_class.new(rand,20)
79
+ expect((cf - c)).to be_kind_of(ContinuedFraction)
80
+ end
81
+ end
82
+
83
+ describe '*' do
84
+ it "multiplies a number on the right-hand-side with a continued fraction and returns a continued fraction" do
85
+ expect((cf * 3)).to be_kind_of(ContinuedFraction)
86
+ end
87
+
88
+ it "multiplies a continued fraction with another continued fraction and returns a continued fraction" do
89
+ c = described_class.new(rand,20)
90
+ expect((cf * c)).to be_kind_of(ContinuedFraction)
91
+ end
92
+ end
93
+
94
+ describe '/' do
95
+ it "divides a number on the right-hand-side with a continued fraction and returns a continued fraction" do
96
+ expect((cf / 3)).to be_kind_of(ContinuedFraction)
97
+ end
98
+
99
+ it "divides a continued fraction with another continued fraction and returns a continued fraction" do
100
+ c = described_class.new(rand,20)
101
+ expect((cf / c)).to be_kind_of(ContinuedFraction)
102
+ end
88
103
  end
89
104
  end
90
105
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,13 @@
1
1
  $LOAD_PATH << File.join(File.dirname(__FILE__), "/../lib")
2
2
  require 'rubygems'
3
3
  require 'rspec'
4
- require 'continued_fractions'
4
+ require 'continued_fractions'
5
+
6
+ RSpec.configure do |config|
7
+ # Run specs in random order to surface order dependencies. If you find an
8
+ # order dependency and want to debug it, you can fix the order by providing
9
+ # the seed, which is printed after each run.
10
+ # --seed 1234
11
+ config.order = "random"
12
+ config.formatter = :documentation
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: continued_fractions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,43 +16,25 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: '3.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: echoe
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 4.6.6
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 4.6.6
26
+ version: '3.2'
41
27
  description: Class for working with continued fractions
42
28
  email: jolohaga@me.com
43
29
  executables: []
44
30
  extensions: []
45
31
  extra_rdoc_files:
46
- - CHANGELOG
47
32
  - LICENSE
48
33
  - README.md
49
34
  - lib/continued_fractions.rb
50
35
  files:
51
- - CHANGELOG
52
36
  - Gemfile
53
- - History.txt
54
37
  - LICENSE
55
- - Manifest
56
38
  - README.md
57
39
  - Rakefile
58
40
  - continued_fractions.gemspec
@@ -84,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
66
  version: '1.2'
85
67
  requirements: []
86
68
  rubyforge_project: continued_fractions
87
- rubygems_version: 2.4.5
69
+ rubygems_version: 2.5.1
88
70
  signing_key:
89
71
  specification_version: 4
90
72
  summary: Generate continued fractions
data/CHANGELOG DELETED
@@ -1,13 +0,0 @@
1
- v0.1.0 Initial release
2
-
3
- v1.1.0 Change public class representation of convergents from an array of Rationals to an array of arrays.
4
-
5
- v1.2.0 Change parameter signature of ContinuedFraction#convergents_as_rationals
6
-
7
- v1.3.0 Add binary operators: + - * /
8
-
9
- v1.4.0 Eliminate need to invoke "include ContinuedFractions"
10
-
11
- v1.5.0 Remove ContinuedFractions module; Move its methods into ContinuedFraction class
12
-
13
- v1.6.0 Handle rational numbers, finite continued fractions
data/History.txt DELETED
@@ -1,86 +0,0 @@
1
- === 1.3.0 / 2011-06-10
2
-
3
- * Added binary operators: + - * / between two ContinuedFractions and a ContinuedFraction and a number (on the right-hand-side). Returns a ContinuedFraction.
4
- * Added tests for operators.
5
-
6
- === 1.2.3 / 2011-06-09
7
-
8
- * Fixed emplementation of #convergent to match its definition.
9
- * Added exception on #convergent to be raised when index is less than 1.
10
- * Added mention of ContinuedFractions#convergents_as_rationals in README
11
- * Changed README example. Variable real changed to pi.
12
-
13
- === 1.2.2 / 2010-03-27
14
-
15
- * Moved repo to Git.
16
-
17
- === 1.2.1 / 2010-03-18
18
-
19
- * Updated README file to display change in return class of ContinuedFractions#convergents.
20
-
21
- === 1.2.0 / 2010-03-18
22
-
23
- * Changed parameter signature of ContinuedFraction#convergents_as_rationals. Added a nth parameter to select the length of the convergents to return.
24
-
25
- === 1.1.0 / 2010-03-18
26
-
27
- * Changed the public class representation of convergents from an array of Rationals to an array of arrays.
28
- * Removed convergents_array (unnecessary since ContinuedFraction#convergents now returns an array).
29
- * Added ContinuedFraction#convergents_as_rationals which facilitate returning convergents as Rationals.
30
- * Changed names of index variables to be more descriptive.
31
- * Changed documentation to reflect change of class type returned by ContinuedFraction#convergents.
32
- * Changed tests to deal with new class type returned by ContinuedFraction#convergents.
33
-
34
- === 0.1.12 / 2010-03-18
35
-
36
- * Added examples in the documentation.
37
- * Moved convergents to the Class level to make it accessible to use with any quotient array passed to it.
38
-
39
-
40
- === 0.1.11 / 2010-03-16
41
-
42
- * Changed names of some variable to provide better in-code documentation.
43
-
44
- === 0.1.10 / 2010-03-16
45
-
46
- * Improved documentation and formatting.
47
-
48
- === 0.1.9 / 2010-03-15
49
-
50
- * Added the lowest term test.
51
- * Removed begin..end exception block which was hiding failing limit test.
52
- * Fixed limit test.
53
-
54
- === 0.1.8 / 2010-03-15
55
-
56
- * Added Rdoc comments.
57
-
58
- === 0.1.7 / 2010-03-15
59
-
60
- * Including spec files in distribution (forgot to add them to the manifest).
61
-
62
- === 0.1.6 / 2010-03-15
63
-
64
- * Refactored code generating matrix that holds convergences. Renamed the method convergence_matrix.
65
- * In calculate_convergences, refactored multiple occurances of i-1 and i-2, assigning the values to variables at the top of the iterations.
66
-
67
- === 0.1.5 / 2010-03-15
68
-
69
- * Minor changes to README
70
- * Added :nodoc: to Matrix singleton class method.
71
-
72
- === 0.1.4 / 2010-03-15
73
-
74
- * Added Rspec files and tests.
75
-
76
- === 0.1.3 / 2010-03-13
77
-
78
- * Changed url to the Bitbucket site.
79
-
80
- === 0.1.2 / 2010-03-13
81
-
82
- * Fixed the documentation.
83
-
84
- === 0.1.0 / 2010-03-13
85
-
86
- * Initial Release of ContinuedFractions
data/Manifest DELETED
@@ -1,10 +0,0 @@
1
- CHANGELOG
2
- Gemfile
3
- History.txt
4
- LICENSE
5
- Manifest
6
- README.md
7
- Rakefile
8
- lib/continued_fractions.rb
9
- spec/continued_fractions/continued_fraction_spec.rb
10
- spec/spec_helper.rb