time_value 0.1.1 → 0.1.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: c9adc69a58238719d597b04365a769516bacaa1a
4
- data.tar.gz: 0d522a20351d5c6b85e297c686c9abbd886a60f2
3
+ metadata.gz: b8d062fe004503ddf10aa4868b97ae5de157d066
4
+ data.tar.gz: 1bb4988314cb5add83dc1961c433e69933b93bdf
5
5
  SHA512:
6
- metadata.gz: aa9ebc0a7ff6e09a3e773d9eadab8ee8b3b807db7298cbd6099da16dc7c8273b90b230382dffd30be7ea87abeb42e4486f4843fb72c05882adf10ad230131478
7
- data.tar.gz: 538d7e32757dc58e73a1676cf5b91c2c741255004d4ad3e13fe9ff51192371f99db354bcb32f300bab5fde9e5367f1d24fa400e934f9a51399e9a5c52ac95674
6
+ metadata.gz: e9af1844641632a746306d97b8739f08c51ac39fb32934c98c6037a546af7aab600da7cd51ee0806c6ea6dd2822f1a870c1009e36d1521fe9548852f3138e250
7
+ data.tar.gz: df779a51ed6d53b9192c33a0fd9f8fda36e5cdd7ddf65d6715d47a99497c95d01e9820e8d6bc8b74b669683154f79ea5652566942bba3d320593ff0a6f4954a4
data/lib/solver.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Solver
2
+ PRECISION = 3
3
+ INTERVAL = 10 ** (-1 * PRECISION)
4
+ MAX_ITERATIONS = 20
2
5
  attr_reader :time_value, :goal
3
6
  attr_accessor :guess, :lower_bound, :upper_bound, :upper_cap_met
4
7
 
@@ -14,7 +17,8 @@ class Solver
14
17
  def solve!
15
18
  iteration_count = 0
16
19
  time_value.i = guess
17
- while (upper_bound - lower_bound).round(2) > 0.01 && iteration_count < 100
20
+ while (upper_bound - lower_bound).round(PRECISION) > INTERVAL &&
21
+ iteration_count < MAX_ITERATIONS
18
22
  iteration_count += 1
19
23
  begin
20
24
  result = time_value.calc_fv
@@ -24,7 +28,7 @@ class Solver
24
28
  adjust_bounds(result)
25
29
  time_value.i = guess
26
30
  end
27
- guess if iteration_count < 100
31
+ guess.round(2) if iteration_count < MAX_ITERATIONS
28
32
  end
29
33
 
30
34
  def adjust_bounds(result)
@@ -37,6 +41,6 @@ class Solver
37
41
  self.upper_bound *= 2 unless upper_cap_met
38
42
  self.lower_bound = guess
39
43
  end
40
- self.guess = ((upper_bound + lower_bound) / 2).round(2)
44
+ self.guess = ((upper_bound + lower_bound) / 2).round(PRECISION)
41
45
  end
42
46
  end
@@ -1,3 +1,3 @@
1
1
  module TimeValue
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randall Reed, Jr.