to_fib 1.0.1 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b72178c084973532b893b264655acba5ea416a8
4
- data.tar.gz: cb91408f8db56ab4457a08ca4f9cb51831253a92
3
+ metadata.gz: 083c42b40b5a84a300f1805f27192f4cec1a1b8c
4
+ data.tar.gz: 2905e77e7b39292fa49bbebcb4bd7b92c3111ec5
5
5
  SHA512:
6
- metadata.gz: 199b94c55c93e02afa359b8d785471c2d02a0e60bd67efad5acd5c630964dc4c6b1e20e3e6a7a6c10c2aae8c5222d707e4213606d965cab015f1963138cfb00e
7
- data.tar.gz: 14bb30cca4f9e9e7ae72d75c48057db8437050994d00a4604bfc0f56438e0b652f31980f7bdc208282aaaf8d18cc7dd87dbe9675d4d2a66bb15e129ee2f447f6
6
+ metadata.gz: 798a8277094602efb867fb974c4eaa2f5c46ed0eafbb38885924a516a9654774c7e6b20f7f79cbadeacba9ebac01ec2021332da9f92c780e57836f3126e8f39f
7
+ data.tar.gz: 3c279920702b38aa0b57afb56ae50ad2fe2c963107ab982f3601255ee8be3b09837e81eac228b6fa30d4e85d989f063e8730d0ba66d3988ea7934a4776fd7ae4
data/README.md CHANGED
@@ -27,6 +27,7 @@ And use it in irb:
27
27
  13.to_fib # 13
28
28
  20.to_fib # 21
29
29
  900000000000000000000000000000000000000000000000000000000000000000000.to_fib # 1082459262056433063877940200966638133809015267665311237542082678938909
30
+ -44.to_fib # -55
30
31
  8.is_fib? # true
31
32
  9.is_fib? # false
32
33
  ```
data/lib/to_fib/to_fib.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  module ToFib
2
- module ObjectExtension
2
+ module ObjectExtension
3
3
  def to_fib
4
- fibonacci(self).reverse_each.take(2).min {|a, b| (self-a).abs <=> (self-b).abs}
4
+ f, neg = fibonacci(self.abs), []
5
+ if self < 0
6
+ f.each_with_index {|i, index| neg << -i if index.even?}
7
+ f = neg
8
+ end
9
+ f.reverse_each.take(2).min {|a, b| (self-a).abs <=> (self-b).abs}
5
10
  end
6
11
 
7
12
  def is_fib?
@@ -2,7 +2,7 @@ module ToFib
2
2
  class Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
  PRE = nil
7
7
 
8
8
  class << self
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class TestIsFib < BaseTest
4
+
5
+ def test_is_fib
6
+ assert_equal true, 55.is_fib?
7
+ end
8
+
9
+ def test_not_is_fib
10
+ assert_equal false, 58.is_fib?
11
+ end
12
+
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class TestNegToFib < BaseTest
4
+
5
+ def test_neg_4
6
+ assert_equal -3, -4.to_fib
7
+ end
8
+
9
+ def test_neg_44
10
+ assert_equal -55, -44.to_fib
11
+ end
12
+
13
+ def test_neg_4444
14
+ assert_equal -2584, -4444.to_fib
15
+ end
16
+
17
+ def test_neg_10_000_000_000
18
+ assert_equal -12_586_269_025, -10_000_000_000.to_fib
19
+ end
20
+
21
+ end
data/test/test_to_fib.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class TestToFib < BaseTest
4
-
5
- def test_version
6
- refute_equal nil, ToFib::Version
4
+
5
+ def test_zero
6
+ assert_equal 0, 0.to_fib
7
7
  end
8
8
 
9
9
  def test_13
@@ -21,13 +21,5 @@ class TestToFib < BaseTest
21
21
  def test_900000000000000000000000000000000000000000000000000000000000000000000
22
22
  assert_equal 1082459262056433063877940200966638133809015267665311237542082678938909, 900000000000000000000000000000000000000000000000000000000000000000000.to_fib
23
23
  end
24
-
25
- def test_is_fib
26
- assert_equal true, 55.is_fib?
27
- end
28
-
29
- def test_not_is_fib
30
- assert_equal false, 58.is_fib?
31
- end
32
-
24
+
33
25
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class TestVersion < BaseTest
4
+
5
+ def test_to_fib_version
6
+ refute_equal nil, ToFib::Version
7
+ end
8
+
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_fib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave De Carlo
@@ -55,7 +55,10 @@ files:
55
55
  - lib/to_fib/to_fib.rb
56
56
  - lib/to_fib/version.rb
57
57
  - test/test_helper.rb
58
+ - test/test_is_fib.rb
59
+ - test/test_neg_fib.rb
58
60
  - test/test_to_fib.rb
61
+ - test/test_version.rb
59
62
  - to_fib.gemspec
60
63
  homepage: https://github.com/quotha/to_fib
61
64
  licenses:
@@ -83,4 +86,7 @@ specification_version: 4
83
86
  summary: to the nearest fibonacci number
84
87
  test_files:
85
88
  - test/test_helper.rb
89
+ - test/test_is_fib.rb
90
+ - test/test_neg_fib.rb
86
91
  - test/test_to_fib.rb
92
+ - test/test_version.rb