y_support 2.0.10 → 2.0.11

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: 4432f7ef973dca2e7f87209c1e87d0eeaee4f8a5
4
- data.tar.gz: 9bcb2d62ec6f26ccb51418fc4d5ff1b4e2b892ff
3
+ metadata.gz: bc98d20ebfbbb5861b8ec817347e5d73a71e4518
4
+ data.tar.gz: 1226960b1bc6b9e15a0c1626816266378fa489de
5
5
  SHA512:
6
- metadata.gz: 721d34ead1fd14834e9af3eed8568d379f58f1c10fb6f89b0460ad08635f5f4fac4709780f9dbfaae66436f2a16ae1042640968cedd9b17c936b372da15b86f8
7
- data.tar.gz: 47a5d2e4333ec6d78b6ba6ae302ce9d471a6a9d928b130fc9266ac640b4f8e253c0141cf79b8ea00fab5c378f299ff8827492c7077179e6861ab117479e9eb0d
6
+ metadata.gz: 070a617610e329aa6a5ca5ac868ab3f875864485626e4db658da11bade01e37fb64f56a9323d41dc2a98acbac23e440bf3abb15a2d25fd4a0803d9c639713cda
7
+ data.tar.gz: 68f0b3f5b32caa61bc0fe44391d1946ca25dc6e394dbdc23fdcfe3e63d5b7d8489f9906a691d3b71107b4993a35192f65f452ee33a1a7628d34d4414718b65c7
@@ -1,5 +1,5 @@
1
1
  class Array
2
- # Converts an array, whose elements are also arrays, to a hash. Head
2
+ # Converts an array, whose elements are also arrays, to a hash. Head
3
3
  # (position 0) of each array is made to point at the rest of the array
4
4
  # (tail), normally starting immediately after the head (position 1). The
5
5
  # starting position of the tail can be controlled by an optional
@@ -12,26 +12,51 @@ class Array
12
12
  }
13
13
  end
14
14
 
15
- # Does things for each consecutive pair (expects a binary block).
16
- #
17
- def each_consecutive_pair
18
- if block_given?
19
- return self if ( n = self.size - 1 ) <= 0
20
- n.times.with_index{|i| yield( self[i], self[i+1] ) }
21
- return self
22
- else
23
- return Enumerator.new do |yielder|
24
- n.times.with_index{|i| yielder << [ self[i], self[i+1] ] } unless
25
- ( n = self.size - 1 ) <= 0
26
- end
27
- end
28
- end
29
-
30
15
  # Allows style &[ function, *arguments ]
31
16
  #
32
17
  def to_proc
33
18
  proc { |receiver| receiver.send *self }
34
19
  end # def to_proc
20
+
21
+ # With array construction syntax [:foo, bar: 42] now possible in Ruby, arrays
22
+ # become closer to argument collections, and supporting methods might come
23
+ # handy. This method pushes an element on top of the "ordered arguments" part
24
+ # of the array.
25
+ #
26
+ def push_ordered element
27
+ return push element unless last.is_a? Hash
28
+ push pop.tap { push element }
29
+ end
30
+
31
+ # With array construction syntax [:foo, bar: 42] now possible in Ruby, arrays
32
+ # become closer to argument collections, and supporting methods might come
33
+ # handy. This method pushes an element on top of the "named arguments" part
34
+ # of the array.
35
+ #
36
+ def push_named **oo
37
+ l = last
38
+ return push oo unless l.is_a? Hash
39
+ tap { l.update oo }
40
+ end
41
+
42
+ # With array construction syntax [:foo, bar: 42] now possible in Ruby, arrays
43
+ # become closer to argument collections, and supporting methods might come
44
+ # handy. This method pops an element from the "ordered arguments" array part.
45
+ #
46
+ def pop_ordered
47
+ l = pop
48
+ return l unless l.is_a? Hash
49
+ pop.tap { push l }
50
+ end
51
+
52
+ # With array construction syntax [:foo, bar: 42] now possible in Ruby, arrays
53
+ # become closer to argument collections, and supporting methods might come
54
+ # handy. This method pops an element from the "ordered arguments" array part.
55
+ #
56
+ def pop_named key
57
+ l = last
58
+ l.delete( key ).tap { pop if l.empty? } if l.is_a? Hash
59
+ end
35
60
 
36
61
  # TEST ME
37
62
  # def pretty_inspect
@@ -1,43 +1,4 @@
1
1
  #encoding: utf-8
2
2
 
3
3
  class Module
4
- # Further automation of soon-to-be-deprecated #autorequire.
5
- #
6
- def autoreq( *symbols, descending_path: '..', ascending_path_prefix: 'lib' )
7
-
8
- require 'active_support/core_ext/string/inflections'
9
-
10
- namespace = self.name
11
- namespace_path = namespace.underscore
12
- namespace_chain = namespace.split "::"
13
- ascending_path = ascending_path_prefix + '/' + namespace_path
14
- symbols.map( &:to_s ).each { |ς|
15
- next if ς.strip.empty?
16
- camelized_ß = ς.camelize.to_sym
17
- path = './' + [ descending_path, ascending_path, ς ].join( '/' )
18
- autoload camelized_ß, path
19
- }
20
- end
21
-
22
- # I didn't write this method by myself.
23
- #
24
- def attr_accessor_with_default *symbols, &block
25
- raise ArgumentError, 'Block with default value required!' unless block
26
- symbols.each { |ß|
27
- module_eval {
28
- define_method "#{ß}=" do |arg|
29
- instance_variable_set "@#{ß}", arg
30
- end
31
- define_method ß do
32
- singleton_class.class_eval { attr_reader ß }
33
- if instance_variables.include? "@#{ß}".to_sym then
34
- instance_variable_get "@#{ß}"
35
- else
36
- instance_variable_set "@#{ß}", block.call
37
- end
38
- end
39
- }
40
- }
41
- end
42
- alias :attr_accessor_w_default :attr_accessor_with_default
43
4
  end
@@ -1,3 +1,3 @@
1
1
  module YSupport
2
- VERSION = "2.0.10"
2
+ VERSION = "2.0.11"
3
3
  end
data/test/misc_test.rb CHANGED
@@ -1,289 +1,281 @@
1
1
  #! /usr/bin/ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- require 'test/unit'
5
- require 'shoulda'
6
-
7
- class MiscTest < Test::Unit::TestCase
8
- context "Object" do
9
- setup do
10
- require 'y_support/core_ext/object'
11
- end
12
-
13
- should "have #const_set_if_not_defined" do
14
- ( = Object.new ).const_set_if_not_defined :KOKO, 42
15
- assert_equal 42, ◉.singleton_class::KOKO
16
- ◉.const_set_if_not_defined :KOKO, 43
17
- assert_equal 42, ◉.singleton_class::KOKO
18
- end
19
-
20
- should "have #const_redef_without_warning" do
21
- ( ◉ = Object.new ).const_set_if_not_defined :KOKO, 42
22
- ◉.const_redefine_without_warning :KOKO, 43
23
- assert_equal 43, ◉.singleton_class::KOKO
24
- end
25
- end # context Object
26
-
27
- context "Module" do
28
- setup do
29
- require 'y_support/core_ext/module'
30
- end
31
-
32
- should "have working #attr_accessor_with_default" do
33
- class Klass
34
- attr_accessor_with_default :hello do "world" end
35
- end
36
- assert_equal "world", Klass.new.hello
37
- instance = Klass.new
38
- instance.hello = "certain string" # testing setter
39
- assert_equal "certain string", instance.hello # testing getter
40
- end
41
-
42
- should "have working autoreq" do
43
- module TestModule
44
- autoreq :fixture_class, descending_path: '.', ascending_path_prefix: '.'
45
- end
46
- assert_equal "world", TestModule::FixtureClass.new.hello
47
- end
48
- end # context Module
49
-
50
- context "Enumerable" do
51
- setup do
52
- require 'y_support/core_ext/enumerable'
53
- end
54
-
55
- should "introduce #all_kind_of? collection qualifier" do
56
- assert_equal true, [ 1, 1.0 ].all_kind_of?( Numeric )
57
- assert_equal false, [ 1, [1.0] ].all_kind_of?( Numeric )
58
- end
59
-
60
- should "introduce #all_numeric? collection qualifier" do
61
- assert_equal true, [1, 1.0].all_numeric?
62
- assert_equal false, [:a, 1].all_numeric?
63
- end
64
-
65
- should "have #subset_of? collection qualifier" do
66
- assert_equal( true, [1,2].subset_of?( [1,2,3,4] ) )
67
- assert_equal( false, [1,2].subset_of?( [2,3] ) )
68
- assert_equal( true, [1,2].subset_of?( [1,2] ) )
69
- assert_equal( true, [1, 1.0].subset_of?( [1.0, 2.0] ) )
70
- end
71
- end # context Enumerable
72
-
73
- context "Array" do
74
- setup do
75
- require 'y_support/core_ext/array'
76
- end
77
-
78
- should "have #to_hash" do
79
- assert_equal( {a: :b, c: :d}, [[:a, :b],[:c, :d]].to_hash )
80
- assert_equal( {k: :kokot, p: :pica}, [[:k, :o, :kokot], [:p, :i, :pica]].to_hash(2) )
81
- end
82
-
83
- should "have #each_consecutive_pair iterator" do
84
- assert_kind_of Enumerator, [].each_consecutive_pair
85
- assert_kind_of Enumerator, [:a].each_consecutive_pair
86
- assert_kind_of Enumerator, [:a, :b].each_consecutive_pair
87
- assert_kind_of Enumerator, [:a, :b, :c].each_consecutive_pair
88
- assert_equal [], [].each_consecutive_pair.collect{|e| e }
89
- assert_equal [], [:a].each_consecutive_pair.collect{|e| e }
90
- assert_equal [[:a, :b]], [:a, :b].each_consecutive_pair.collect{|e| e }
91
- assert_equal [[:a, :b], [:b, :c]], [:a, :b, :c].each_consecutive_pair.collect{|e| e }
92
- end
93
-
94
- should "have #to_proc in style &[ function, *arguments ]" do
95
- assert_equal [2, 3], [1, 2].map( &[:+, 1] )
96
- end
97
- end # context Array
98
-
99
- context "Hash" do
100
- setup do
101
- require 'y_support/core_ext/hash'
102
- end
103
-
104
- should "have #default! custom defaulter" do
105
- defaults = { a: 1, b: nil }
106
- test = {}
107
- result = test.default!( defaults )
108
- assert_equal defaults, result
109
- assert_equal result.object_id, test.object_id
110
- test = { a: 11, b: 22 }
111
- assert_equal( { a: 11, b: 22 }, test.default!( defaults ) )
112
- test = { a: 11, c: 22 }
113
- assert_equal( { a: 11, b: nil, c: 22 }, test.default!( defaults ) )
114
- end
115
-
116
- should "have #with_keys and #modify_keys" do
117
- assert_equal( {"a" => :b, "c" => :d}, {a: :b, c: :d}.with_keys( &:to_s ) )
118
- assert_equal( {"a1" => 1, "c2" => 2}, {a: 1, c: 2}.modify_keys { |k, v|
119
- k.to_s + v.to_s } )
120
- assert_equal( {"a1" => 1, "c2" => 2}, {a: 1, c: 2}.modify_keys {|p|
121
- p[0].to_s + p[1].to_s } )
122
- assert_equal( {2 => 1, 4 => 2}, {1 => 1, 2 => 2}.modify_keys { |k, v|
123
- k + v } )
124
- assert_equal( {2 => 1, 4 => 2}, {1 => 1, 2 => 2}.modify_keys { |p|
125
- p[0] + p[1] } )
126
- end
127
-
128
- should "have #with_values and #modify_values" do
129
- assert_equal( { a: "b", c: "d" }, {a: :b, c: :d}.with_values( &:to_s ) )
130
- assert_equal( {a: "ab", c: "cd"}, {a: :b, c: :d}.modify_values { |k, v|
131
- k.to_s + v.to_s } )
132
- assert_equal( {a: "ab", c: "cd"}, {a: :b, c: :d}.modify_values { |p|
133
- p[0].to_s + p[1].to_s } )
134
- hh = { a: 1, b: 2 }
135
- hh.with_values! &:to_s
136
- assert_equal ["1", "2"], hh.values
137
- hh.modify_values! &:join
138
- assert_equal ["a1", "b2"], hh.values
139
- end
140
-
141
- should "have #modify" do
142
- assert_equal( { ab: "ba", cd: "dc" },
143
- { a: :b, c: :d }
144
- .modify { |k, v| ["#{k}#{v}".to_sym, "#{v}#{k}"] } )
145
- end
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+
7
+ describe Object do
8
+ before do
9
+ require 'y_support/core_ext/object'
10
+ end
11
+
12
+ it "should have #const_set_if_not_defined" do
13
+ ( = Object.new ).const_set_if_not_defined :KOKO, 42
14
+ assert_equal 42, ◉.singleton_class::KOKO
15
+ ◉.const_set_if_not_defined :KOKO, 43
16
+ assert_equal 42, ◉.singleton_class::KOKO
17
+ end
18
+
19
+ it "should have #const_redef_without_warning" do
20
+ ( = Object.new ).const_set_if_not_defined :KOKO, 42
21
+ ◉.const_redefine_without_warning :KOKO, 43
22
+ assert_equal 43, ◉.singleton_class::KOKO
23
+ end
24
+ end
25
+
26
+
27
+ describe Module do
28
+ before do
29
+ require 'y_support/core_ext/module'
30
+ end
31
+
32
+ it "presently has no extensions" do
33
+ end
34
+ end
35
+
36
+
37
+ describe Enumerable do
38
+ before do
39
+ require 'y_support/core_ext/enumerable'
40
+ end
41
+
42
+ it "should introduce #all_kind_of? collection qualifier" do
43
+ assert_equal true, [ 1, 1.0 ].all_kind_of?( Numeric )
44
+ assert_equal false, [ 1, [1.0] ].all_kind_of?( Numeric )
45
+ end
146
46
 
147
- should "have #dot! meta patcher for dotted access to keys" do
148
- h = Hash.new.merge!(aaa: 1, taint: 2)
149
- assert_raise ArgumentError do h.dot! end
150
- assert_nothing_raised do h.dot!( overwrite_methods: true ) end
151
- assert_equal( {aaa: 1}, {aaa: 1}.dot! )
152
- end
153
- end # context Hash
47
+ it "should introduce #all_numeric? collection qualifier" do
48
+ assert_equal true, [1, 1.0].all_numeric?
49
+ assert_equal false, [:a, 1].all_numeric?
50
+ end
51
+
52
+ it "should have #subset_of? collection qualifier" do
53
+ assert_equal( true, [1,2].subset_of?( [1,2,3,4] ) )
54
+ assert_equal( false, [1,2].subset_of?( [2,3] ) )
55
+ assert_equal( true, [1,2].subset_of?( [1,2] ) )
56
+ assert_equal( true, [1, 1.0].subset_of?( [1.0, 2.0] ) )
57
+ end
58
+ end
59
+
60
+
61
+ describe Array do
62
+ before do
63
+ require 'y_support/core_ext/array'
64
+ end
154
65
 
155
- context "Matrix" do
156
- setup do
157
- require 'y_support/stdlib_ext/matrix'
158
- end
159
-
160
- should "have #pp method" do
161
- assert_respond_to Matrix[[1, 2], [3, 4]], :pretty_print
162
- assert_respond_to Matrix[[1, 2], [3, 4]], :pp
163
- end
164
-
165
- should "have #correspondence_matrix method" do
166
- assert_respond_to Matrix, :correspondence_matrix
167
- assert_equal Matrix[[1, 0, 0], [0, 1, 0]],
168
- Matrix.correspondence_matrix( [:a, :b, :c], [:a, :b] )
169
- assert_equal Matrix.column_vector( [1, 2] ),
170
- Matrix.correspondence_matrix( [:a, :b, :c], [:a, :b] ) *
171
- Matrix.column_vector( [1, 2, 3] )
172
- assert_equal 2, Matrix.correspondence_matrix( [1, 2], [1] ).column_size
173
- end
174
-
175
- should "have #column_to_a & #row_to_a" do
176
- assert_equal [1, 2, 3], Matrix[[1], [2], [3]].column_to_a
177
- assert_equal [2, 3, 4], Matrix[[1, 2], [2, 3], [3, 4]].column_to_a( 1 )
178
- assert_equal nil, Matrix.empty( 5, 0 ).column_to_a
179
- assert_equal [1], Matrix[[1], [2], [3]].row_to_a
180
- assert_equal [3], Matrix[[1], [2], [3]].row_to_a( 2 )
181
- end
182
-
183
- should "have aliased #row_vector, #column_vector methods" do
184
- assert_equal Matrix.column_vector( [1, 2, 3] ),
185
- Matrix.cv( [1, 2, 3] )
186
- assert_equal Matrix.row_vector( [1, 2, 3] ),
187
- Matrix.rv( [1, 2, 3] )
188
- end
189
-
190
- should "have #join_bottom and #join_right" do
191
- assert_equal Matrix[[1, 2], [3, 4]],
192
- Matrix[[1, 2]].join_bottom( Matrix[[3, 4]] )
193
- assert_equal Matrix[[1, 2, 3, 4]],
194
- Matrix[[1, 2]].join_right( Matrix[[3, 4]] )
195
- end
196
-
197
- should "have aliased #row_size, #column_size methods" do
198
- assert_equal 3, Matrix.zero(3, 2).height
199
- assert_equal 3, Matrix.zero(3, 2).number_of_rows
200
- assert_equal 2, Matrix.zero(3, 2).width
201
- assert_equal 2, Matrix.zero(3, 2).number_of_columns
202
- end
203
- end # context Matrix
66
+ it "has #to_hash" do
67
+ assert_equal( {a: :b, c: :d}, [[:a, :b],[:c, :d]].to_hash )
68
+ assert_equal( {k: :kokot, p: :pica}, [[:k, :o, :kokot], [:p, :i, :pica]].to_hash(2) )
69
+ end
204
70
 
205
- context "String" do
206
- setup do
207
- require 'y_support/core_ext/string'
208
- end
209
-
210
- should "have #can_be_integer? returning the integer or false if not convertible" do
211
- assert_equal 33, " 33".to_Integer
212
- assert_equal 8, " 010 ".to_Integer
213
- assert_equal false, "garbage".to_Integer
214
- end
215
-
216
- should "have #can_be_float? returning the float or false if not convertible" do
217
- assert_equal 22.2, ' 2.22e1'.to_Float
218
- assert_equal 10, " 010 ".to_Float
219
- assert_equal false, "garbage".to_Float
220
- end
221
-
222
- should "have #default! defaulter" do
223
- assert_equal "default", "".default!("default")
224
- assert_equal "default", " ".default!(:default)
225
- assert_equal "default", " \n ".default!("default")
226
- assert_equal "kokot", "kokot".default!("default")
227
- a = ""
228
- assert_equal a.object_id, a.default!("tata").object_id
229
- end
230
-
231
- should "have #stripn upgrade of #strip, which also strips newlines" do
232
- assert_equal "test test", " \n test test \n\n \n ".stripn
233
- end
234
-
235
- should "have #compact for joining indented lines (esp. heredocs)" do
236
- assert_equal "test test test",
237
- "test\n test\n\n \n test\n ".wring_heredoc
238
- funny_string = <<-FUNNY_STRING.wring_heredoc
71
+ it "has #to_proc in style &[function, *args]" do
72
+ assert_equal [2, 3], [1, 2].map( &[:+, 1] )
73
+ end
74
+
75
+ it "has #push/pop_ordered/named" do
76
+ a = [1, 2, foo: 3]
77
+ a.pop_named( :foo ).must_equal 3
78
+ a.pop_named( :bar ).must_equal nil
79
+ a.pop_ordered.must_equal 2
80
+ a.push_ordered( 2 ).must_equal [1, 2]
81
+ a.push_named( foo: 3 ).must_equal [1, 2, foo: 3]
82
+ a.push_named( bar: 4 ).must_equal [1, 2, foo: 3, bar: 4]
83
+ a.pop_named( :foo ).must_equal 3
84
+ a.push_ordered( 42 ).must_equal [1, 2, 42, bar: 4]
85
+ end
86
+ end
87
+
88
+ describe Hash do
89
+ before do
90
+ require 'y_support/core_ext/hash'
91
+ end
92
+
93
+ it "should have #default! custom defaulter" do
94
+ defaults = { a: 1, b: nil }
95
+ test = {}
96
+ result = test.default!( defaults )
97
+ assert_equal defaults, result
98
+ assert_equal result.object_id, test.object_id
99
+ test = { a: 11, b: 22 }
100
+ assert_equal( { a: 11, b: 22 }, test.default!( defaults ) )
101
+ test = { a: 11, c: 22 }
102
+ assert_equal( { a: 11, b: nil, c: 22 }, test.default!( defaults ) )
103
+ end
104
+
105
+ it "should have #with_keys and #modify_keys" do
106
+ assert_equal( {"a" => :b, "c" => :d}, {a: :b, c: :d}.with_keys( &:to_s ) )
107
+ assert_equal( {"a1" => 1, "c2" => 2}, {a: 1, c: 2}.modify_keys { |k, v|
108
+ k.to_s + v.to_s } )
109
+ assert_equal( {"a1" => 1, "c2" => 2}, {a: 1, c: 2}.modify_keys {|p|
110
+ p[0].to_s + p[1].to_s } )
111
+ assert_equal( {2 => 1, 4 => 2}, {1 => 1, 2 => 2}.modify_keys { |k, v|
112
+ k + v } )
113
+ assert_equal( {2 => 1, 4 => 2}, {1 => 1, 2 => 2}.modify_keys { |p|
114
+ p[0] + p[1] } )
115
+ end
116
+
117
+ it "should have #with_values and #modify_values" do
118
+ assert_equal( { a: "b", c: "d" }, {a: :b, c: :d}.with_values( &:to_s ) )
119
+ assert_equal( {a: "ab", c: "cd"}, {a: :b, c: :d}.modify_values { |k, v|
120
+ k.to_s + v.to_s } )
121
+ assert_equal( {a: "ab", c: "cd"}, {a: :b, c: :d}.modify_values { |p|
122
+ p[0].to_s + p[1].to_s } )
123
+ hh = { a: 1, b: 2 }
124
+ hh.with_values! &:to_s
125
+ assert_equal ["1", "2"], hh.values
126
+ hh.modify_values! &:join
127
+ assert_equal ["a1", "b2"], hh.values
128
+ end
129
+
130
+ it "should have #modify" do
131
+ assert_equal( { ab: "ba", cd: "dc" },
132
+ { a: :b, c: :d }
133
+ .modify { |k, v| ["#{k}#{v}".to_sym, "#{v}#{k}"] } )
134
+ end
135
+
136
+ it "should have #dot! meta patcher for dotted access to keys" do
137
+ h = Hash.new.merge!(aaa: 1, taint: 2)
138
+ -> { h.dot! }.must_raise ArgumentError
139
+ h.dot!( overwrite_methods: true ) # instead of #assert_nothing_raised
140
+ assert_equal( {aaa: 1}, {aaa: 1}.dot! )
141
+ end
142
+ end
143
+
144
+
145
+ describe "Matrix" do
146
+ before do
147
+ require 'matrix'
148
+ require 'y_support/stdlib_ext/matrix'
149
+ end
150
+
151
+ it "should have #pp method" do
152
+ assert_respond_to Matrix[[1, 2], [3, 4]], :pretty_print
153
+ assert_respond_to Matrix[[1, 2], [3, 4]], :pp
154
+ end
155
+
156
+ it "should have #correspondence_matrix method" do
157
+ assert_respond_to Matrix, :correspondence_matrix
158
+ assert_equal Matrix[[1, 0, 0], [0, 1, 0]],
159
+ Matrix.correspondence_matrix( [:a, :b, :c], [:a, :b] )
160
+ assert_equal Matrix.column_vector( [1, 2] ),
161
+ Matrix.correspondence_matrix( [:a, :b, :c], [:a, :b] ) *
162
+ Matrix.column_vector( [1, 2, 3] )
163
+ assert_equal 2, Matrix.correspondence_matrix( [1, 2], [1] ).column_size
164
+ end
165
+
166
+ it "should have #column_to_a & #row_to_a" do
167
+ assert_equal [1, 2, 3], Matrix[[1], [2], [3]].column_to_a
168
+ assert_equal [2, 3, 4], Matrix[[1, 2], [2, 3], [3, 4]].column_to_a( 1 )
169
+ assert_equal nil, Matrix.empty( 5, 0 ).column_to_a
170
+ assert_equal [1], Matrix[[1], [2], [3]].row_to_a
171
+ assert_equal [3], Matrix[[1], [2], [3]].row_to_a( 2 )
172
+ end
173
+
174
+ it "should have aliased #row_vector, #column_vector methods" do
175
+ assert_equal Matrix.column_vector( [1, 2, 3] ),
176
+ Matrix.cv( [1, 2, 3] )
177
+ assert_equal Matrix.row_vector( [1, 2, 3] ),
178
+ Matrix.rv( [1, 2, 3] )
179
+ end
180
+
181
+ it "should have #join_bottom and #join_right" do
182
+ assert_equal Matrix[[1, 2], [3, 4]],
183
+ Matrix[[1, 2]].join_bottom( Matrix[[3, 4]] )
184
+ assert_equal Matrix[[1, 2, 3, 4]],
185
+ Matrix[[1, 2]].join_right( Matrix[[3, 4]] )
186
+ end
187
+
188
+ it "should have aliased #row_size, #column_size methods" do
189
+ assert_equal 3, Matrix.zero(3, 2).height
190
+ assert_equal 3, Matrix.zero(3, 2).number_of_rows
191
+ assert_equal 2, Matrix.zero(3, 2).width
192
+ assert_equal 2, Matrix.zero(3, 2).number_of_columns
193
+ end
194
+ end
195
+
196
+ describe String do
197
+ before do
198
+ require 'y_support/core_ext/string'
199
+ end
200
+
201
+ it "should have #can_be_integer? returning the integer or false if not convertible" do
202
+ assert_equal 33, " 33".to_Integer
203
+ assert_equal 8, " 010 ".to_Integer
204
+ assert_equal false, "garbage".to_Integer
205
+ end
206
+
207
+ it "should have #can_be_float? returning the float or false if not convertible" do
208
+ assert_equal 22.2, ' 2.22e1'.to_Float
209
+ assert_equal 10, " 010 ".to_Float
210
+ assert_equal false, "garbage".to_Float
211
+ end
212
+
213
+ it "should have #default! defaulter" do
214
+ assert_equal "default", "".default!("default")
215
+ assert_equal "default", " ".default!(:default)
216
+ assert_equal "default", " \n ".default!("default")
217
+ assert_equal "kokot", "kokot".default!("default")
218
+ a = ""
219
+ assert_equal a.object_id, a.default!("tata").object_id
220
+ end
221
+
222
+ it "should have #stripn upgrade of #strip, which also strips newlines" do
223
+ assert_equal "test test", " \n test test \n\n \n ".stripn
224
+ end
225
+
226
+ it "should have #compact for joining indented lines (esp. heredocs)" do
227
+ assert_equal "test test test",
228
+ "test\n test\n\n \n test\n ".wring_heredoc
229
+ funny_string = <<-FUNNY_STRING.wring_heredoc
239
230
  This
240
231
  is
241
232
  a funny string.
242
233
  FUNNY_STRING
243
- assert_equal( 'This is a funny string.', funny_string )
244
- end
245
-
246
- should "be able #underscore_spaces" do
247
- assert_equal "te_st_test", "te st test".underscore_spaces
248
- end
249
-
250
- should "have #symbolize stripping, removing capitalization and diacritics " \
251
- 'as if to make a suitable symbol material' do
252
- assert_equal "Yes_sir!", " \nYes, sir!.; \n \n".standardize
253
- end
254
-
255
- should "have #to_standardized_sym chaining #standardize and #to_sym" do
256
- assert_equal :Yes, " \nYes,.; \n \n".to_standardized_sym
257
- end
258
- end # context String
259
-
260
- context "Symbol" do
261
- setup do
262
- require 'y_support/core_ext/symbol'
263
- end
264
-
265
- should "have #default! defaulter going through String#default!" do
266
- assert_equal :default, "".to_sym.default!(:default)
267
- assert_equal :default, "".to_sym.default!("default")
268
- assert_equal :default, " ".to_sym.default!("default")
269
- assert_equal :default, " \n ".to_sym.default!("default")
270
- assert_equal :kokot, :kokot.default!("default")
271
- end
272
-
273
- should "have #to_standardized_sym" do
274
- assert_equal :Yes, (:" \nYes, \n").to_standardized_sym
275
- end
276
- end # context Symbol
277
-
278
- context "Numeric" do
279
- setup do
280
- require 'y_support/core_ext/numeric'
281
- end
282
-
283
- should "have #zero public class methods" do
284
- assert_equal 0, Integer.zero
285
- assert_equal 0.0, Float.zero
286
- assert_equal Complex(0, 0), Complex.zero
287
- end
288
- end
289
- end # class YSupportTest
234
+ assert_equal( 'This is a funny string.', funny_string )
235
+ end
236
+
237
+ it "should be able #underscore_spaces" do
238
+ assert_equal "te_st_test", "te st test".underscore_spaces
239
+ end
240
+
241
+ it "should have #symbolize stripping, removing capitalization and diacritics " \
242
+ 'as if to make a suitable symbol material' do
243
+ assert_equal "Yes_sir!", " \nYes, sir!.; \n \n".standardize
244
+ end
245
+
246
+ it "should have #to_standardized_sym chaining #standardize and #to_sym" do
247
+ assert_equal :Yes, " \nYes,.; \n \n".to_standardized_sym
248
+ end
249
+ end
250
+
251
+
252
+ describe Symbol do
253
+ before do
254
+ require 'y_support/core_ext/symbol'
255
+ end
256
+
257
+ it "should have #default! defaulter going through String#default!" do
258
+ assert_equal :default, "".to_sym.default!(:default)
259
+ assert_equal :default, "".to_sym.default!("default")
260
+ assert_equal :default, " ".to_sym.default!("default")
261
+ assert_equal :default, " \n ".to_sym.default!("default")
262
+ assert_equal :kokot, :kokot.default!("default")
263
+ end
264
+
265
+ it "should have #to_standardized_sym" do
266
+ assert_equal :Yes, (:" \nYes, \n").to_standardized_sym
267
+ end
268
+ end
269
+
270
+
271
+ describe Numeric do
272
+ before do
273
+ require 'y_support/core_ext/numeric'
274
+ end
275
+
276
+ it "should have #zero public class methods" do
277
+ assert_equal 0, Integer.zero
278
+ assert_equal 0.0, Float.zero
279
+ assert_equal Complex(0, 0), Complex.zero
280
+ end
281
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport