sixarm_ruby_ramp 2.1.3 → 3.0.0

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +1 -1
  4. data/CONTRIBUTING.md +28 -0
  5. data/{README.rdoc → README.md} +112 -42
  6. data/VERSION +1 -1
  7. data/lib/sixarm_ruby_ramp.rb +1 -1
  8. data/lib/sixarm_ruby_ramp/array.rb +39 -16
  9. data/lib/sixarm_ruby_ramp/hash.rb +1 -1
  10. data/lib/sixarm_ruby_ramp/kernel.rb +11 -5
  11. data/lib/sixarm_ruby_ramp/numeric.rb +49 -35
  12. data/lib/sixarm_ruby_ramp/process.rb +5 -20
  13. data/lib/sixarm_ruby_ramp/string.rb +3 -4
  14. data/lib/sixarm_ruby_ramp/xml.rb +0 -204
  15. data/test/sixarm_ruby_ramp_test.rb +2 -2
  16. data/test/sixarm_ruby_ramp_test/array_test.rb +330 -0
  17. data/test/sixarm_ruby_ramp_test/class_test.rb +87 -0
  18. data/test/sixarm_ruby_ramp_test/csv_test.rb +47 -0
  19. data/test/sixarm_ruby_ramp_test/date_test.rb +60 -0
  20. data/test/sixarm_ruby_ramp_test/enumerable_test.rb +303 -0
  21. data/test/sixarm_ruby_ramp_test/file_test.rb +17 -0
  22. data/test/sixarm_ruby_ramp_test/fixnum_test.rb +25 -0
  23. data/test/sixarm_ruby_ramp_test/hash_test.rb +209 -0
  24. data/test/sixarm_ruby_ramp_test/integer_test.rb +21 -0
  25. data/test/sixarm_ruby_ramp_test/io_test.rb +30 -0
  26. data/test/{sixarm_ruby_ramp → sixarm_ruby_ramp_test}/io_test.txt +0 -0
  27. data/test/sixarm_ruby_ramp_test/kernel_test.rb +55 -0
  28. data/test/sixarm_ruby_ramp_test/math_test.rb +19 -0
  29. data/test/sixarm_ruby_ramp_test/nil_test.rb +16 -0
  30. data/test/sixarm_ruby_ramp_test/numeric_test.rb +57 -0
  31. data/test/sixarm_ruby_ramp_test/object_test.rb +13 -0
  32. data/test/sixarm_ruby_ramp_test/process_test.rb +67 -0
  33. data/test/sixarm_ruby_ramp_test/string_test.rb +131 -0
  34. data/test/sixarm_ruby_ramp_test/symbol_test.rb +27 -0
  35. data/test/sixarm_ruby_ramp_test/time_test.rb +29 -0
  36. data/test/sixarm_ruby_ramp_test/xml_test.rb +10 -0
  37. data/test/sixarm_ruby_ramp_test/yaml_test.rb +8 -0
  38. metadata +100 -48
  39. metadata.gz.sig +0 -0
  40. data/CHANGELOG.txt +0 -53
  41. data/INSTALL.txt +0 -32
  42. data/LICENSE.txt +0 -25
  43. data/test/sixarm_ruby_ramp/xml_test_1.xml +0 -5
  44. data/test/sixarm_ruby_ramp/xml_test_2.xml +0 -5
  45. data/test/sixarm_ruby_ramp/xml_test_msword_clean.html +0 -1
  46. data/test/sixarm_ruby_ramp/xml_test_msword_dirty.html +0 -148
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class ClassTest < Minitest::Test
7
+
8
+
9
+ METHOD_REGEXP = /^[abc]\W*$/
10
+ def test_publicize_methods
11
+
12
+ # Before we test the block, ensure our setup is correct
13
+ assert_equal(["a","a!","a=","a?"],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods before block')
14
+ assert_equal(["b","b!","b=","b?"],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods before block')
15
+ assert_equal(["c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods before block')
16
+
17
+ # Now we test inside the block
18
+ My.publicize_methods{
19
+ assert_equal([],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods inside block')
20
+ assert_equal([],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods inside block')
21
+ assert_equal(["a","a!","a=","a?","b","b!","b=","b?","c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods inside block')
22
+ }
23
+
24
+ # After we test the block, ensure our setup is restored
25
+ assert_equal(["a","a!","a=","a?"],My.private_instance_methods.grep_sort_to_s(METHOD_REGEXP),'private methods before block')
26
+ assert_equal(["b","b!","b=","b?"],My.protected_instance_methods.grep_sort_to_s(METHOD_REGEXP),'protected methods before block')
27
+ assert_equal(["c","c!","c=","c?"],My.public_instance_methods.grep_sort_to_s(METHOD_REGEXP),'public methods before block')
28
+
29
+ end
30
+
31
+ protected
32
+
33
+ end
34
+
35
+
36
+ class Array
37
+ def grep_sort_to_s(regexp)
38
+ grep(regexp).sort.map{|x| x.to_s}
39
+ end
40
+ end
41
+
42
+
43
+ class My
44
+
45
+ private
46
+
47
+ def a
48
+ end
49
+
50
+ def a!
51
+ end
52
+
53
+ def a=
54
+ end
55
+
56
+ def a?
57
+ end
58
+
59
+ protected
60
+
61
+ def b
62
+ end
63
+
64
+ def b!
65
+ end
66
+
67
+ def b=
68
+ end
69
+
70
+ def b?
71
+ end
72
+
73
+ public
74
+
75
+ def c
76
+ end
77
+
78
+ def c!
79
+ end
80
+
81
+ def c=
82
+ end
83
+
84
+ def c?
85
+ end
86
+
87
+ end
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class CSVTest < Minitest::Test
7
+
8
+ def test_http_headers
9
+ h=CSV.http_headers
10
+ assert_equal('text/csv',h["Content-Type"])
11
+ assert_equal("attachment; filename=\"data.csv\"",h["Content-Disposition"])
12
+ end
13
+
14
+ def test_http_headers_with_filename
15
+ h=CSV.http_headers(:filename=>'foo')
16
+ assert_equal('text/csv',h["Content-Type"])
17
+ assert_equal("attachment; filename=\"foo\"",h["Content-Disposition"])
18
+ end
19
+
20
+ def test_http_headers_adjust_for_broken_msie_with_request_as_firefox
21
+ headers = {:request => MockRequest.new('HTTP_USER_AGENT' => 'firefox')}
22
+ headers = CSV.http_headers_adjust_for_broken_msie(headers)
23
+ assert_equal(nil,headers[:content_type])
24
+ assert_equal(nil,headers[:cache])
25
+ end
26
+
27
+ def test_http_headers_adjust_for_broken_msie_with_request_as_msie
28
+ headers = {:request => MockRequest.new('HTTP_USER_AGENT' => 'msie')}
29
+ headers = CSV.http_headers_adjust_for_broken_msie(headers)
30
+ assert_equal('text/plain',headers[:content_type])
31
+ assert_equal(false,headers[:cache])
32
+ end
33
+
34
+ end
35
+
36
+ class MockRequest
37
+
38
+ def initialize(env)
39
+ @env=env
40
+ end
41
+
42
+ def env
43
+ @env
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class DateTest < Minitest::Test
7
+
8
+
9
+ def test_weekday
10
+ # Start on Monday, January 1, 2007
11
+ assert( Date.new(2007,1,1).weekday?)
12
+ assert( Date.new(2007,1,2).weekday?)
13
+ assert( Date.new(2007,1,3).weekday?)
14
+ assert( Date.new(2007,1,4).weekday?)
15
+ assert( Date.new(2007,1,5).weekday?)
16
+ assert(!Date.new(2007,1,6).weekday?)
17
+ assert(!Date.new(2007,1,7).weekday?)
18
+ assert( Date.new(2007,1,8).weekday?)
19
+ end
20
+
21
+
22
+ def test_weekend
23
+ # Start on Monday, January 1, 2007
24
+ assert(!Date.new(2007,1,1).weekend?)
25
+ assert(!Date.new(2007,1,2).weekend?)
26
+ assert(!Date.new(2007,1,3).weekend?)
27
+ assert(!Date.new(2007,1,4).weekend?)
28
+ assert(!Date.new(2007,1,5).weekend?)
29
+ assert( Date.new(2007,1,6).weekend?)
30
+ assert( Date.new(2007,1,7).weekend?)
31
+ assert(!Date.new(2007,1,8).weekend?)
32
+ end
33
+
34
+
35
+ def test_to_sql_with_non_zero_month_and_mday
36
+ assert_equal('2007-12-31',Date.new(2007,12,31).to_sql)
37
+ end
38
+
39
+
40
+ def test_to_sql_with_zero_month_and_mday
41
+ assert_equal('2007-01-02',Date.new(2007,1,2).to_sql)
42
+ end
43
+
44
+
45
+ def test_between
46
+ d1= Date.parse('2008-01-01')
47
+ d2= Date.parse('2009-01-01')
48
+ d3= Date.between(d1,d2)
49
+ assert(d3>=d1)
50
+ assert(d3<=d2)
51
+ end
52
+
53
+
54
+ def self.between(min,max)
55
+ min+rand(max-min)
56
+ end
57
+
58
+
59
+ end
60
+
@@ -0,0 +1,303 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+ require 'set'
5
+
6
+
7
+ class EnumerableTest < Minitest::Test
8
+
9
+ ITEMS = ['a','b','c']
10
+ MAPTEST = [123,"456"] # to test typecasts-- one is numeric and one is string
11
+ RGB = ["red","green","blue"] # to test case changes
12
+
13
+
14
+ ########################################################################
15
+ #
16
+ # typecast
17
+ #
18
+ ########################################################################
19
+
20
+
21
+ def test_to_h_with_unique_keys
22
+ a=[[:a,:b],[:c,:d],[:e,:f]]
23
+ assert_equal({:a=>:b, :c=>:d, :e=>:f}, a.to_h)
24
+ end
25
+
26
+ def test_to_h_with_duplicate_keys
27
+ a=[[:a,:b],[:a,:c],[:a,:d]]
28
+ assert_equal({:a=>[:b, :c, :d]}, a.to_h)
29
+ end
30
+
31
+ def test_index_by
32
+ assert_equal({3=>"red",4=>"blue",5=>"green"},RGB.index_by{|x| x.size})
33
+ end
34
+
35
+ def test_hash_by
36
+ assert_equal({3=>"RED",4=>"BLUE",5=>"GREEN"},RGB.hash_by{|x| [x.size,x.upcase]})
37
+ end
38
+
39
+
40
+ ########################################################################
41
+ #
42
+ # map
43
+ #
44
+ ########################################################################
45
+
46
+
47
+ class Mock #:nodoc: all
48
+ attr_accessor :id
49
+
50
+ def initialize(id)
51
+ @id=id
52
+ end
53
+
54
+ def to_a
55
+ [self]
56
+ end
57
+
58
+ end
59
+
60
+
61
+ A = Mock.new('a')
62
+ B = Mock.new('b')
63
+ C = Mock.new('c')
64
+
65
+
66
+ def test_map_id
67
+ assert_equal(['a','b','c'],[A,B,C].map_id)
68
+ end
69
+
70
+ def test_map_to_a
71
+ assert_equal([[123],["456"]],MAPTEST.to_set.map_to_a)
72
+ end
73
+
74
+ def test_map_to_f
75
+ assert_equal([123.0,456.0],MAPTEST.map_to_f)
76
+ end
77
+
78
+ def test_map_to_i
79
+ assert_equal([123,456],MAPTEST.map_to_i)
80
+ end
81
+
82
+ def test_map_to_s
83
+ assert_equal(["123","456"],MAPTEST.map_to_s)
84
+ end
85
+
86
+ def test_map_to_sym
87
+ assert_equal([:a,:b,:c],ITEMS.map_to_sym)
88
+ end
89
+
90
+ def test_map_with_index
91
+ assert_equal(['a0','b1','c2'],ITEMS.map_with_index{|x,i| "#{x}#{i}"})
92
+ end
93
+
94
+
95
+ ########################################################################
96
+ #
97
+ # select
98
+ #
99
+ ########################################################################
100
+
101
+
102
+ def test_select_while
103
+ assert_equal([ ],ITEMS.select_while{|x| x < 'a' },'< a')
104
+ assert_equal(['a' ],ITEMS.select_while{|x| x < 'b' },'< b')
105
+ assert_equal(['a','b' ],ITEMS.select_while{|x| x < 'c' },'< c')
106
+ assert_equal(['a','b','c'],ITEMS.select_while{|x| x < 'd' },'< d')
107
+ assert_equal(['a','b','c'],ITEMS.select_while{|x| x < 'e' },'< e')
108
+ end
109
+
110
+
111
+ def test_select_until_condition
112
+ assert_equal([ ],ITEMS.select_until{|x| x == 'a' },'a')
113
+ assert_equal(['a' ],ITEMS.select_until{|x| x == 'b' },'b')
114
+ assert_equal(['a','b' ],ITEMS.select_until{|x| x == 'c' },'c')
115
+ assert_equal(['a','b','c'],ITEMS.select_until{|x| x == 'd' },'d')
116
+ assert_equal(['a','b','c'],ITEMS.select_until{|x| x == 'e' },'e')
117
+ end
118
+
119
+
120
+ def test_select_with_index
121
+ assert_equal([ ],ITEMS.select_with_index{|x,i| i < 0 },'i < 0')
122
+ assert_equal(['a' ],ITEMS.select_with_index{|x,i| i < 1 },'i < 1')
123
+ assert_equal(['a','b' ],ITEMS.select_with_index{|x,i| i < 2 },'i < 2')
124
+ assert_equal(['a','b','c'],ITEMS.select_with_index{|x,i| i < 3 },'i < 3')
125
+ assert_equal(['a','b','c'],ITEMS.select_with_index{|x,i| i < 4 },'i < 4')
126
+ end
127
+
128
+
129
+ ########################################################################
130
+ #
131
+ # bisect
132
+ #
133
+ ########################################################################
134
+
135
+ def test_bisect
136
+ assert_equal([[ ],['a','b','c']],ITEMS.bisect{|x| x < 'a' },'< a')
137
+ assert_equal([['a' ],[ 'b','c']],ITEMS.bisect{|x| x < 'b' },'< b')
138
+ assert_equal([['a','b' ],[ 'c']],ITEMS.bisect{|x| x < 'c' },'< c')
139
+ assert_equal([['a','b','c'],[ ]],ITEMS.bisect{|x| x < 'd' },'< d')
140
+ end
141
+
142
+
143
+ ########################################################################
144
+ #
145
+ # mutex?
146
+ #
147
+ ########################################################################
148
+
149
+ def test_mutex
150
+ assert_equal(true, ITEMS.mutex?{|x| x < 'a'})
151
+ assert_equal(true, ITEMS.mutex?{|x| x < 'b'})
152
+ assert_equal(false, ITEMS.mutex?{|x| x < 'c'})
153
+ assert_equal(false, ITEMS.mutex?{|x| x < 'd'})
154
+ end
155
+
156
+
157
+ ########################################################################
158
+ #
159
+ # nitems
160
+ #
161
+ ########################################################################
162
+
163
+ def test_nitems?
164
+ assert_equal(true, ITEMS.nitems?(0){|x| x < 'a'})
165
+ assert_equal(false, ITEMS.nitems?(1){|x| x < 'a'})
166
+ assert_equal(false, ITEMS.nitems?(2){|x| x < 'a'})
167
+ assert_equal(false, ITEMS.nitems?(0){|x| x < 'b'})
168
+ assert_equal(true, ITEMS.nitems?(1){|x| x < 'b'})
169
+ assert_equal(false, ITEMS.nitems?(2){|x| x < 'b'})
170
+ assert_equal(false, ITEMS.nitems?(0){|x| x < 'c'})
171
+ assert_equal(false, ITEMS.nitems?(1){|x| x < 'c'})
172
+ assert_equal(true, ITEMS.nitems?(2){|x| x < 'c'})
173
+ end
174
+
175
+
176
+ def test_nitems_while
177
+ assert_equal(0,ITEMS.nitems_while{|x| x < 'a' },'< a')
178
+ assert_equal(1,ITEMS.nitems_while{|x| x < 'b' },'< b')
179
+ assert_equal(2,ITEMS.nitems_while{|x| x < 'c' },'< c')
180
+ assert_equal(3,ITEMS.nitems_while{|x| x < 'd' },'< d')
181
+ assert_equal(3,ITEMS.nitems_while{|x| x < 'e' },'< e')
182
+ end
183
+
184
+
185
+ def test_nitems_until
186
+ assert_equal(0,ITEMS.nitems_until{|x| x == 'a' },'a')
187
+ assert_equal(1,ITEMS.nitems_until{|x| x == 'b' },'b')
188
+ assert_equal(2,ITEMS.nitems_until{|x| x == 'c' },'c')
189
+ assert_equal(3,ITEMS.nitems_until{|x| x == 'd' },'d')
190
+ assert_equal(3,ITEMS.nitems_until{|x| x == 'e' },'e')
191
+ end
192
+
193
+
194
+ def test_nitems_with_index
195
+ assert_equal(0,ITEMS.nitems_with_index{|x,i| i < 0 },'i < 0')
196
+ assert_equal(1,ITEMS.nitems_with_index{|x,i| i < 1 },'i < 1')
197
+ assert_equal(2,ITEMS.nitems_with_index{|x,i| i < 2 },'i < 2')
198
+ assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 3 },'i < 3')
199
+ assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 4 },'i < 4')
200
+ end
201
+
202
+
203
+ ########################################################################
204
+ #
205
+ # strings
206
+ #
207
+ ########################################################################
208
+
209
+
210
+ def test_join_0
211
+ a='a'..'c'
212
+ assert_equal("abc",a.join,"join()")
213
+ end
214
+
215
+ def test_join_1
216
+ a='a'..'c'
217
+ assert_equal("a+b+c",a.join('+'),"join('+')")
218
+ end
219
+
220
+ def test_join_2
221
+ a='a'..'c'
222
+ assert_equal("+a-+b-+c-",a.join("+","-"),"join('+','-')")
223
+ end
224
+
225
+
226
+ ########################################################################
227
+ #
228
+ # set math
229
+ #
230
+ ########################################################################
231
+
232
+ def test_intersect_true
233
+ assert_equal(true,['a','b'].intersect?(['b','c']))
234
+ end
235
+
236
+ def test_intersect_true_with_same
237
+ assert_equal(true,['a','b'].intersect?(['a','b']))
238
+ end
239
+
240
+ def test_intersect_false
241
+ assert_equal(false,['a','b'].intersect?(['c','d']))
242
+ end
243
+
244
+ def test_intersect_false_with_none
245
+ assert_equal(false,['a','b','c'].intersect?([]))
246
+ end
247
+
248
+ CARTESIAN_PRODUCT_EXPECT=[["a", "d", "g"],
249
+ ["a", "d", "h"],
250
+ ["a", "d", "i"],
251
+ ["a", "e", "g"],
252
+ ["a", "e", "h"],
253
+ ["a", "e", "i"],
254
+ ["a", "f", "g"],
255
+ ["a", "f", "h"],
256
+ ["a", "f", "i"],
257
+ ["b", "d", "g"],
258
+ ["b", "d", "h"],
259
+ ["b", "d", "i"],
260
+ ["b", "e", "g"],
261
+ ["b", "e", "h"],
262
+ ["b", "e", "i"],
263
+ ["b", "f", "g"],
264
+ ["b", "f", "h"],
265
+ ["b", "f", "i"],
266
+ ["c", "d", "g"],
267
+ ["c", "d", "h"],
268
+ ["c", "d", "i"],
269
+ ["c", "e", "g"],
270
+ ["c", "e", "h"],
271
+ ["c", "e", "i"],
272
+ ["c", "f", "g"],
273
+ ["c", "f", "h"],
274
+ ["c", "f", "i"]]
275
+
276
+ def test_cartesian_product_class_method
277
+ a1=['a','b','c']
278
+ a2=['d','e','f']
279
+ a3=['g','h','i']
280
+ actual=Enumerable.cartesian_product(a1,a2,a3)
281
+ assert_equal(CARTESIAN_PRODUCT_EXPECT,actual,'class method')
282
+ end
283
+
284
+ def test_cartesian_product_instance_method
285
+ a1=['a','b','c']
286
+ a2=['d','e','f']
287
+ a3=['g','h','i']
288
+ actual=a1.cartesian_product(a2,a3)
289
+ assert_equal(CARTESIAN_PRODUCT_EXPECT,actual,'instance method')
290
+ end
291
+
292
+ def test_power_set
293
+ a=['a','b','c']
294
+ expect=[[],['a'],['a','b'],['a','b','c'],['a','c'],['b'],['b','c'],['c']]
295
+ actual=a.power_set.sort
296
+ assert_equal(expect,actual)
297
+ end
298
+
299
+ end
300
+
301
+
302
+
303
+