numerals 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -249,4 +249,12 @@ class TestFormatInput < Test::Unit::TestCase # < Minitest::Test
249
249
  assert_equal Flt::DecNum('-0.667'), f.read("*******-0.667*******", type: Flt::DecNum)
250
250
  end
251
251
 
252
+ def test_alternative_read_parameters
253
+ assert_same_number 0.1, Format[].read('0.1', type: Float)
254
+ assert_same_number 0.1, Format[].read('0.1', as: Float)
255
+ assert_same_number 0.1, Format[].read('0.1', context: Float.context)
256
+ assert_same_number 0.1, Format[].read('0.1', Float)
257
+ assert_same_number 0.1, Format[].read(Float, '0.1')
258
+ end
259
+
252
260
  end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))
2
+ require 'yaml'
3
+
4
+ class TestFormatSugar < Test::Unit::TestCase # < Minitest::Test
5
+
6
+ include Numerals
7
+
8
+ def test_sweetness
9
+ txt = Format << 0.1
10
+ assert_equal Format[].write(0.1), txt.to_s
11
+
12
+ fmt = Format[Rounding[places: 3]]
13
+ txt = fmt << 0.1
14
+ txt_x = fmt.write(0.1)
15
+ assert_equal txt_x, txt.to_s
16
+
17
+ txt = fmt << 0.1 << 0.2
18
+ txt_y = fmt.write(0.2)
19
+ assert_equal [txt_x, txt_y], txt.to_a
20
+ assert_equal "#{txt_x}#{txt_y}", txt.to_s
21
+ txt = fmt << 0.1 << " " << 0.2
22
+ assert_equal [txt_x, ' ', txt_y], txt.to_a
23
+ assert_equal "#{txt_x} #{txt_y}", txt.to_s
24
+
25
+ assert_equal [txt_x, txt_y], fmt.<<(*[0.1, 0.2]).to_a
26
+ result = fmt << 0.1 << [:sci, precision: 3] << 0.2
27
+ assert_equal [txt_x, fmt[:sci, precision: 3].write(0.2)], result.to_a
28
+
29
+ x = fmt >> '0.1' >> Float
30
+ assert_equal fmt.read('0.1', type: Float), x.value
31
+
32
+ to_float = fmt >> Float
33
+ x = fmt.read('0.1', type: Float)
34
+ y = fmt.read('0.2', type: Float)
35
+ assert_same_number x, (to_float << '0.1').value
36
+ to_float.clear
37
+ assert_same_number y, (to_float << '0.2').value
38
+ to_float.clear
39
+ assert_equal [x, y], (to_float << '0.1' << '0.2').to_a
40
+
41
+ assert_equal x, (fmt >> '0.1' >> Float).value
42
+
43
+ convert = fmt >> '0.1'
44
+ x = fmt.read('0.1', type: Float)
45
+ y = fmt.read('0.1', type: Flt::DecNum)
46
+ assert_same_number x, (convert >> Float).value
47
+ convert.clear
48
+ assert_same_number y, (convert >> Flt::DecNum).value
49
+ convert.clear
50
+ assert_equal [x, y], (convert >> Float >> Flt::DecNum).to_a
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numerals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flt
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.6
19
+ version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.6
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: modalsupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.2
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.2
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +98,7 @@ files:
98
98
  - lib/numerals/format/notations/latex.rb
99
99
  - lib/numerals/format/notations/text.rb
100
100
  - lib/numerals/format/output.rb
101
+ - lib/numerals/format/sugar.rb
101
102
  - lib/numerals/format/symbols.rb
102
103
  - lib/numerals/format/symbols/digits.rb
103
104
  - lib/numerals/format/symbols/padding.rb
@@ -113,6 +114,7 @@ files:
113
114
  - test/helper.rb
114
115
  - test/test_base_scaler.rb
115
116
  - test/test_big_conversions.rb
117
+ - test/test_conversions.rb
116
118
  - test/test_digits_definition.rb
117
119
  - test/test_exp_setter.rb
118
120
  - test/test_float_conversions.rb
@@ -121,6 +123,7 @@ files:
121
123
  - test/test_format_input.rb
122
124
  - test/test_format_mode.rb
123
125
  - test/test_format_output.rb
126
+ - test/test_format_sugar.rb
124
127
  - test/test_integer_conversions.rb
125
128
  - test/test_numeral.rb
126
129
  - test/test_qualified.rb
@@ -157,6 +160,7 @@ test_files:
157
160
  - test/helper.rb
158
161
  - test/test_base_scaler.rb
159
162
  - test/test_big_conversions.rb
163
+ - test/test_conversions.rb
160
164
  - test/test_digits_definition.rb
161
165
  - test/test_exp_setter.rb
162
166
  - test/test_float_conversions.rb
@@ -165,6 +169,7 @@ test_files:
165
169
  - test/test_format_input.rb
166
170
  - test/test_format_mode.rb
167
171
  - test/test_format_output.rb
172
+ - test/test_format_sugar.rb
168
173
  - test/test_integer_conversions.rb
169
174
  - test/test_numeral.rb
170
175
  - test/test_qualified.rb