fibonaccia 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.tito/custom/gemtagger.py +112 -0
- data/.tito/custom/gemtagger.pyc +0 -0
- data/.tito/packages/.readme +3 -0
- data/.tito/packages/rubygem-fibonaccia +1 -0
- data/.tito/tito.props +6 -0
- data/.travis.yml +30 -0
- data/CONTRIBUTORS.md +7 -0
- data/Changelog +3 -0
- data/Details.md +304 -0
- data/Gemfile +44 -0
- data/LICENCE.md +203 -0
- data/LICENCE.txt +201 -0
- data/README.md +158 -0
- data/Rakefile +53 -0
- data/features/constants.feature +23 -0
- data/features/enumeration.feature +22 -0
- data/features/exceptions.feature +44 -0
- data/features/is_fibonacci.feature +128 -0
- data/features/sizing.feature +70 -0
- data/features/slicing-growth.feature +18 -0
- data/features/slicing-sequence.feature +39 -0
- data/features/slicing.feature +35 -0
- data/features/step_definitions/exceptions.rb +23 -0
- data/features/step_definitions/fibonaccia-specific.rb +36 -0
- data/features/step_definitions/streams.rb +53 -0
- data/features/step_definitions/utility.rb +58 -0
- data/features/support/env.rb +165 -0
- data/features/support/hooks.rb +12 -0
- data/fibonaccia.gemspec +121 -0
- data/lib/fibonaccia.rb +573 -0
- data/lib/fibonaccia/classmethods.rb +35 -0
- data/lib/fibonaccia/exceptions.rb +82 -0
- data/lib/fibonaccia/module-doc.rb +39 -0
- data/lib/fibonaccia/version.rb +86 -0
- data/rubygem-fibonaccia.spec +118 -0
- data/tasks/markdown-to-html.rake +9 -0
- metadata +200 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
Given(%r!the internal series (?:is|has been) reset$!) do
|
2
|
+
@exemplar.reset
|
3
|
+
end
|
4
|
+
|
5
|
+
When(%r!^I (?:query|invoke) (?:attribute|method) ["']?([\[\]_=A-Za-z0-9?]+)["']?\((.*?)\)["']?$!) do |attr,args|
|
6
|
+
args = eval("[#{args}]")
|
7
|
+
@return_value = wrap_exception {
|
8
|
+
@exemplar.send(attr.to_sym, *args)
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
When(%r!^I (?:query|invoke) (?:attribute|method) ["']?\[(.*)\]["']?$!) do |args|
|
13
|
+
args = eval("[#{args}]")
|
14
|
+
@return_value = wrap_exception {
|
15
|
+
@exemplar.send(:[], *args)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
When(%r!^I (?:query|invoke) (?:attribute|method):$!) do |xval|
|
20
|
+
@return_value = wrap_exception {
|
21
|
+
eval(xval)
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
When(%r!^I (?:query|invoke) (?:attribute|method) ["']?([_A-Za-z0-9?]+)["']?$!) do |attr|
|
26
|
+
@return_value = wrap_exception {
|
27
|
+
@exemplar.send(attr.to_sym)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
When(%r!^I set (?:attribute|the)?\s*["']?([_A-Za-z0-9]+)["']? to (.+?)$!) do |attr,val|
|
32
|
+
@return_value = wrap_exception {
|
33
|
+
@exemplar.send((attr. + '=').to_sym, eval(val))
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Cucumber steps dealing with checking the content of stdout/stderr.
|
3
|
+
#
|
4
|
+
streams = %w( stdout stderr )
|
5
|
+
streams.each do |sname|
|
6
|
+
Then(%r!^#{sname} should contain exactly (.+)$!) do |xval|
|
7
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
8
|
+
expect(sval).to eq(eval(xval))
|
9
|
+
end
|
10
|
+
Then(%r!^#{sname} should NOT contain exactly (.+)$!) do |xval|
|
11
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
12
|
+
expect(sval).not_to eq(eval(xval))
|
13
|
+
end
|
14
|
+
Then(%r!^#{sname} should contain exactly:$!) do |xval|
|
15
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
16
|
+
expect(sval).to eq(xval)
|
17
|
+
end
|
18
|
+
Then(%r!^#{sname} should NOT contain exactly:$!) do |xval|
|
19
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
20
|
+
expect(sval).not_to eq(xval)
|
21
|
+
end
|
22
|
+
Then(%r!^#{sname} should match (.*)$!) do |xval|
|
23
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
24
|
+
expect(sval).to match(Regexp.new(xval))
|
25
|
+
end
|
26
|
+
Then(%r!^#{sname} should match:$!) do |xval|
|
27
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
28
|
+
expect(sval).to match(Regexp.new(xval))
|
29
|
+
end
|
30
|
+
Then(%r!^#{sname} should NOT match (.*)$!) do |xval|
|
31
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
32
|
+
expect(sval).not_to match(Regexp.new(xval))
|
33
|
+
end
|
34
|
+
Then(%r!^#{sname} should NOT match:$!) do |xval|
|
35
|
+
sval = instance_variable_get("@#{sname}_text".to_sym)
|
36
|
+
expect(sval).not_to match(Regexp.new(xval))
|
37
|
+
end
|
38
|
+
end # streams.each do
|
39
|
+
|
40
|
+
#
|
41
|
+
# This should probably go into utility.rb -- except it explicitly
|
42
|
+
# mentions stream stuff.
|
43
|
+
#
|
44
|
+
When(%r!^I include the (\S+) module$!) do |xval|
|
45
|
+
traffic = capture_streams(:$stdout, :$stderr) {
|
46
|
+
invocation = "class #{xval}_Includer ; include #{xval} ; end"
|
47
|
+
@return_value = eval(invocation)
|
48
|
+
}
|
49
|
+
@stdout_text = traffic[:$stdout]
|
50
|
+
@stderr_text = traffic[:$stderr]
|
51
|
+
@return_value
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#
|
2
|
+
# Cucumber steps of semi-general utility.
|
3
|
+
#
|
4
|
+
|
5
|
+
#
|
6
|
+
# Run a command and record any exception.
|
7
|
+
#
|
8
|
+
Given(%r!^I run system\("([^"]+)"\)$!) do |xval|
|
9
|
+
wrap_exception do
|
10
|
+
system(xval)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Then(%r!^the return value should be a kind of (\S+)$!) do |xval|
|
15
|
+
expect(@return_value.kind_of?(eval(xval))).to eq(true)
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(%r!^the return value should be a kind of:$!) do |xval|
|
19
|
+
expect(@return_value.kind_of?(eval(xval))).to eq(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
Then(%r!^the return value should NOT be a kind of (\S+)$!) do |xval|
|
23
|
+
expect(@return_value.kind_of?(eval(xval))).not_to eq(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
Then(%r!^the return value should NOT be a kind of:$!) do |xval|
|
27
|
+
expect(@return_value.kind_of?(eval(xval))).not_to eq(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
Then(%r!^the return value should be exactly (.*)$!) do |xval|
|
31
|
+
expect(@return_value).to eq(eval(xval))
|
32
|
+
end
|
33
|
+
|
34
|
+
Then(%r!^the return value should be exactly:$!) do |xval|
|
35
|
+
debugger
|
36
|
+
expect(@return_value).to eq(eval(xval))
|
37
|
+
end
|
38
|
+
|
39
|
+
Then(%r!^the return value should match ['"]?(.*)['"]?$!) do |xval|
|
40
|
+
expect(@return_value).to match(%r!#{xval}!)
|
41
|
+
end
|
42
|
+
|
43
|
+
Then(%r!^the return value should NOT match ['"]?(.*)['"]?$!) do |xval|
|
44
|
+
expect(@return_value).not_to match(%r!#{xval}!)
|
45
|
+
end
|
46
|
+
|
47
|
+
Then(%r!^the return value should include (\S+)$!) do |xval|
|
48
|
+
expect(@return_value.include?(eval(xval))).to eq(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
Then(%r!^the return value should include:$!) do |xval|
|
52
|
+
expect(@return_value.include?(eval(xval))).to eq(true)
|
53
|
+
end
|
54
|
+
|
55
|
+
Then(%r!^the value of attribute ["']([_A-Za-z][_A-Za-z0-9]*)["'] should be exactly (["']?.*?["']?)$!) do |mname,xval|
|
56
|
+
attr_value = wrap_exception { @exemplar.send(mname) }
|
57
|
+
expect(attr_value).to eq(eval(xval))
|
58
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
Proc.new {
|
2
|
+
libdir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
3
|
+
$:.replace($: | [ libdir ])
|
4
|
+
}.call
|
5
|
+
|
6
|
+
#
|
7
|
+
# Must load and start simplecov before any application code
|
8
|
+
#
|
9
|
+
require('json')
|
10
|
+
require('versionomy')
|
11
|
+
|
12
|
+
if (Versionomy.ruby_version >= Versionomy.parse('1.9'))
|
13
|
+
require('simplecov')
|
14
|
+
SimpleCov.start do
|
15
|
+
add_filter('/features/')
|
16
|
+
add_filter('/libexec')
|
17
|
+
add_filter('/lib/hll_active_record/')
|
18
|
+
add_filter('/test/')
|
19
|
+
add_filter('/tmp/')
|
20
|
+
end
|
21
|
+
SimpleCov.command_name(ARGV.join(' '))
|
22
|
+
end
|
23
|
+
|
24
|
+
require('fibonaccia')
|
25
|
+
require('aruba/cucumber')
|
26
|
+
|
27
|
+
#
|
28
|
+
# Pick the right debugging gem.
|
29
|
+
#
|
30
|
+
if (Versionomy.ruby_version < Versionomy.parse('1.9.0'))
|
31
|
+
require('ruby-debug')
|
32
|
+
elsif (Versionomy.ruby_version >= Versionomy.parse('2.0.0'))
|
33
|
+
require('byebug')
|
34
|
+
else
|
35
|
+
require('debugger')
|
36
|
+
end
|
37
|
+
|
38
|
+
# @private
|
39
|
+
#
|
40
|
+
# This module provides helper methods for the Cucumber testing suite.
|
41
|
+
#
|
42
|
+
module Fibonaccia_TestSupport
|
43
|
+
|
44
|
+
#
|
45
|
+
# Suggested by from https://github.com/codegram/spinach
|
46
|
+
#
|
47
|
+
|
48
|
+
#
|
49
|
+
# Provide helpers to wrap IO streams by temporarily redirecting them
|
50
|
+
# to a StringIO object.
|
51
|
+
#
|
52
|
+
|
53
|
+
# @private
|
54
|
+
#
|
55
|
+
# Capture IO to one or more streams during block execution.
|
56
|
+
#
|
57
|
+
# @param [Array<Symbol,String>] stms
|
58
|
+
# One or more stream identifiers to be captured. Symbols like `:$stderr`
|
59
|
+
# and strings like `"$stdout"` are acceptable.
|
60
|
+
#
|
61
|
+
# @yield
|
62
|
+
# Block for which stream traffic should be captured.
|
63
|
+
#
|
64
|
+
# @return [String,Hash<<String,Symbol>=>String>]
|
65
|
+
# If only one stream was specified, the result will be a simple string.
|
66
|
+
#
|
67
|
+
def capture_streams(*stms, &block)
|
68
|
+
if (stms.any? { |o| (! (o.kind_of?(String) || o.kind_of?(Symbol))) })
|
69
|
+
raise(ArgumentError, 'streams must be strings or symbols')
|
70
|
+
end
|
71
|
+
ovalues = stms.inject({}) { |memo,stm|
|
72
|
+
stmname = stm.to_s
|
73
|
+
stmobj = eval(stmname)
|
74
|
+
unless (stmobj.kind_of?(IO))
|
75
|
+
raise(ArgumentError, "'#{stm.inspect}' is not an IO object")
|
76
|
+
end
|
77
|
+
stat = {
|
78
|
+
:persistent => stmobj,
|
79
|
+
:temporary => StringIO.new,
|
80
|
+
}
|
81
|
+
eval("#{stmname} = stat[:temporary]")
|
82
|
+
memo[stm] = stat
|
83
|
+
memo
|
84
|
+
}
|
85
|
+
#
|
86
|
+
# Make sure we restore the streams to their original settings if an
|
87
|
+
# exception gets raised. We don't care about the exception, just
|
88
|
+
# making sure the streams are as they were when we were called.
|
89
|
+
#
|
90
|
+
rvalues = stms.map { |o| {o => ''} }.reduce(:merge)
|
91
|
+
begin
|
92
|
+
yield
|
93
|
+
ensure
|
94
|
+
rvalues = ovalues.inject({}) { |memo,(stm,stat)|
|
95
|
+
eval("#{stm.to_s} = stat[:persistent]")
|
96
|
+
memo[stm] = stat[:temporary].string
|
97
|
+
memo
|
98
|
+
}
|
99
|
+
end
|
100
|
+
rvalues = rvalues.values.first if (rvalues.count == 1)
|
101
|
+
return rvalues
|
102
|
+
end # def capture_streams
|
103
|
+
|
104
|
+
# @private
|
105
|
+
#
|
106
|
+
# Capture standard output activity as a string.
|
107
|
+
#
|
108
|
+
# @yield
|
109
|
+
# Block during the execution of which output is to be captured.
|
110
|
+
#
|
111
|
+
# @return [String]
|
112
|
+
# Returns whatever was sent to `$stdout` during the block's execution.
|
113
|
+
#
|
114
|
+
def capture_stdout(&block)
|
115
|
+
return capture_stream(:$stdout, &block)
|
116
|
+
end # def capture_stdout
|
117
|
+
|
118
|
+
# @private
|
119
|
+
#
|
120
|
+
# Capture standard error activity as a string.
|
121
|
+
#
|
122
|
+
# @yield (see #capture_stdout)
|
123
|
+
#
|
124
|
+
# @return [String]
|
125
|
+
# Returns whatever was sent to `$stderr` during the block's execution.
|
126
|
+
#
|
127
|
+
# @see #capture_stdout
|
128
|
+
# @see #capture_streams
|
129
|
+
#
|
130
|
+
def capture_stderr(&block)
|
131
|
+
return capture_stream(:$stderr, &block)
|
132
|
+
end # def capture_stderr
|
133
|
+
|
134
|
+
# @private
|
135
|
+
#
|
136
|
+
# Wrap the specified block in a rescue block so we can capture any
|
137
|
+
# exceptions.
|
138
|
+
#
|
139
|
+
# @yield
|
140
|
+
# Yields to the block, passing no arguments.
|
141
|
+
#
|
142
|
+
# @return [nil,Object]
|
143
|
+
# Returns the exit value of the block (whatever it may be), or
|
144
|
+
# `nil` if an exception was caught.
|
145
|
+
#
|
146
|
+
def wrap_exception(&block)
|
147
|
+
@exception_raised = nil
|
148
|
+
return_value = nil
|
149
|
+
begin
|
150
|
+
#
|
151
|
+
# Do this in two steps in case the block itself puts something
|
152
|
+
# in the @return_value ivar.
|
153
|
+
#
|
154
|
+
result = block.call
|
155
|
+
return_value ||= result
|
156
|
+
rescue => exc
|
157
|
+
@exception_raised = exc
|
158
|
+
return_value = nil
|
159
|
+
end
|
160
|
+
return return_value
|
161
|
+
end
|
162
|
+
|
163
|
+
end # module Fibonaccia_TestSupport
|
164
|
+
|
165
|
+
include Fibonaccia_TestSupport
|
data/fibonaccia.gemspec
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#--
|
3
|
+
# Copyright © 2015 Ken Coar
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#++
|
17
|
+
|
18
|
+
Proc.new {
|
19
|
+
libdir = File.join(File.dirname(__FILE__), 'lib')
|
20
|
+
xlibdir = File.expand_path(libdir)
|
21
|
+
$:.unshift(xlibdir) unless ($:.include?(libdir) || $:.include?(xlibdir))
|
22
|
+
}.call
|
23
|
+
require('fibonaccia/version')
|
24
|
+
|
25
|
+
Gem::Specification.new do |s|
|
26
|
+
s.required_ruby_version = ">= #{Fibonaccia::MINIMUM_RUBY_VERSION.to_s}"
|
27
|
+
if (s.respond_to?(:required_rubygems_version=))
|
28
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
29
|
+
end
|
30
|
+
s.name = 'fibonaccia'
|
31
|
+
s.version = Fibonaccia::VERSION
|
32
|
+
s.authors = [
|
33
|
+
'Ken Coar',
|
34
|
+
]
|
35
|
+
s.email = [
|
36
|
+
'kcoar@redhat.com',
|
37
|
+
]
|
38
|
+
s.summary = ("#{'%s-%s' % [ s.name, s.version, ]} - " +
|
39
|
+
'Easy access to Fibonacci series and related things.')
|
40
|
+
s.description = <<-EOD
|
41
|
+
Non-mixin module providing access to terms in the Fibonacci series.
|
42
|
+
Fetch specific terms, slice the series, check to see if an arbitrary
|
43
|
+
value is a Fibonacci number, etc.
|
44
|
+
EOD
|
45
|
+
s.homepage = 'https://github.com/RoUS/rubygem-fibonaccia'
|
46
|
+
s.license = 'Apache 2.0'
|
47
|
+
|
48
|
+
s.files = `git ls-files -z`.split("\x0")
|
49
|
+
#
|
50
|
+
# These cause problems when building RPMs, and we don't need 'em in
|
51
|
+
# the gem anyway.
|
52
|
+
#
|
53
|
+
s.files.delete('.yardopts')
|
54
|
+
s.files.delete('.gitignore')
|
55
|
+
s.executables = s.files.grep(%r!^bin/!) { |f| File.basename(f) }
|
56
|
+
s.test_files = s.files.grep(%r!^(test|spec|features)/!)
|
57
|
+
s.has_rdoc = true
|
58
|
+
s.extra_rdoc_files = [
|
59
|
+
'README.md',
|
60
|
+
'Details.md',
|
61
|
+
]
|
62
|
+
s.rdoc_options = [
|
63
|
+
'--main=README.md',
|
64
|
+
'--charset=UTF-8',
|
65
|
+
]
|
66
|
+
s.require_paths = [
|
67
|
+
'lib',
|
68
|
+
]
|
69
|
+
|
70
|
+
#
|
71
|
+
# Make a hash for our dependencies, since we're using some fancy
|
72
|
+
# code to declare them depending upon the version of the
|
73
|
+
# environment.
|
74
|
+
#
|
75
|
+
requirements_all = {
|
76
|
+
'bigdecimal' => [],
|
77
|
+
'bundler' => [
|
78
|
+
'~> 1.7',
|
79
|
+
],
|
80
|
+
'versionomy' => [
|
81
|
+
'>= 0.4.3',
|
82
|
+
],
|
83
|
+
}
|
84
|
+
requirements_dev = {
|
85
|
+
'cucumber' => [],
|
86
|
+
'rake' => [
|
87
|
+
'~> 10.0',
|
88
|
+
],
|
89
|
+
'rdiscount' => [],
|
90
|
+
'yard' => [
|
91
|
+
'>= 0.8.2',
|
92
|
+
],
|
93
|
+
}
|
94
|
+
|
95
|
+
requirements_all.each do |dep,*vargs|
|
96
|
+
args = [ dep ]
|
97
|
+
args.push(*vargs) unless (vargs.count.zero? || vargs[0].empty?)
|
98
|
+
s.add_dependency(*args)
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# The following bit of hanky-panky was adapted from uuidtools-2.1.3.
|
103
|
+
#
|
104
|
+
if (s.respond_to?(:specification_version=))
|
105
|
+
s.specification_version = 3
|
106
|
+
|
107
|
+
if (Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0'))
|
108
|
+
depmethod = :add_development_dependency
|
109
|
+
else
|
110
|
+
depmethod = :add_dependency
|
111
|
+
end
|
112
|
+
else
|
113
|
+
depmethod = :add_dependency
|
114
|
+
end
|
115
|
+
requirements_dev.each do |dep,*vargs|
|
116
|
+
args = [ dep ]
|
117
|
+
args.push(*vargs) unless (vargs.count.zero? || vargs[0].empty?)
|
118
|
+
s.send(depmethod, *args)
|
119
|
+
end
|
120
|
+
|
121
|
+
end # Gem::Specification.new
|