simple_fibonacci 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +11 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/lib/ext/core/integer.rb +15 -0
- data/simple_fibonacci.gemspec +60 -0
- data/simple_fibonacci.rb +5 -0
- data/spec/lib/ext/core/integer_spec.rb +35 -0
- metadata +126 -0
data/.document
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
gemcutter (0.7.0)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rake (0.9.2)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
gemcutter
|
27
|
+
jeweler (~> 1.6.4)
|
28
|
+
rspec (= 2.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Anjali Shenoy
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "simple_fibonacci"
|
18
|
+
gem.homepage = "http://github.com/anjshenoy/simple_fibonacci"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Gem that calculates fibonacci numbers upto a a provided number}
|
21
|
+
gem.description = %Q{Overrides Ruby code Integer class to provide a fibonacci number less than supplied argument}
|
22
|
+
gem.email = "anjshenoy@gmail.com"
|
23
|
+
gem.authors = ["Anjali Shenoy"]
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
desc "Run all specs"
|
30
|
+
task :spec do
|
31
|
+
exec "rspec spec/lib/ext/core/*_spec.rb -c -fd"
|
32
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Integer
|
2
|
+
|
3
|
+
def closest_fibonacci
|
4
|
+
raise InvalidArgumentError.new("Cannot be less than zero") if self < 0
|
5
|
+
return self if [0,1].include?(self)
|
6
|
+
x, y = 1, 1
|
7
|
+
while((x+y) < self) do
|
8
|
+
x, y = (x+y), x
|
9
|
+
end
|
10
|
+
x
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class InvalidArgumentError < StandardError
|
15
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{simple_fibonacci}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Anjali Shenoy"]
|
12
|
+
s.date = %q{2011-08-10}
|
13
|
+
s.description = %q{Overrides Ruby code Integer class to provide a fibonacci number less than supplied argument}
|
14
|
+
s.email = %q{anjshenoy@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/ext/core/integer.rb",
|
28
|
+
"simple_fibonacci.gemspec",
|
29
|
+
"simple_fibonacci.rb",
|
30
|
+
"spec/lib/ext/core/integer_spec.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/anjshenoy/simple_fibonacci}
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{Gem that calculates fibonacci numbers upto a a provided number}
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
|
44
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
45
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
46
|
+
s.add_development_dependency(%q<gemcutter>, [">= 0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
49
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
s.add_dependency(%q<gemcutter>, [">= 0"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
57
|
+
s.add_dependency(%q<gemcutter>, [">= 0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/simple_fibonacci.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../../../lib/ext/core/integer"
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
context "calculate the sequence up to a given integer" do
|
5
|
+
it "starts out with a base value of 1" do
|
6
|
+
1.closest_fibonacci.should == 1
|
7
|
+
end
|
8
|
+
it "returns 0 if supplied with 0" do
|
9
|
+
0.closest_fibonacci.should == 0
|
10
|
+
end
|
11
|
+
it "returns 1 if supplied with 2" do
|
12
|
+
2.closest_fibonacci.should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns 2 if supplied with an upper bound of 3" do
|
16
|
+
3.closest_fibonacci.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns 3 if supplied with an upper bound of 4" do
|
20
|
+
4.closest_fibonacci.should == 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns 2 if supplied with an upper bound of 3" do
|
24
|
+
21.closest_fibonacci.should == 13
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can come up with really large fibonacci numbers since its not recursive and won't break the stack" do
|
28
|
+
503240000.closest_fibonacci == 433494437
|
29
|
+
end
|
30
|
+
|
31
|
+
it "throws an error if self is negative" do
|
32
|
+
lambda{-1.closest_fibonacci}.should raise_error(InvalidArgumentError, "Cannot be less than zero")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_fibonacci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Anjali Shenoy
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-08-10 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
type: :development
|
23
|
+
name: rspec
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 6
|
31
|
+
- 0
|
32
|
+
version: 2.6.0
|
33
|
+
requirement: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
type: :development
|
37
|
+
name: bundler
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
requirement: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
name: jeweler
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 6
|
59
|
+
- 4
|
60
|
+
version: 1.6.4
|
61
|
+
requirement: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
name: gemcutter
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirement: *id004
|
74
|
+
description: Overrides Ruby code Integer class to provide a fibonacci number less than supplied argument
|
75
|
+
email: anjshenoy@gmail.com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files:
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.rdoc
|
83
|
+
files:
|
84
|
+
- .document
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.rdoc
|
89
|
+
- Rakefile
|
90
|
+
- VERSION
|
91
|
+
- lib/ext/core/integer.rb
|
92
|
+
- simple_fibonacci.gemspec
|
93
|
+
- simple_fibonacci.rb
|
94
|
+
- spec/lib/ext/core/integer_spec.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://github.com/anjshenoy/simple_fibonacci
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.3.6
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Gem that calculates fibonacci numbers upto a a provided number
|
125
|
+
test_files: []
|
126
|
+
|