continued_fractions 0.1.8 → 0.1.9
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.
- data/History.txt +7 -1
- data/Rakefile +1 -1
- data/continued_fractions.gemspec +1 -1
- data/lib/continued_fractions.rb +3 -0
- data/spec/continued_fractions/continued_fraction_spec.rb +8 -6
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
=== 0.1.9 / 2010-03-15
|
2
|
+
|
3
|
+
* Added the lowest term test.
|
4
|
+
* Removed begin..end exception block which was hiding failing limit test.
|
5
|
+
* Fixed limit test.
|
6
|
+
|
1
7
|
=== 0.1.8 / 2010-03-15
|
2
8
|
|
3
|
-
*
|
9
|
+
* Added Rdoc comments.
|
4
10
|
|
5
11
|
=== 0.1.7 / 2010-03-15
|
6
12
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('continued_fractions', '0.1.
|
5
|
+
Echoe.new('continued_fractions', '0.1.9') do |config|
|
6
6
|
config.summary = 'Generate continued fractions.'
|
7
7
|
config.author = 'Jose Hales-Garcia'
|
8
8
|
config.url = 'http://bitbucket.org/jolohaga/continued_fractions/'
|
data/continued_fractions.gemspec
CHANGED
data/lib/continued_fractions.rb
CHANGED
@@ -15,6 +15,9 @@ module ContinuedFractions #:nodoc:
|
|
15
15
|
|
16
16
|
# For a given number, n, calculate its continued fraction quotients and convergents.
|
17
17
|
#
|
18
|
+
# The quotients and convergents arrays are length 5, by default. Pass an integer for
|
19
|
+
# the second parameter to change the default.
|
20
|
+
#
|
18
21
|
def initialize(n,l=5)
|
19
22
|
@number = n
|
20
23
|
@limit = l
|
@@ -23,12 +23,14 @@ module ContinuedFractions
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should contain convergents approaching the number" do
|
26
|
-
0.upto(@cf.convergents.length) do |i|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
0.upto(@cf.convergents.length-2) do |i|
|
27
|
+
((@cf.convergents[i+1] - @cf.number).abs <= (@cf.convergents[i] - @cf.number).abs).should == true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should contain convergents which are expressed in lowest terms" do
|
32
|
+
1.upto(@cf.convergents.length-1) do |i|
|
33
|
+
(@cf.convergent(i-1).numerator*@cf.convergent(i).denominator - @cf.convergent(i).numerator*@cf.convergent(i-1).denominator).should == (-1)**(i)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|