integer 0.1.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.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/config/boot.rb +114 -0
- data/config/database.yml +22 -0
- data/config/environment.rb +43 -0
- data/config/environments/test.rb +28 -0
- data/config/routes.rb +4 -0
- data/integer.gemspec +62 -0
- data/lib/integer.rb +16 -0
- data/test/test_helper.rb +4 -0
- data/test/test_integer.rb +116 -0
- metadata +143 -0
data/.document
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Mary Wong
|
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
@@ -0,0 +1,19 @@
|
|
1
|
+
= integer
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to integer
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Mary Wong. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
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 = "integer"
|
18
|
+
gem.homepage = "http://github.com/mspwong/integer"
|
19
|
+
gem.license = "mspwong"
|
20
|
+
gem.summary = "extends Integer by adding fibonancci support"
|
21
|
+
gem.description = "This gem adds to the Integer type an extra instance method 'closest_fibonacci_smaller_or_equal_to' which returns the largest fibonancci number that is less than or equal to the integer."
|
22
|
+
gem.authors = ["Mary Wong"]
|
23
|
+
# dependencies defined in Gemfile
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
test.rcov_opts << '--exclude "gems/*"'
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "integer #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/config/boot.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
if load_error.message =~ /Could not find RubyGem rails/
|
66
|
+
STDERR.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
67
|
+
exit 1
|
68
|
+
else
|
69
|
+
raise
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class << self
|
74
|
+
def rubygems_version
|
75
|
+
Gem::RubyGemsVersion rescue nil
|
76
|
+
end
|
77
|
+
|
78
|
+
def gem_version
|
79
|
+
if defined? RAILS_GEM_VERSION
|
80
|
+
RAILS_GEM_VERSION
|
81
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
82
|
+
ENV['RAILS_GEM_VERSION']
|
83
|
+
else
|
84
|
+
parse_gem_version(read_environment_rb)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def load_rubygems
|
89
|
+
min_version = '1.3.2'
|
90
|
+
require 'rubygems'
|
91
|
+
unless rubygems_version >= min_version
|
92
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
rescue LoadError
|
97
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse_gem_version(text)
|
102
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
def read_environment_rb
|
107
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# All that for this:
|
114
|
+
Rails.boot!
|
data/config/database.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
## SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file
|
2
|
+
|
3
|
+
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
+
RAILS_GEM_VERSION = '2.3.12' unless defined? RAILS_GEM_VERSION
|
5
|
+
|
6
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
8
|
+
|
9
|
+
Rails::Initializer.run do |config|
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Add additional load paths for your own custom dirs
|
15
|
+
# config.autoload_paths += %W( #{RAILS_ROOT}/extras )
|
16
|
+
|
17
|
+
# Specify gems that this application depends on and have them installed with rake gems:install
|
18
|
+
# config.gem "bj"
|
19
|
+
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
|
20
|
+
# config.gem "sqlite3-ruby", :lib => "sqlite3"
|
21
|
+
# config.gem "aws-s3", :lib => "aws/s3"
|
22
|
+
|
23
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
24
|
+
# :all can be used as a placeholder for all plugins not explicitly named
|
25
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
26
|
+
|
27
|
+
# Skip frameworks you're not going to use. To use Rails without a database,
|
28
|
+
# you must remove the Active Record framework.
|
29
|
+
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
30
|
+
|
31
|
+
# Activate observers that should always be running
|
32
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
33
|
+
|
34
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
35
|
+
# Run "rake -D time" for a list of tasks for finding time zone names.
|
36
|
+
config.time_zone = 'UTC'
|
37
|
+
|
38
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
39
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
40
|
+
# config.i18n.default_locale = :de
|
41
|
+
|
42
|
+
config.action_controller.session = { :key => "_myapp_session", :secret => "e6fb6fc797f7c95510086db2a45d577d" }
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
2
|
+
|
3
|
+
# The test environment is used exclusively to run your application's
|
4
|
+
# test suite. You never need to work with it otherwise. Remember that
|
5
|
+
# your test database is "scratch space" for the test suite and is wiped
|
6
|
+
# and recreated between test runs. Don't rely on the data there!
|
7
|
+
config.cache_classes = true
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.action_controller.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
config.action_view.cache_template_loading = true
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
24
|
+
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
27
|
+
# like if you have constraints or database-specific column types
|
28
|
+
# config.active_record.schema_format = :sql
|
data/config/routes.rb
ADDED
data/integer.gemspec
ADDED
@@ -0,0 +1,62 @@
|
|
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{integer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mary Wong"]
|
12
|
+
s.date = %q{2011-08-09}
|
13
|
+
s.description = %q{This gem adds to the Integer type an extra instance method 'closest_fibonacci_smaller_or_equal_to' which returns the largest fibonancci number that is less than or equal to the integer.}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"LICENSE.txt",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"config/boot.rb",
|
26
|
+
"config/database.yml",
|
27
|
+
"config/environment.rb",
|
28
|
+
"config/environments/test.rb",
|
29
|
+
"config/routes.rb",
|
30
|
+
"integer.gemspec",
|
31
|
+
"lib/integer.rb",
|
32
|
+
"test/test_helper.rb",
|
33
|
+
"test/test_integer.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/mspwong/integer}
|
36
|
+
s.licenses = ["mspwong"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.6.2}
|
39
|
+
s.summary = %q{extends Integer by adding fibonancci support}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<rails>, ["= 2.3.12"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rails>, ["= 2.3.12"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rails>, ["= 2.3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/lib/integer.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Fibonacci
|
2
|
+
def closest_fibonacci_smaller_or_equal_to
|
3
|
+
|
4
|
+
raise "method 'closest_fibonacci_smaller_or_equal_to' is not available for negative integers" if self < 0
|
5
|
+
|
6
|
+
sequence = [0, 1]
|
7
|
+
sequence << sequence[sequence.size-2] + sequence.last while sequence.last <= self
|
8
|
+
|
9
|
+
sequence[sequence.size-2]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class Integer
|
15
|
+
include Fibonacci
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "integer"
|
3
|
+
|
4
|
+
class TestInteger < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
context "spot regression testing: " do
|
7
|
+
context "an integer/fixnum/bignum" do
|
8
|
+
should "retain core Integer behavior" do
|
9
|
+
test_fixnum = 4
|
10
|
+
assert_equal Fixnum, test_fixnum.class
|
11
|
+
assert test_fixnum.is_a?(Fixnum)
|
12
|
+
assert test_fixnum.is_a?(Integer)
|
13
|
+
assert test_fixnum.is_a?(Numeric)
|
14
|
+
assert test_fixnum.is_a?(Precision)
|
15
|
+
assert test_fixnum.is_a?(Object)
|
16
|
+
assert test_fixnum.integer?
|
17
|
+
assert test_fixnum == 4
|
18
|
+
assert test_fixnum.eql?(4)
|
19
|
+
four = 4
|
20
|
+
assert test_fixnum == four
|
21
|
+
assert test_fixnum.eql?(four)
|
22
|
+
assert test_fixnum == 4.0
|
23
|
+
assert !test_fixnum.eql?(4.0)
|
24
|
+
assert !test_fixnum.zero?
|
25
|
+
assert test_fixnum < test_fixnum + 1
|
26
|
+
assert test_fixnum > test_fixnum - 1
|
27
|
+
assert_equal 4, test_fixnum.round
|
28
|
+
assert_equal 4, test_fixnum.ceil
|
29
|
+
assert_equal 1, test_fixnum.modulo(3)
|
30
|
+
assert_equal "4", test_fixnum.to_s
|
31
|
+
assert_equal 2, test_fixnum / 2
|
32
|
+
assert_equal -4, (test_fixnum * -1)
|
33
|
+
assert_equal test_fixnum, (test_fixnum * -1).abs
|
34
|
+
assert test_fixnum.even?
|
35
|
+
assert !test_fixnum.odd?
|
36
|
+
assert (test_fixnum * -1).even?
|
37
|
+
assert !(test_fixnum * -1).odd?
|
38
|
+
assert_not_nil test_fixnum.hash
|
39
|
+
|
40
|
+
test_bignum = 999999999999999999999999999999
|
41
|
+
assert_equal Bignum, test_bignum.class
|
42
|
+
assert test_bignum.is_a?(Bignum)
|
43
|
+
assert test_bignum.is_a?(Integer)
|
44
|
+
assert test_bignum < test_bignum + 1
|
45
|
+
assert test_bignum > test_bignum - 1
|
46
|
+
assert_not_nil test_bignum.hash
|
47
|
+
|
48
|
+
assert Time.now.to_i.is_a?(Integer)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "a non-integer" do
|
53
|
+
should "not have access to core Integer methods" do
|
54
|
+
assert !0.5.integer?
|
55
|
+
assert_raise(NoMethodError) { 0.5.even? }
|
56
|
+
assert_raise(NoMethodError) { 0.5.times { |i| puts "does not matter" } }
|
57
|
+
|
58
|
+
assert !Time.now.is_a?(Integer)
|
59
|
+
assert_raise(NoMethodError) { Time.now.even? }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "calling closest_fibonacci_smaller_or_equal_to on a non-integer" do
|
65
|
+
should "throw exception" do
|
66
|
+
assert_raise(NoMethodError) { 0.5.closest_fibonacci_smaller_or_equal_to }
|
67
|
+
assert_raise(NoMethodError) { 4.5.closest_fibonacci_smaller_or_equal_to }
|
68
|
+
assert_raise(NoMethodError) { -0.5.closest_fibonacci_smaller_or_equal_to }
|
69
|
+
assert_raise(NoMethodError) { "abc".closest_fibonacci_smaller_or_equal_to }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "calling closest_fibonacci_smaller_or_equal_to on a negative integer" do
|
74
|
+
should "throw exception" do
|
75
|
+
assert_raise(RuntimeError) { -1.closest_fibonacci_smaller_or_equal_to }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "calling closest_fibonacci_smaller_or_equal_to on a positive integer or zero" do
|
80
|
+
should "return the correct value" do
|
81
|
+
assert_equal 0, -0.closest_fibonacci_smaller_or_equal_to
|
82
|
+
assert_equal 0, 0.closest_fibonacci_smaller_or_equal_to
|
83
|
+
assert_equal 1, 1.closest_fibonacci_smaller_or_equal_to
|
84
|
+
assert_equal 2, 2.closest_fibonacci_smaller_or_equal_to
|
85
|
+
assert_equal 3, 3.closest_fibonacci_smaller_or_equal_to
|
86
|
+
assert_equal 3, 3.closest_fibonacci_smaller_or_equal_to
|
87
|
+
assert_equal 5, 5.closest_fibonacci_smaller_or_equal_to
|
88
|
+
assert_equal 5, 6.closest_fibonacci_smaller_or_equal_to
|
89
|
+
assert_equal 5, 7.closest_fibonacci_smaller_or_equal_to
|
90
|
+
assert_equal 8, 8.closest_fibonacci_smaller_or_equal_to
|
91
|
+
assert_equal 8, 9.closest_fibonacci_smaller_or_equal_to
|
92
|
+
assert_equal 8, 10.closest_fibonacci_smaller_or_equal_to
|
93
|
+
assert_equal 8, 11.closest_fibonacci_smaller_or_equal_to
|
94
|
+
assert_equal 8, 12.closest_fibonacci_smaller_or_equal_to
|
95
|
+
assert_equal 13, 13.closest_fibonacci_smaller_or_equal_to
|
96
|
+
assert_equal 13, 14.closest_fibonacci_smaller_or_equal_to
|
97
|
+
assert_equal 13, 15.closest_fibonacci_smaller_or_equal_to
|
98
|
+
assert_equal 13, 15.closest_fibonacci_smaller_or_equal_to
|
99
|
+
assert_equal 13, 20.closest_fibonacci_smaller_or_equal_to
|
100
|
+
assert_equal 21, 21.closest_fibonacci_smaller_or_equal_to
|
101
|
+
|
102
|
+
test_fixnum = 99999999
|
103
|
+
assert test_fixnum.is_a?(Fibonacci)
|
104
|
+
assert test_fixnum.is_a?(Fixnum)
|
105
|
+
assert_equal 63245986, test_fixnum.closest_fibonacci_smaller_or_equal_to
|
106
|
+
|
107
|
+
test_bignum = 999999999999999999999999999999
|
108
|
+
assert test_bignum.is_a?(Fibonacci)
|
109
|
+
assert test_bignum.is_a?(Bignum)
|
110
|
+
assert_equal 898923707008479989274290850145, test_bignum.closest_fibonacci_smaller_or_equal_to
|
111
|
+
|
112
|
+
assert_not_nil Time.now.to_i.closest_fibonacci_smaller_or_equal_to
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: integer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mary Wong
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-09 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 12
|
33
|
+
version: 2.3.12
|
34
|
+
name: rails
|
35
|
+
version_requirements: *id001
|
36
|
+
prerelease: false
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
name: bundler
|
51
|
+
version_requirements: *id002
|
52
|
+
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 7
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 6
|
64
|
+
- 4
|
65
|
+
version: 1.6.4
|
66
|
+
name: jeweler
|
67
|
+
version_requirements: *id003
|
68
|
+
prerelease: false
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
name: rcov
|
81
|
+
version_requirements: *id004
|
82
|
+
prerelease: false
|
83
|
+
description: This gem adds to the Integer type an extra instance method 'closest_fibonacci_smaller_or_equal_to' which returns the largest fibonancci number that is less than or equal to the integer.
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.rdoc
|
92
|
+
files:
|
93
|
+
- .document
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- config/boot.rb
|
100
|
+
- config/database.yml
|
101
|
+
- config/environment.rb
|
102
|
+
- config/environments/test.rb
|
103
|
+
- config/routes.rb
|
104
|
+
- integer.gemspec
|
105
|
+
- lib/integer.rb
|
106
|
+
- test/test_helper.rb
|
107
|
+
- test/test_integer.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://github.com/mspwong/integer
|
110
|
+
licenses:
|
111
|
+
- mspwong
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.6.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: extends Integer by adding fibonancci support
|
142
|
+
test_files: []
|
143
|
+
|