sixarm_ruby_ramp 2.1.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class FileTestCase < Minitest::Test
7
+
8
+ def test_load_dir_files
9
+ filename='/a/b/c.d'
10
+ dirname=File.dirname(filename)
11
+ expect=File.join(dirname,'x','y','z')
12
+ actual=File.joindir(filename,'x','y','z')
13
+ assert_equal(expect,actual,"filename:#{filename} dirname:#{dirname}")
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class FixnumTest < Minitest::Test
7
+
8
+ def test_even_with_true
9
+ assert(2.even?)
10
+ end
11
+
12
+ def test_even_with_false
13
+ assert(!3.even?)
14
+ end
15
+
16
+ def test_odd_with_true
17
+ assert(3.odd?)
18
+ end
19
+
20
+ def test_odd_with_false
21
+ assert(!2.odd?)
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,209 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class HashTest < Minitest::Test
6
+
7
+
8
+ def test_size_true
9
+ h = {'a'=>'b'}
10
+ assert(h.size?)
11
+ end
12
+
13
+
14
+ def test_size_false
15
+ h = {}
16
+ assert(!h.size?)
17
+ end
18
+
19
+
20
+ def test_sort_by_keys
21
+ h = {'c' => 'z', 'b' => 'y', 'a' => 'x'}
22
+ assert_equal({'a' => 'x', 'b' => 'y', 'c' => 'z'}, h.sort_by_keys)
23
+ end
24
+
25
+
26
+ def test_each_sort
27
+ out = []
28
+ h = {'c' => 'z', 'b' => 'y', 'a' => 'x'}
29
+ h.each_sort{|key,val| out << key.upcase; out << val.upcase}
30
+ assert_equal(['A','X','B','Y','C','Z'], out)
31
+ end
32
+
33
+
34
+ def test_each_sort_with_empty
35
+ out = []
36
+ h = {}
37
+ h.each_sort{|key,val| out << key.upcase; out << val.upcase}
38
+ assert_equal([], out)
39
+ end
40
+
41
+
42
+ def test_each_key_bang
43
+ actual = { "a" => "b", "c" => "d" }
44
+ expect = { "A" => "b", "C" => "d" }
45
+ actual.each_key! {|key| key.upcase }
46
+ assert_equal(expect,actual)
47
+ end
48
+
49
+
50
+ def test_each_key_bang_with_empty
51
+ actual = {}
52
+ expect = {}
53
+ actual.each_key! {|key| key.upcase }
54
+ assert_equal(expect,actual)
55
+ end
56
+
57
+
58
+ def test_each_pair_bang
59
+ actual = { "a" => "b", "c" => "d" }
60
+ expect = { "A" => "B", "C" => "D" }
61
+ actual.each_pair! {|key,value| [key.upcase, value.upcase] }
62
+ assert_equal(expect,actual)
63
+ end
64
+
65
+
66
+ def test_each_pair_bang_with_empty
67
+ actual = {}
68
+ expect = {}
69
+ actual.each_pair! {|key,value| [key.upcase, value.upcase] }
70
+ assert_equal(expect,actual)
71
+ end
72
+
73
+
74
+ def test_each_pair_bang_with_same_key_different_value
75
+ actual = { "a" => "b", "c" => "d" }
76
+ expect = { "a" => "B", "c" => "D" }
77
+ actual.each_pair! {|key,value| [key, value.upcase] }
78
+ assert_equal(expect,actual)
79
+ end
80
+
81
+
82
+ def test_each_pair_bang_with_same_key_same_value
83
+ actual = { "a" => "b", "c" => "d" }
84
+ expect = { "a" => "b", "c" => "d" }
85
+ actual.each_pair! {|key,value| [key, value] }
86
+ assert_equal(expect,actual)
87
+ end
88
+
89
+
90
+ def test_each_value_bang
91
+ actual = { "a" => "b", "c" => "d" }
92
+ expect = { "a" => "B", "c" => "D" }
93
+ actual.each_value! {|value| value.upcase }
94
+ assert_equal(expect,actual)
95
+ end
96
+
97
+
98
+ def test_each_value_bang_with_empty
99
+ actual = {}
100
+ expect = {}
101
+ actual.each_value! {|value| value.upcase }
102
+ assert_equal(expect,actual)
103
+ end
104
+
105
+
106
+ def test_map_pair
107
+ h = {"a"=>"b", "c"=>"d", "e"=>"f" }
108
+ expect=["ab","cd","ef"]
109
+ actual=h.map_pair{|key,value| key+value }.sort
110
+ assert_equal(expect,actual,h.inspect)
111
+ end
112
+
113
+
114
+ def test_map_pair_with_empty
115
+ h = {}
116
+ expect=[]
117
+ actual=h.map_pair{|key,value| key+value }.sort
118
+ assert_equal(expect,actual,h.inspect)
119
+ end
120
+
121
+
122
+ def pivotable
123
+ h=Hash.new
124
+ h['a']=Hash.new
125
+ h['b']=Hash.new
126
+ h['c']=Hash.new
127
+ h['a']['x']='m'
128
+ h['a']['y']='n'
129
+ h['a']['z']='o'
130
+ h['b']['x']='p'
131
+ h['b']['y']='q'
132
+ h['b']['z']='r'
133
+ h['c']['x']='s'
134
+ h['c']['y']='t'
135
+ h['c']['z']='u'
136
+ return h
137
+ end
138
+
139
+
140
+ def test_pivot_vals
141
+ p=pivotable.pivot(:vals)
142
+ assert_equal(['x','y','z'], p.keys.sort)
143
+ assert_equal(['m','p','s'], p['x'].sort)
144
+ assert_equal(['n','q','t'], p['y'].sort)
145
+ assert_equal(['o','r','u'], p['z'].sort)
146
+ end
147
+
148
+
149
+ def test_pivot_vals_with_block
150
+ p=pivotable.pivot(:vals){|items| items.sort.join }
151
+ assert_equal(['x','y','z'], p.keys.sort)
152
+ assert_equal('mps', p['x'])
153
+ assert_equal('nqt', p['y'])
154
+ assert_equal('oru', p['z'])
155
+ end
156
+
157
+
158
+ def test_pivot_keys
159
+ p=pivotable.pivot(:keys)
160
+ assert_equal(['a','b','c'], p.keys.sort)
161
+ assert_equal(['m','n','o'], p['a'].sort)
162
+ assert_equal(['p','q','r'], p['b'].sort)
163
+ assert_equal(['s','t','u'], p['c'].sort)
164
+ end
165
+
166
+
167
+ def test_pivot_keys_with_block
168
+ p=pivotable.pivot(:keys){|items| items.sort.join }
169
+ assert_equal(['a','b','c'], p.keys.sort)
170
+ assert_equal('mno', p['a'])
171
+ assert_equal('pqr', p['b'])
172
+ assert_equal('stu', p['c'])
173
+ end
174
+
175
+
176
+ def test_pivot_direction_up_with_true
177
+ Hash.publicize_methods do
178
+ assert({}.pivot_direction_up?('key'))
179
+ assert({}.pivot_direction_up?('keys'))
180
+ assert({}.pivot_direction_up?('up'))
181
+ assert({}.pivot_direction_up?('left'))
182
+ assert({}.pivot_direction_up?('out'))
183
+ end
184
+ end
185
+
186
+
187
+ def test_pivot_direction_up_with_false
188
+ Hash.publicize_methods do
189
+ assert(!{}.pivot_direction_up?('val'))
190
+ assert(!{}.pivot_direction_up?('vals'))
191
+ assert(!{}.pivot_direction_up?('down'))
192
+ assert(!{}.pivot_direction_up?('right'))
193
+ assert(!{}.pivot_direction_up?('in'))
194
+ end
195
+ end
196
+
197
+
198
+ def test_pivot_direction_up_with_invalid
199
+ Hash.publicize_methods do
200
+ assert_raises(ArgumentError){ {}.pivot_direction_up?('nonsense') }
201
+ end
202
+ end
203
+
204
+
205
+ end
206
+
207
+
208
+
209
+
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+
6
+ class IntegerTest < Minitest::Test
7
+
8
+ def test_maps
9
+ expect=['a','a','a']
10
+ actual=3.maps{'a'}
11
+ assert_equal(expect,actual)
12
+ end
13
+
14
+ def test_maps_with_index
15
+ expect=[0,1,2]
16
+ actual=3.maps{|i| i}
17
+ assert_equal(expect,actual)
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class IOTest < Minitest::Test
6
+
7
+ def test_load_dir_files
8
+ dirpath=File.join(__dir__,'io_test*')
9
+ expect=[File.join(__dir__,'io_test.rb'),File.join(__dir__,'io_test.txt')]
10
+ actual=Dir[dirpath].sort
11
+ assert_equal(expect,actual,"Dir[#{dirpath}] expects test data files")
12
+ end
13
+
14
+ def test_readrow
15
+ filename=Dir[File.join(__dir__,'io_test.txt')].first
16
+ f=File.open(filename)
17
+ assert_equal(["A1","B1","C1"],f.readrow(:row=>"=",:col=>"-"))
18
+ assert_equal(["A2","B2","C2"],f.readrow(:row=>"=",:col=>"-"))
19
+ assert_equal(["A3","B3","C3"],f.readrow(:row=>"=",:col=>"-"))
20
+ end
21
+
22
+ def test_readrows
23
+ filename=Dir[File.join(__dir__,'io_test.txt')].first
24
+ expect=[["A1","B1","C1"],["A2","B2","C2"],["A3","B3","C3"]]
25
+ actual=IO.readrows(filename,:row=>"=",:col=>"-")
26
+ assert_equal(expect,actual)
27
+ end
28
+
29
+ end
30
+
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class KernelTest < Minitest::Test
6
+
7
+ class TestMyMethodName
8
+ def a
9
+ my_method_name
10
+ end
11
+ end
12
+
13
+ class TestCallerMethodNameWithNoOps
14
+ def a
15
+ caller_method_name()
16
+ end
17
+ end
18
+
19
+ class TestCallerMethodNameWithIndex0
20
+ def a
21
+ caller_method_name(0)
22
+ end
23
+ end
24
+
25
+ class TestCallerMethodNameWithIndex1
26
+ def a
27
+ b
28
+ end
29
+ def b
30
+ caller_method_name(1)
31
+ end
32
+ end
33
+
34
+ def test_my_method_name
35
+ assert_equal('a', TestMyMethodName.new.a)
36
+ end
37
+
38
+ def test_caller_method_name_with_no_ops
39
+ assert_equal('a', TestCallerMethodNameWithNoOps.new.a)
40
+ end
41
+
42
+ def test_caller_method_name_with_index_0
43
+ assert_equal('a', TestCallerMethodNameWithIndex0.new.a)
44
+ end
45
+
46
+ def test_caller_method_name_with_index_1
47
+ assert_equal('a', TestCallerMethodNameWithIndex1.new.a)
48
+ end
49
+
50
+ def test_pp_s
51
+ assert_equal(":foo\n",pp_s(:foo))
52
+ end
53
+
54
+ end
55
+
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class MathTest < Minitest::Test
6
+
7
+ def test_ln
8
+ assert_equal(0.0,Math.ln(1.0))
9
+ assert_equal(1.0,Math.ln(Math.exp(1.0)))
10
+ end
11
+
12
+ def test_logn
13
+ assert_equal(1.0,Math.logn(3,3),'log of 3 base 3')
14
+ assert_equal(2.0,Math.logn(9,3),'log of 9 base 3')
15
+ assert_equal(3.0,Math.logn(27,3),'log of 27 base 3')
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class NilTest < Minitest::Test
6
+
7
+ def test_blank
8
+ assert_equal(true,nil.blank?)
9
+ end
10
+
11
+ def test_size
12
+ assert_equal(false,nil.size?)
13
+ end
14
+
15
+ end
16
+
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'sixarm_ruby_ramp'
4
+
5
+ class NumericTest < Minitest::Test
6
+
7
+
8
+ def test_if_with_true
9
+ assert_equal(5,5.if(true))
10
+ end
11
+
12
+
13
+ def test_if_with_false
14
+ assert_equal(0,5.if(false))
15
+ end
16
+
17
+
18
+ def test_unless_with_true
19
+ assert_equal(0,5.unless(true))
20
+ end
21
+
22
+
23
+ def test_unless_with_false
24
+ assert_equal(5,5.unless(false))
25
+ end
26
+
27
+
28
+ def test_percent_with_ndigits_default
29
+ assert_equal(12, (0.1234).percent)
30
+ end
31
+
32
+
33
+ def test_percent_with_ndigits_zero
34
+ assert_equal(12, (0.1234).percent(0))
35
+ end
36
+
37
+
38
+ def test_percent_with_ndigits_positive
39
+ assert_equal(12.3, (0.1234).percent(1))
40
+ end
41
+
42
+
43
+ def test_percent_with_ndigits_negative
44
+ assert_equal(10, (0.1234).percent(-1))
45
+ end
46
+
47
+
48
+ def test_floor_precision
49
+ x = 0.12345
50
+ assert_equal(0.0, x.floor_precision(0))
51
+ assert_equal(0.1, x.floor_precision(1))
52
+ assert_equal(0.12, x.floor_precision(2))
53
+ assert_equal(0.123, x.floor_precision(3))
54
+ end
55
+
56
+
57
+ end