continued_fractions 1.7.0 → 1.8.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
2
  SHA256:
3
- metadata.gz: 6e470cce2d4c42db6d51b74ebb62cd551cf91142e63bd18345bca3b222fc5eb3
4
- data.tar.gz: af28baf19c09d53d4143629061266773ef9506f0fb5672acb68d0e2cf7c66f94
3
+ metadata.gz: 9253bbf7cf75a29375e99c2bdec92f643413eba529a1d360e0165d2ce98fbdd7
4
+ data.tar.gz: '09063bf865028894dd41c43bc47118d8445dd79811154f7c862cf1ab696cff93'
5
5
  SHA512:
6
- metadata.gz: 14403e28b7828dd596491b97a676ad5bf3a6c2e11bceadcd636cdef637ba6cc6ea6dc5d5c455de15a87bf03f6f2b8d55f7619b7ab73442b4cf7e530f07a0a819
7
- data.tar.gz: 2740a521fb624d61b58e9b62e7f3f48bc9b6bc53b58caa65a1a0ef92c7d938e7c6c8f95b099e90ca814cb6e6b4a3a699f591909ef6cb8f3b5831a7f49dd58825
6
+ metadata.gz: ce2f1dbad5629bef37ea84ceaa549005e0c0c73931ecbf54e36f3f779b22c3256505e4719fe3095fbaa116937ed01307eeded90547491db96084994a6459e77b
7
+ data.tar.gz: 1b881899377e3ba060db5d03666ac3451703a169bf768bee1aebc5e512b91c8bc1c5c15373669514854b33cf623449e8588a329f6a68026a22363d268efae2c7
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- ## ContinuedFractions
1
+ # ContinuedFractions
2
2
 
3
3
  * http://rubygems.org/gems/continued_fractions
4
4
 
5
- #### Description
5
+ ## Description
6
6
 
7
7
  Generates quotients and convergents for a given number.
8
8
 
9
- #### Synopsis
9
+ ## Synopsis
10
10
 
11
11
  require 'continued_fractions'
12
12
 
@@ -38,17 +38,20 @@ Generates quotients and convergents for a given number.
38
38
  cf + cf2
39
39
  => #<ContinuedFractions::ContinuedFraction:0x000001009d2708 @number=3.1799344075396196, @limit=20, @quotients=[3, 5, 1, 1, 3, 1, 5, 3, 7, 25, 1, 2, 15, 6, 1, 1, 2, 3, 1, 2], @convergents=[[3, 1], [16, 5], [19, 6], [35, 11], [124, 39], [159, 50], [919, 289], [2916, 917], [21331, 6708], [536191, 168617], [557522, 175325], [1651235, 519267], [25326047, 7964330], [153607517, 48305247], [178933564, 56269577], [332541081, 104574824], [844015726, 265419225], [2864588259, 900832499], [3708603985, 1166251724], [10281796229, 3233335947]]>
40
40
 
41
- #### Install
41
+ ## Install
42
42
 
43
43
  sudo gem install continued_fractions
44
44
 
45
- #### Requirements/Dependencies
45
+ ## Requirements/Dependencies
46
46
 
47
47
  * Ruby 2.2+
48
48
  * Depends on Ruby's Rational class
49
49
 
50
- ##### Developers
50
+ ## Developers
51
51
 
52
52
  * RSpec required to run tests
53
- * Echoe required to run rake tasks
54
-
53
+
54
+ ## Contributors
55
+
56
+ * [Jose Hales-Garcia](https://github.com/jolohaga)
57
+ * [Eoin Kelly](https://github.com/eoinkelly)
@@ -7,6 +7,8 @@
7
7
  #
8
8
  #
9
9
  class ContinuedFraction
10
+ include ::Comparable
11
+
10
12
  attr_accessor :number, :quotients, :limit
11
13
 
12
14
  # For a given number calculate its continued fraction quotients and convergents up to limit.
@@ -99,6 +101,10 @@ class ContinuedFraction
99
101
  evaluate("#{number} * #{num}",prec)
100
102
  end
101
103
  end
104
+
105
+ def <=>(other)
106
+ number <=> other.number
107
+ end
102
108
 
103
109
  def convergent_to_rational(convergent) #:nodoc:
104
110
  Rational(convergent[0],convergent[1])
@@ -108,7 +114,7 @@ class ContinuedFraction
108
114
  def evaluate(exp, prec) #:nodoc:
109
115
  ContinuedFraction.new(eval(exp), prec)
110
116
  end
111
-
117
+
112
118
  def number_of(n) #:nodoc:
113
119
  num = nil
114
120
  prec = nil
@@ -68,4 +68,23 @@ describe ContinuedFraction do
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ describe 'comparing' do
73
+ context 'when numbers are the same' do
74
+ let(:cf2) { described_class.new(cf.number) }
75
+
76
+ it "the ContinuedFractions are equal" do
77
+ expect(cf).to eq cf2
78
+ end
79
+ end
80
+
81
+ context 'when numbers are different' do
82
+ let(:cond) { [['+', '<'], ['-', '>']].sample }
83
+ let(:cf2) { described_class.new(cf.number.send(cond[0], 1.0)) }
84
+
85
+ it "the ContinuedFractions are unequal" do
86
+ expect(cf.send(cond[1], cf2)).to be true
87
+ end
88
+ end
89
+ end
71
90
  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.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Hales-Garcia