continued_fractions 1.6.1 → 1.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 20796325ed2f95282a02bd81c21b78fd95c21d31
4
- data.tar.gz: c0ea003c4ec0d7f2109e7a3084147aedf2b2975a
2
+ SHA256:
3
+ metadata.gz: 6e470cce2d4c42db6d51b74ebb62cd551cf91142e63bd18345bca3b222fc5eb3
4
+ data.tar.gz: af28baf19c09d53d4143629061266773ef9506f0fb5672acb68d0e2cf7c66f94
5
5
  SHA512:
6
- metadata.gz: f00f4c5449144a099abcd4a0f01a04c3302724f4246af9d766f8168767fdf71b6409af806601a4a58889bd60d71bc12ade5ecf49a2f252cf89e924f3d174f4c4
7
- data.tar.gz: 7b84d72a3c6a4648fce6a5e3db00ff760e901e0ec1e0386a577148a119055c9ac77468e7cbf8129d532e3e6f9fdb671030428987543585f6238036c53131d4da
6
+ metadata.gz: 14403e28b7828dd596491b97a676ad5bf3a6c2e11bceadcd636cdef637ba6cc6ea6dc5d5c455de15a87bf03f6f2b8d55f7619b7ab73442b4cf7e530f07a0a819
7
+ data.tar.gz: 2740a521fb624d61b58e9b62e7f3f48bc9b6bc53b58caa65a1a0ef92c7d938e7c6c8f95b099e90ca814cb6e6b4a3a699f591909ef6cb8f3b5831a7f49dd58825
@@ -113,7 +113,7 @@ class ContinuedFraction
113
113
  num = nil
114
114
  prec = nil
115
115
  case n
116
- when Fixnum, Integer
116
+ when Float, Integer, Rational
117
117
  num = n
118
118
  prec = limit
119
119
  when ContinuedFraction
@@ -1,7 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), "/../spec_helper")
2
2
 
3
3
  describe ContinuedFraction do
4
- let(:cf) { described_class.new(number,10) }
4
+ let(:cf) { described_class.new(number, 10) }
5
5
  let(:number) { rand }
6
6
 
7
7
  describe '#convergents' do
@@ -12,7 +12,7 @@ describe ContinuedFraction do
12
12
  context 'with irrational numbers' do
13
13
  it "accurately calculates the convergents" do
14
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)
15
+ convs = [3/1r, 22/7r, 333/106r, 355/113r, 103993/33102r, 104348/33215r, 208341/66317r, 312689/99532r, 833719/265381r, 1146408/364913r]
16
16
  cf = described_class.new(Math::PI,10)
17
17
  expect((cf.convergents_as_rationals - convs)).to be_empty
18
18
  end
@@ -38,7 +38,7 @@ describe ContinuedFraction do
38
38
  end
39
39
 
40
40
  it 'calculates the convergents' do
41
- convs = [ '1/1', '3/2' ].map(&:to_r)
41
+ convs = [ 1/1r, 3/2r ]
42
42
  expect(described_class.new(1.5, 10).convergents_as_rationals - convs).to be_empty
43
43
  end
44
44
  end
@@ -51,54 +51,20 @@ describe ContinuedFraction do
51
51
  end
52
52
 
53
53
  describe 'operators' do
54
+ let(:cf2) { described_class.new(rand, 20) }
55
+
56
+ %i{+ - * /}.each do |op|
57
+ describe "#{op}" do
58
+ [3, 3.0, 3/1r, described_class.new(rand, 20)].each do |rhs|
59
+ it "#{rhs.class.name} operates on the right-hand side and returns a ContinuedFraction" do
60
+ expect(cf.send(op, rhs)).to be_kind_of(ContinuedFraction)
61
+ end
62
+ end
54
63
 
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)
64
+ it "Assigns the max limit of the two operands" do
65
+ result = cf.send(op, cf2)
66
+ expect(result.limit).to eq [cf.limit, cf2.limit].max
67
+ end
102
68
  end
103
69
  end
104
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: continued_fractions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia
@@ -65,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '1.2'
67
67
  requirements: []
68
- rubyforge_project: continued_fractions
69
- rubygems_version: 2.5.1
68
+ rubygems_version: 3.0.3
70
69
  signing_key:
71
70
  specification_version: 4
72
71
  summary: Generate continued fractions