dohruby 0.1.13 → 0.1.14
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/CHANGELOG +2 -0
- data/lib/doh/core/bigdecimal.rb +11 -0
- data/test/core/tc_bigdecimal.rb +31 -0
- metadata +4 -2
data/CHANGELOG
CHANGED
data/lib/doh/core/bigdecimal.rb
CHANGED
@@ -5,4 +5,15 @@ class BigDecimal
|
|
5
5
|
def to_s(format = 'F')
|
6
6
|
_doh_original_to_s(format)
|
7
7
|
end
|
8
|
+
|
9
|
+
def to_dig(digits_after_decimal = 2)
|
10
|
+
raise ArgumentError.new("digits_after_decimal must be > 0") unless digits_after_decimal > 0
|
11
|
+
return '0.' + ('0' * digits_after_decimal) if nan? || infinite?
|
12
|
+
|
13
|
+
retval = truncate(digits_after_decimal).to_s
|
14
|
+
digits_needed = retval.index('.') + digits_after_decimal + 1 - retval.size
|
15
|
+
retval += ('0' * digits_needed) if digits_needed > 0
|
16
|
+
|
17
|
+
retval
|
18
|
+
end
|
8
19
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'doh/core/bigdecimal'
|
3
|
+
|
4
|
+
module Doh
|
5
|
+
|
6
|
+
class TC_core_bigdecimal < Test::Unit::TestCase
|
7
|
+
def test_to_dig_valid
|
8
|
+
assert_equal('0.00', BigDecimal('0').to_dig)
|
9
|
+
assert_equal('1.00', BigDecimal('1').to_dig)
|
10
|
+
assert_equal('1.10', BigDecimal('1.1').to_dig)
|
11
|
+
assert_equal('1.11', BigDecimal('1.11134').to_dig)
|
12
|
+
assert_equal('1.111', BigDecimal('1.1113456').to_dig(3))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_to_dig_errors
|
16
|
+
assert_raise(ArgumentError) { BigDecimal('1').to_dig(-1) }
|
17
|
+
assert_raise(ArgumentError) { BigDecimal('1').to_dig(0) }
|
18
|
+
assert_equal('0.00', BigDecimal('NaN').to_dig)
|
19
|
+
assert_equal('0.00', BigDecimal('Infinity').to_dig)
|
20
|
+
assert_equal('0.00', BigDecimal('blah').to_dig)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_to_dig_doesnt_modify
|
24
|
+
bd = BigDecimal('1.11134')
|
25
|
+
assert_equal('1.11134', bd.to_s)
|
26
|
+
assert_equal('1.11', bd.to_dig)
|
27
|
+
assert_equal('1.11134', bd.to_s)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dohruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makani & Kem Mason
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-05-10 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/doh/util/unit_test_logging.rb
|
90
90
|
- lib/doh.rb
|
91
91
|
- test/core
|
92
|
+
- test/core/tc_bigdecimal.rb
|
92
93
|
- test/core/tc_string.rb
|
93
94
|
- test/logger
|
94
95
|
- test/logger/sample.rb
|
@@ -134,6 +135,7 @@ signing_key:
|
|
134
135
|
specification_version: 2
|
135
136
|
summary: DohRuby's purpose is to make your life as a developer easier & make you more efficient in your programming.
|
136
137
|
test_files:
|
138
|
+
- test/core/tc_bigdecimal.rb
|
137
139
|
- test/core/tc_string.rb
|
138
140
|
- test/logger/sample.rb
|
139
141
|
- test/logger/tc_acceptor.rb
|