closestfib 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -10,4 +10,5 @@ group :development do
10
10
  gem "bundler", "~> 1.0.0"
11
11
  gem "jeweler", "~> 1.6.4"
12
12
  gem "rcov", ">= 0"
13
+ gem 'rdoc', ">= 0"
13
14
  end
data/README.rdoc CHANGED
@@ -1,6 +1,9 @@
1
1
  = closestfib
2
2
 
3
- Description goes here.
3
+ Written by Richard Nygord on 9/10/11
4
+
5
+ Find the closest fibonacci number less than n
6
+ by adding method closest_fibonacci to Fixnum and Bignum
4
7
 
5
8
  == Contributing to closestfib
6
9
 
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.homepage = "http://github.com/RichNygord/closestfib"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Finds the closest fibonacci < n}
21
- gem.description = %Q{Finds the closest fibonacci < n with ClosestFib.find}
21
+ gem.description = %Q{Adds closest_fibonacci to Fixnum and Bignum}
22
22
  gem.email = "rvnygord@yahoo.com"
23
23
  gem.authors = ["Richard Nygord"]
24
24
  # dependencies defined in Gemfile
@@ -42,8 +42,8 @@ end
42
42
 
43
43
  task :default => :test
44
44
 
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
45
+ require 'rdoc/task'
46
+ RDoc::Task.new do |rdoc|
47
47
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
48
 
49
49
  rdoc.rdoc_dir = 'rdoc'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/closestfib.rb CHANGED
@@ -1,18 +1,20 @@
1
- # Written by Richard Nygord
2
- # Modified on 9/9/11
3
- # Find the closest fibonacci < n
1
+ # Written by Richard Nygord, Copyright (c) 2011
2
+ # Created on 9/10/11
3
+ # Find the closest fibonacci number less than n
4
+ # Adds method closest_fibonacci to Fixnum and Bignum
4
5
 
5
6
  module ClosestFib
6
-
7
+ class Error < RuntimeError
8
+ end
9
+
7
10
  class Fibs
8
11
  @@fibs = [0,1]
9
12
 
10
13
  class << self
11
14
  def fib n
12
- raise(RuntimeError, "fib index can't be negative") if n < 0
13
15
  if n > 1
14
16
  while @@fibs[n] == nil do
15
- self.next_fib
17
+ next_fib
16
18
  end
17
19
  end
18
20
  @@fibs[n]
@@ -27,20 +29,30 @@ module ClosestFib
27
29
  end
28
30
 
29
31
  def next_fib
30
- @@fibs[@@fibs.length] = self.prev_fib + self.last_fib
32
+ @@fibs[@@fibs.length] = prev_fib + last_fib
31
33
  end
32
- end
34
+ end
33
35
  end
34
-
35
- def self.find f
36
- raise(RuntimeError, "no fibonacci numbers are negative") if f <= 0
36
+
37
+ def self.closestfib x
38
+ raise(Error, "no fibonacci numbers are negative") if x <= 0
37
39
  n=0
38
- while (Fibs.fib n) < f do
40
+ while (Fibs.fib n) < x do
39
41
  n += 1
40
42
  end
41
43
  Fibs.fib n-1
42
44
  end
45
+ end
43
46
 
47
+ class Fixnum
48
+ def closest_fibonacci
49
+ ClosestFib.closestfib self
50
+ end
44
51
  end
45
52
 
53
+ class Bignum
54
+ def closest_fibonacci
55
+ ClosestFib.closestfib self
56
+ end
57
+ end
46
58
 
@@ -1,7 +1,16 @@
1
1
  require 'helper'
2
2
 
3
- class TestClosestfib < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
3
+ class TestClosestFib < Test::Unit::TestCase
4
+ def test_closest_fibonacci
5
+ assert_equal( 0, 1.closest_fibonacci )
6
+ assert_equal( 1, 2.closest_fibonacci )
7
+ assert_equal( 2, 3.closest_fibonacci )
8
+ assert_equal( 13, 14.closest_fibonacci )
9
+ assert_equal( 144, 156.closest_fibonacci )
10
+ assert_equal( 89, 99.closest_fibonacci )
11
+ assert_equal( 956722026041, 956722026042.closest_fibonacci )
12
+ ex = assert_raise(ClosestFib::Error) { 0.closest_fibonacci }
13
+ assert_match( /no fibonacci numbers are negative/, ex.message )
6
14
  end
7
15
  end
16
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: closestfib
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Richard Nygord
@@ -56,7 +56,18 @@ dependencies:
56
56
  type: :development
57
57
  prerelease: false
58
58
  version_requirements: *id004
59
- description: Finds the closest fibonacci < n with ClosestFib.find
59
+ - !ruby/object:Gem::Dependency
60
+ name: rdoc
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ description: Adds closest_fibonacci to Fixnum and Bignum
60
71
  email: rvnygord@yahoo.com
61
72
  executables: []
62
73
 
@@ -88,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
99
  requirements:
89
100
  - - ">="
90
101
  - !ruby/object:Gem::Version
91
- hash: -1025349837
102
+ hash: 314006893
92
103
  segments:
93
104
  - 0
94
105
  version: "0"