fibonaccia 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ # -*- coding: 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
+ require('rubygems')
19
+ require('fileutils')
20
+
21
+ Proc.new {
22
+ libdir = File.join(File.dirname(__FILE__), 'lib')
23
+ xlibdir = File.expand_path(libdir)
24
+ $:.unshift(xlibdir) unless ($:.include?(libdir) || $:.include?(xlibdir))
25
+ }.call
26
+
27
+ require('fibonaccia')
28
+
29
+ require('rake')
30
+
31
+ topdir = File.dirname(__FILE__)
32
+
33
+ include Rake::DSL
34
+
35
+ require('bundler/gem_tasks')
36
+
37
+ require('rake/testtask')
38
+ Rake::TestTask.new do |test|
39
+ test.libs << 'lib' << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+
44
+ require('cucumber/rake/task')
45
+ Cucumber::Rake::Task.new(:features)
46
+
47
+ task(:default => :test)
48
+
49
+ require('yard')
50
+ #require('yard-method-overrides')
51
+ YARD::Rake::YardocTask.new
52
+
53
+ Dir['tasks/**/*.rake'].each { |t| load t }
@@ -0,0 +1,23 @@
1
+ @constants
2
+ Feature: Test the various constants we provide
3
+
4
+ Scenario Outline: Test that the PHI values are of the correct class
5
+ When I invoke method '<testmethod>'
6
+ Then the return value should be a kind of <expectedclass>
7
+
8
+ Examples:
9
+ | testmethod | expectedclass |
10
+ | PHI | Float |
11
+ | PHI(false) | Float |
12
+ | PHI(true) | BigDecimal |
13
+
14
+ Scenario Outline: Test that the PHI values are as expected
15
+ When I invoke method '<testmethod>'
16
+ Then the return value should be exactly <expected>
17
+
18
+ Examples:
19
+ | testmethod | expected |
20
+ | PHI | Fibonaccia::PHI_Float |
21
+ | PHI(false) | Fibonaccia::PHI_Float |
22
+ | PHI(true) | Fibonaccia::PHI_BigDecimal |
23
+
@@ -0,0 +1,22 @@
1
+ @enumeration
2
+ Feature: Test the useability of the mixed-in Enumerable methods
3
+
4
+ Background:
5
+ Given the internal series has been reset
6
+
7
+ Scenario: Test the #count and #terms methods
8
+ Given I invoke method 'slice(30)'
9
+ Then the return value should be exactly 832040
10
+ And the value of attribute 'terms' should be exactly 31
11
+ And the value of attribute 'count' should be exactly 31
12
+
13
+ Scenario: Test the #first and #last methods
14
+ Given I invoke method 'slice(30)'
15
+ And the value of attribute 'first' should be exactly 0
16
+ And the value of attribute 'last' should be exactly 832040
17
+
18
+ Scenario: Test slicing out of bounds
19
+ When I invoke method 'slice(-20)'
20
+ Then the return value should be exactly nil
21
+ And the value of attribute 'terms' should be exactly 3
22
+
@@ -0,0 +1,44 @@
1
+ @exceptions
2
+ Feature: Test that all the things that *should* raise exceptions -- do.
3
+
4
+ Scenario: Test that including the module gives a warning
5
+ When I include the Fibonaccia module
6
+ Then stderr should match:
7
+ """
8
+ is not intended for use as a mix-in
9
+ """
10
+
11
+ Scenario Outline: Test that #shrink, #grow, and #limit raise an exception on bad arguments
12
+ When I invoke method '<testmethod>("foo")'
13
+ Then it should raise an exception of type StandardError
14
+ And it should raise an exception of type Fibonaccia::Exception
15
+ And it should raise an exception of type Fibonaccia::NotPositiveInteger
16
+ And it should raise an exception with exc.to_s containing 'non-negative integer'
17
+ And it should raise an exception with exc.to_str containing 'non-negative integer'
18
+
19
+ Examples:
20
+ | testmethod |
21
+ | shrink |
22
+ | grow |
23
+ | terms= |
24
+
25
+ Scenario: Test that non-integer slice parameters raise exceptions
26
+ When I invoke method slice("foo")
27
+ Then it should raise an exception of type ArgumentError
28
+ When I invoke method slice("foo", 1)
29
+ Then it should raise an exception of type ArgumentError
30
+ When I invoke method slice(1, "foo")
31
+ Then it should raise an exception of type ArgumentError
32
+ When I invoke method slice("foo", "bar")
33
+ Then it should raise an exception of type ArgumentError
34
+
35
+ Scenario: Test that non-integer slice ([]) parameters raise exceptions
36
+ When I invoke method ["foo"]
37
+ Then it should raise an exception of type ArgumentError
38
+ When I invoke method ["foo", 1]
39
+ Then it should raise an exception of type ArgumentError
40
+ When I invoke method [1, "foo"]
41
+ Then it should raise an exception of type ArgumentError
42
+ When I invoke method ["foo", "bar"]
43
+ Then it should raise an exception of type ArgumentError
44
+
@@ -0,0 +1,128 @@
1
+ @is_fibonnaci
2
+ Feature: Test the #is_fibonacci? method
3
+
4
+ Background:
5
+ Given the internal series has been reset
6
+
7
+ Scenario: Test the #is_fibonacci? method non-integers
8
+ When I invoke method 'is_fibonacci?("foo")'
9
+ Then the return value should be exactly false
10
+ When I invoke method 'is_fibonacci?(:symbol)'
11
+ Then the return value should be exactly false
12
+ When I invoke method 'is_fibonacci?([])'
13
+ Then the return value should be exactly false
14
+ When I invoke method 'is_fibonacci?({})'
15
+ Then the return value should be exactly false
16
+ When I invoke method 'is_fibonacci?(Math::PI)'
17
+ Then the return value should be exactly false
18
+
19
+ Scenario Outline: Test the #is_fibonacci? method with first 100 F-numbers
20
+ When I invoke method 'is_fibonacci?(<testval>)'
21
+ Then the return value should be exactly true
22
+ When I invoke method 'is_fibonacci?(<testval> - (<testval> < 5 ? 6 : 1))'
23
+ Then the return value should be exactly false
24
+
25
+ Examples:
26
+ | testval |
27
+ | 0 |
28
+ | 1 |
29
+ | 1 |
30
+ | 2 |
31
+ | 3 |
32
+ | 5 |
33
+ | 8 |
34
+ | 13 |
35
+ | 21 |
36
+ | 34 |
37
+ | 55 |
38
+ | 89 |
39
+ | 144 |
40
+ | 233 |
41
+ | 377 |
42
+ | 610 |
43
+ | 987 |
44
+ | 1597 |
45
+ | 2584 |
46
+ | 4181 |
47
+ | 6765 |
48
+ | 10946 |
49
+ | 17711 |
50
+ | 28657 |
51
+ | 46368 |
52
+ | 75025 |
53
+ | 121393 |
54
+ | 196418 |
55
+ | 317811 |
56
+ | 514229 |
57
+ | 832040 |
58
+ | 1346269 |
59
+ | 2178309 |
60
+ | 3524578 |
61
+ | 5702887 |
62
+ | 9227465 |
63
+ | 14930352 |
64
+ | 24157817 |
65
+ | 39088169 |
66
+ | 63245986 |
67
+ | 102334155 |
68
+ | 165580141 |
69
+ | 267914296 |
70
+ | 433494437 |
71
+ | 701408733 |
72
+ | 1134903170 |
73
+ | 1836311903 |
74
+ | 2971215073 |
75
+ | 4807526976 |
76
+ | 7778742049 |
77
+ | 12586269025 |
78
+ | 20365011074 |
79
+ | 32951280099 |
80
+ | 53316291173 |
81
+ | 86267571272 |
82
+ | 139583862445 |
83
+ | 225851433717 |
84
+ | 365435296162 |
85
+ | 591286729879 |
86
+ | 956722026041 |
87
+ | 1548008755920 |
88
+ | 2504730781961 |
89
+ | 4052739537881 |
90
+ | 6557470319842 |
91
+ | 10610209857723 |
92
+ | 17167680177565 |
93
+ | 27777890035288 |
94
+ | 44945570212853 |
95
+ | 72723460248141 |
96
+ | 117669030460994 |
97
+ | 190392490709135 |
98
+ | 308061521170129 |
99
+ | 498454011879264 |
100
+ | 806515533049393 |
101
+ | 1304969544928657 |
102
+ | 2111485077978050 |
103
+ | 3416454622906707 |
104
+ | 5527939700884757 |
105
+ | 8944394323791464 |
106
+ | 14472334024676221 |
107
+ | 23416728348467685 |
108
+ | 37889062373143906 |
109
+ | 61305790721611591 |
110
+ | 99194853094755497 |
111
+ | 160500643816367088 |
112
+ | 259695496911122585 |
113
+ | 420196140727489673 |
114
+ | 679891637638612258 |
115
+ | 1100087778366101931 |
116
+ | 1779979416004714189 |
117
+ | 2880067194370816120 |
118
+ | 4660046610375530309 |
119
+ | 7540113804746346429 |
120
+ | 12200160415121876738 |
121
+ | 19740274219868223167 |
122
+ | 31940434634990099905 |
123
+ | 51680708854858323072 |
124
+ | 83621143489848422977 |
125
+ | 135301852344706746049 |
126
+ | 218922995834555169026 |
127
+ | 354224848179261915075 |
128
+
@@ -0,0 +1,70 @@
1
+ @sizing
2
+ Feature: Test our methods for adjusting the length of the series.
3
+
4
+ Scenario: Test the default initial series
5
+ When I invoke method 'series'
6
+ Then the return value should be exactly [0,1,1]
7
+ And the value of attribute 'terms' should be exactly 3
8
+
9
+ Scenario: Test that resetting leaves the series still at the default
10
+ When I invoke method 'reset'
11
+ And I query method 'series'
12
+ Then the return value should be exactly [0,1,1]
13
+ And the value of attribute 'terms' should be exactly 3
14
+
15
+ Scenario Outline: Grow the series repeatedly
16
+ When I query attribute 'terms'
17
+ Then the return value should be exactly <terms0>
18
+ And I invoke method 'grow(<nterms>)'
19
+ Then the return value should be exactly <terms1>
20
+ And the value of attribute 'terms' should be exactly <terms1>
21
+
22
+ Examples:
23
+ | terms0 | nterms | terms1 |
24
+ | 3 | 1 | 4 |
25
+ | 4 | 6 | 10 |
26
+ | 10 | 0 | 10 |
27
+ | 10 | 1000 | 1010 |
28
+ | 1010 | 10280 | 11290 |
29
+
30
+ Scenario: Test the series in the next scenario after the growth scenario
31
+ When I query attribute 'terms'
32
+ Then the return value should be exactly 11290
33
+
34
+ Scenario: Test that resetting restores to just the seed
35
+ When I invoke method 'reset'
36
+ And I query method 'series'
37
+ Then the return value should be exactly [0,1,1]
38
+ And the value of attribute 'terms' should be exactly 3
39
+
40
+ Scenario Outline: Test setting explicit term counts
41
+ When I set attribute 'terms' to <setting>
42
+ Then the return value should be exactly <expected>
43
+ And the value of attribute 'terms' should be exactly <expected>
44
+
45
+ Examples:
46
+ | setting | expected |
47
+ | 1024 | 1024 |
48
+ | 0 | 3 |
49
+ | 0 | 3 |
50
+ | 0 | 3 |
51
+ | 1 | 3 |
52
+ | 2 | 3 |
53
+ | 11290 | 11290 |
54
+
55
+ Scenario Outline: Test shrinking
56
+ When I query attribute 'terms'
57
+ Then the return value should be exactly <terms0>
58
+ And I invoke method 'shrink(<nterms>)'
59
+ Then the return value should be exactly <terms1>
60
+ And the value of attribute 'terms' should be exactly <terms1>
61
+
62
+ Examples:
63
+ | terms0 | nterms | terms1 |
64
+ | 11290 | 10280 | 1010 |
65
+ | 1010 | 0 | 1010 |
66
+ | 1010 | 1000 | 10 |
67
+ | 10 | 4 | 6 |
68
+ | 6 | 4 | 3 |
69
+ | 3 | 100 | 3 |
70
+
@@ -0,0 +1,18 @@
1
+ @slicing
2
+ @slicing_sequences
3
+ @slicing_growth
4
+
5
+ Feature: Test that slicing past the current end of the series will extend it
6
+
7
+ Scenario Outline: Test growth-by-slicing
8
+ Given the internal series has been reset
9
+ When I invoke method '[<index>,<nterms>]'
10
+ Then the return value should be exactly <slice>
11
+ And the value of attribute 'terms' should be exactly <terms>
12
+
13
+ Examples:
14
+ | index | nterms | slice | terms |
15
+ | 0 | 0 | 0 | 3 |
16
+ | 10 | 2 | [55,89] | 12 |
17
+ | 100 | 2 | [354224848179261915075,573147844013817084101] | 102 |
18
+
@@ -0,0 +1,39 @@
1
+ @slicing
2
+ @slicing_sequences
3
+ Feature: Test slicing multi-element pieces out of the series
4
+
5
+ Scenario: Resetting the series before the aggregatative scenario
6
+ When the internal series has been reset
7
+ Then the value of attribute 'terms' should be exactly 3
8
+
9
+ Scenario Outline: Test slicing multi-element values out of the minimal series
10
+ When I invoke method '[<index>,<nterms>]'
11
+ Then the return value should be exactly <slice>
12
+ And the value of attribute 'terms' should be exactly <terms>
13
+ And the value of attribute 'series' should be exactly <series>
14
+
15
+ Examples:
16
+ | index | nterms | slice | terms | series |
17
+ | 0 | 0 | 0 | 3 | [0,1,1] |
18
+ | 0 | 1 | 0 | 3 | [0,1,1] |
19
+ | 0 | 2 | [0,1] | 3 | [0,1,1] |
20
+ | 0 | 3 | [0,1,1] | 3 | [0,1,1] |
21
+ | 0 | -1 | 0 | 3 | [0,1,1] |
22
+ | -1 | 1 | 1 | 3 | [0,1,1] |
23
+ | 1 | 0 | 1 | 3 | [0,1,1] |
24
+ | 1 | 1 | 1 | 3 | [0,1,1] |
25
+ | 1 | 2 | [1,1] | 3 | [0,1,1] |
26
+ | 1 | 3 | [1,1,2] | 4 | [0,1,1,2] |
27
+ | 1 | -1 | 1 | 4 | [0,1,1,2] |
28
+ | -1 | 1 | 2 | 4 | [0,1,1,2] |
29
+ | 2 | 0 | 1 | 4 | [0,1,1,2] |
30
+ | 2 | 1 | 1 | 4 | [0,1,1,2] |
31
+ | 2 | 2 | [1,2] | 4 | [0,1,1,2] |
32
+ | 2 | 3 | [1,2,3] | 5 | [0,1,1,2,3] |
33
+ | -1 | 1 | 3 | 5 | [0,1,1,2,3] |
34
+ | 2 | 0 | 1 | 5 | [0,1,1,2,3] |
35
+ | 2 | 1 | 1 | 5 | [0,1,1,2,3] |
36
+ | 2 | 2 | [1,2] | 5 | [0,1,1,2,3] |
37
+ | 2 | 3 | [1,2,3] | 5 | [0,1,1,2,3] |
38
+ | -1 | 1 | 3 | 5 | [0,1,1,2,3] |
39
+
@@ -0,0 +1,35 @@
1
+ @slicing
2
+
3
+ Feature: Test accessing the internal series through basic slices.
4
+
5
+ Scenario: Test the default initial series
6
+ When I invoke method 'reset'
7
+ Then the value of attribute 'series' should be exactly [0,1,1]
8
+
9
+ Scenario Outline: Test slicing single values out of the minimal series using #slice
10
+ Given the internal series has been reset
11
+ When I invoke method 'slice(<index>)'
12
+ Then the return value should be exactly <slice>
13
+ And the value of attribute 'terms' should be exactly <terms>
14
+
15
+ Examples:
16
+ | index | slice | terms |
17
+ | 0 | 0 | 3 |
18
+ | 1 | 1 | 3 |
19
+ | 2 | 1 | 3 |
20
+ | -1 | 1 | 3 |
21
+
22
+ Scenario Outline: Test slicing single values out of the minimal series using #[]
23
+ Given the internal series has been reset
24
+ When I invoke method '[<index>]'
25
+ Then the return value should be exactly <slice>
26
+ And the value of attribute 'terms' should be exactly <terms>
27
+
28
+ Examples:
29
+ | index | slice | terms |
30
+ | 0 | 0 | 3 |
31
+ | 1 | 1 | 3 |
32
+ | 2 | 1 | 3 |
33
+ | -1 | 1 | 3 |
34
+
35
+
@@ -0,0 +1,23 @@
1
+ #
2
+ #
3
+ #
4
+ Then(%r!^it should raise an exception of type (\S+)$!) do |xval|
5
+ expect(@exception_raised.kind_of?(eval(xval))).to eq(true)
6
+ end
7
+ Then(%r!^it should raise an exception of type:$!) do |xval|
8
+ expect(@exception_raised.kind_of?(eval(xval))).to eq(true)
9
+ end
10
+
11
+ Then(%r!^it should raise an exception with exc.to_s containing ["'](.*)["']$!) do |xval|
12
+ expect(@exception_raised.to_s).to match(Regexp.new(xval))
13
+ end
14
+ Then(%r!^it should raise an exception with exc.to_s containing:$!) do |xval|
15
+ expect(@exception_raised.to_s).to match(Regexp.new(xval))
16
+ end
17
+
18
+ Then(%r!^it should raise an exception with exc.to_str containing ["'](.*)["']$!) do |xval|
19
+ expect(@exception_raised).to match(Regexp.new(xval))
20
+ end
21
+ Then(%r!^it should raise an exception with exc.to_str containing:$!) do |xval|
22
+ expect(@exception_raised).to match(Regexp.new(xval))
23
+ end