ruby-spark 1.1.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +47 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +252 -0
  7. data/Rakefile +35 -0
  8. data/TODO.md +6 -0
  9. data/benchmark/aggregate.rb +33 -0
  10. data/benchmark/bisect.rb +88 -0
  11. data/benchmark/comparison/prepare.sh +18 -0
  12. data/benchmark/comparison/python.py +156 -0
  13. data/benchmark/comparison/r.r +69 -0
  14. data/benchmark/comparison/ruby.rb +167 -0
  15. data/benchmark/comparison/run-all.sh +160 -0
  16. data/benchmark/comparison/scala.scala +181 -0
  17. data/benchmark/custom_marshal.rb +94 -0
  18. data/benchmark/digest.rb +150 -0
  19. data/benchmark/enumerator.rb +88 -0
  20. data/benchmark/serializer.rb +82 -0
  21. data/benchmark/sort.rb +43 -0
  22. data/benchmark/sort2.rb +164 -0
  23. data/benchmark/take.rb +28 -0
  24. data/bin/ruby-spark +8 -0
  25. data/example/pi.rb +28 -0
  26. data/example/website_search.rb +83 -0
  27. data/ext/ruby_c/extconf.rb +3 -0
  28. data/ext/ruby_c/murmur.c +158 -0
  29. data/ext/ruby_c/murmur.h +9 -0
  30. data/ext/ruby_c/ruby-spark.c +18 -0
  31. data/ext/ruby_java/Digest.java +36 -0
  32. data/ext/ruby_java/Murmur2.java +98 -0
  33. data/ext/ruby_java/RubySparkExtService.java +28 -0
  34. data/ext/ruby_java/extconf.rb +3 -0
  35. data/ext/spark/build.sbt +73 -0
  36. data/ext/spark/project/plugins.sbt +9 -0
  37. data/ext/spark/sbt/sbt +34 -0
  38. data/ext/spark/src/main/scala/Exec.scala +91 -0
  39. data/ext/spark/src/main/scala/MLLibAPI.scala +4 -0
  40. data/ext/spark/src/main/scala/Marshal.scala +52 -0
  41. data/ext/spark/src/main/scala/MarshalDump.scala +113 -0
  42. data/ext/spark/src/main/scala/MarshalLoad.scala +220 -0
  43. data/ext/spark/src/main/scala/RubyAccumulatorParam.scala +69 -0
  44. data/ext/spark/src/main/scala/RubyBroadcast.scala +13 -0
  45. data/ext/spark/src/main/scala/RubyConstant.scala +13 -0
  46. data/ext/spark/src/main/scala/RubyMLLibAPI.scala +55 -0
  47. data/ext/spark/src/main/scala/RubyMLLibUtilAPI.scala +21 -0
  48. data/ext/spark/src/main/scala/RubyPage.scala +34 -0
  49. data/ext/spark/src/main/scala/RubyRDD.scala +392 -0
  50. data/ext/spark/src/main/scala/RubySerializer.scala +14 -0
  51. data/ext/spark/src/main/scala/RubyTab.scala +11 -0
  52. data/ext/spark/src/main/scala/RubyUtils.scala +15 -0
  53. data/ext/spark/src/main/scala/RubyWorker.scala +257 -0
  54. data/ext/spark/src/test/scala/MarshalSpec.scala +84 -0
  55. data/lib/ruby-spark.rb +1 -0
  56. data/lib/spark.rb +198 -0
  57. data/lib/spark/accumulator.rb +260 -0
  58. data/lib/spark/broadcast.rb +98 -0
  59. data/lib/spark/build.rb +43 -0
  60. data/lib/spark/cli.rb +169 -0
  61. data/lib/spark/command.rb +86 -0
  62. data/lib/spark/command/base.rb +158 -0
  63. data/lib/spark/command/basic.rb +345 -0
  64. data/lib/spark/command/pair.rb +124 -0
  65. data/lib/spark/command/sort.rb +51 -0
  66. data/lib/spark/command/statistic.rb +144 -0
  67. data/lib/spark/command_builder.rb +141 -0
  68. data/lib/spark/command_validator.rb +34 -0
  69. data/lib/spark/config.rb +238 -0
  70. data/lib/spark/constant.rb +14 -0
  71. data/lib/spark/context.rb +322 -0
  72. data/lib/spark/error.rb +50 -0
  73. data/lib/spark/ext/hash.rb +41 -0
  74. data/lib/spark/ext/integer.rb +25 -0
  75. data/lib/spark/ext/io.rb +67 -0
  76. data/lib/spark/ext/ip_socket.rb +29 -0
  77. data/lib/spark/ext/module.rb +58 -0
  78. data/lib/spark/ext/object.rb +24 -0
  79. data/lib/spark/ext/string.rb +24 -0
  80. data/lib/spark/helper.rb +10 -0
  81. data/lib/spark/helper/logger.rb +40 -0
  82. data/lib/spark/helper/parser.rb +85 -0
  83. data/lib/spark/helper/serialize.rb +71 -0
  84. data/lib/spark/helper/statistic.rb +93 -0
  85. data/lib/spark/helper/system.rb +42 -0
  86. data/lib/spark/java_bridge.rb +19 -0
  87. data/lib/spark/java_bridge/base.rb +203 -0
  88. data/lib/spark/java_bridge/jruby.rb +23 -0
  89. data/lib/spark/java_bridge/rjb.rb +41 -0
  90. data/lib/spark/logger.rb +76 -0
  91. data/lib/spark/mllib.rb +100 -0
  92. data/lib/spark/mllib/classification/common.rb +31 -0
  93. data/lib/spark/mllib/classification/logistic_regression.rb +223 -0
  94. data/lib/spark/mllib/classification/naive_bayes.rb +97 -0
  95. data/lib/spark/mllib/classification/svm.rb +135 -0
  96. data/lib/spark/mllib/clustering/gaussian_mixture.rb +82 -0
  97. data/lib/spark/mllib/clustering/kmeans.rb +118 -0
  98. data/lib/spark/mllib/matrix.rb +120 -0
  99. data/lib/spark/mllib/regression/common.rb +73 -0
  100. data/lib/spark/mllib/regression/labeled_point.rb +41 -0
  101. data/lib/spark/mllib/regression/lasso.rb +100 -0
  102. data/lib/spark/mllib/regression/linear.rb +124 -0
  103. data/lib/spark/mllib/regression/ridge.rb +97 -0
  104. data/lib/spark/mllib/ruby_matrix/matrix_adapter.rb +53 -0
  105. data/lib/spark/mllib/ruby_matrix/vector_adapter.rb +57 -0
  106. data/lib/spark/mllib/stat/distribution.rb +12 -0
  107. data/lib/spark/mllib/vector.rb +185 -0
  108. data/lib/spark/rdd.rb +1377 -0
  109. data/lib/spark/sampler.rb +92 -0
  110. data/lib/spark/serializer.rb +79 -0
  111. data/lib/spark/serializer/auto_batched.rb +59 -0
  112. data/lib/spark/serializer/base.rb +63 -0
  113. data/lib/spark/serializer/batched.rb +84 -0
  114. data/lib/spark/serializer/cartesian.rb +13 -0
  115. data/lib/spark/serializer/compressed.rb +27 -0
  116. data/lib/spark/serializer/marshal.rb +17 -0
  117. data/lib/spark/serializer/message_pack.rb +23 -0
  118. data/lib/spark/serializer/oj.rb +23 -0
  119. data/lib/spark/serializer/pair.rb +41 -0
  120. data/lib/spark/serializer/text.rb +25 -0
  121. data/lib/spark/sort.rb +189 -0
  122. data/lib/spark/stat_counter.rb +125 -0
  123. data/lib/spark/storage_level.rb +39 -0
  124. data/lib/spark/version.rb +3 -0
  125. data/lib/spark/worker/master.rb +144 -0
  126. data/lib/spark/worker/spark_files.rb +15 -0
  127. data/lib/spark/worker/worker.rb +200 -0
  128. data/ruby-spark.gemspec +47 -0
  129. data/spec/generator.rb +37 -0
  130. data/spec/inputs/lorem_300.txt +316 -0
  131. data/spec/inputs/numbers/1.txt +50 -0
  132. data/spec/inputs/numbers/10.txt +50 -0
  133. data/spec/inputs/numbers/11.txt +50 -0
  134. data/spec/inputs/numbers/12.txt +50 -0
  135. data/spec/inputs/numbers/13.txt +50 -0
  136. data/spec/inputs/numbers/14.txt +50 -0
  137. data/spec/inputs/numbers/15.txt +50 -0
  138. data/spec/inputs/numbers/16.txt +50 -0
  139. data/spec/inputs/numbers/17.txt +50 -0
  140. data/spec/inputs/numbers/18.txt +50 -0
  141. data/spec/inputs/numbers/19.txt +50 -0
  142. data/spec/inputs/numbers/2.txt +50 -0
  143. data/spec/inputs/numbers/20.txt +50 -0
  144. data/spec/inputs/numbers/3.txt +50 -0
  145. data/spec/inputs/numbers/4.txt +50 -0
  146. data/spec/inputs/numbers/5.txt +50 -0
  147. data/spec/inputs/numbers/6.txt +50 -0
  148. data/spec/inputs/numbers/7.txt +50 -0
  149. data/spec/inputs/numbers/8.txt +50 -0
  150. data/spec/inputs/numbers/9.txt +50 -0
  151. data/spec/inputs/numbers_0_100.txt +101 -0
  152. data/spec/inputs/numbers_1_100.txt +100 -0
  153. data/spec/lib/collect_spec.rb +42 -0
  154. data/spec/lib/command_spec.rb +68 -0
  155. data/spec/lib/config_spec.rb +64 -0
  156. data/spec/lib/context_spec.rb +165 -0
  157. data/spec/lib/ext_spec.rb +72 -0
  158. data/spec/lib/external_apps_spec.rb +45 -0
  159. data/spec/lib/filter_spec.rb +80 -0
  160. data/spec/lib/flat_map_spec.rb +100 -0
  161. data/spec/lib/group_spec.rb +109 -0
  162. data/spec/lib/helper_spec.rb +19 -0
  163. data/spec/lib/key_spec.rb +41 -0
  164. data/spec/lib/manipulation_spec.rb +122 -0
  165. data/spec/lib/map_partitions_spec.rb +87 -0
  166. data/spec/lib/map_spec.rb +91 -0
  167. data/spec/lib/mllib/classification_spec.rb +54 -0
  168. data/spec/lib/mllib/clustering_spec.rb +35 -0
  169. data/spec/lib/mllib/matrix_spec.rb +32 -0
  170. data/spec/lib/mllib/regression_spec.rb +116 -0
  171. data/spec/lib/mllib/vector_spec.rb +77 -0
  172. data/spec/lib/reduce_by_key_spec.rb +118 -0
  173. data/spec/lib/reduce_spec.rb +131 -0
  174. data/spec/lib/sample_spec.rb +46 -0
  175. data/spec/lib/serializer_spec.rb +88 -0
  176. data/spec/lib/sort_spec.rb +58 -0
  177. data/spec/lib/statistic_spec.rb +170 -0
  178. data/spec/lib/whole_text_files_spec.rb +33 -0
  179. data/spec/spec_helper.rb +38 -0
  180. metadata +389 -0
@@ -0,0 +1,100 @@
1
+ 1
2
+ 2
3
+ 3
4
+ 4
5
+ 5
6
+ 6
7
+ 7
8
+ 8
9
+ 9
10
+ 10
11
+ 11
12
+ 12
13
+ 13
14
+ 14
15
+ 15
16
+ 16
17
+ 17
18
+ 18
19
+ 19
20
+ 20
21
+ 21
22
+ 22
23
+ 23
24
+ 24
25
+ 25
26
+ 26
27
+ 27
28
+ 28
29
+ 29
30
+ 30
31
+ 31
32
+ 32
33
+ 33
34
+ 34
35
+ 35
36
+ 36
37
+ 37
38
+ 38
39
+ 39
40
+ 40
41
+ 41
42
+ 42
43
+ 43
44
+ 44
45
+ 45
46
+ 46
47
+ 47
48
+ 48
49
+ 49
50
+ 50
51
+ 51
52
+ 52
53
+ 53
54
+ 54
55
+ 55
56
+ 56
57
+ 57
58
+ 58
59
+ 59
60
+ 60
61
+ 61
62
+ 62
63
+ 63
64
+ 64
65
+ 65
66
+ 66
67
+ 67
68
+ 68
69
+ 69
70
+ 70
71
+ 71
72
+ 72
73
+ 73
74
+ 74
75
+ 75
76
+ 76
77
+ 77
78
+ 78
79
+ 79
80
+ 80
81
+ 81
82
+ 82
83
+ 83
84
+ 84
85
+ 85
86
+ 86
87
+ 87
88
+ 88
89
+ 89
90
+ 90
91
+ 91
92
+ 92
93
+ 93
94
+ 94
95
+ 95
96
+ 96
97
+ 97
98
+ 98
99
+ 99
100
+ 100
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ RSpec::describe Spark::RDD do
4
+
5
+ let(:mapping) { lambda{|x| [x, 1]} }
6
+ let(:numbers) { Generator.numbers }
7
+
8
+ it ".collect_as_hash" do
9
+ rdd = $sc.parallelize(numbers)
10
+ rdd = rdd.map(mapping)
11
+
12
+ expect(rdd.collect_as_hash).to eql(Hash[numbers.map(&mapping)])
13
+ end
14
+
15
+ context ".take" do
16
+ let(:size) { 1000 }
17
+ let(:numbers) { Generator.numbers(size) }
18
+ let(:rdd) { $sc.parallelize(numbers) }
19
+
20
+ it "nothing" do
21
+ expect(rdd.take(0)).to eql([])
22
+ end
23
+
24
+ it "first" do
25
+ expect(rdd.first).to eql(numbers.first)
26
+ end
27
+
28
+ it "less than limit" do
29
+ _size = size / 2
30
+ expect(rdd.take(_size)).to eql(numbers.take(_size))
31
+ end
32
+
33
+ it "all" do
34
+ expect(rdd.take(size)).to eql(numbers)
35
+ end
36
+
37
+ it "more than limit" do
38
+ expect(rdd.take(size*2)).to eql(numbers)
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ def to_s_method(x)
4
+ x.to_s
5
+ end
6
+
7
+ RSpec::describe Spark::CommandBuilder do
8
+ let(:numbers) { Generator.numbers }
9
+ let(:rdd) { $sc.parallelize(numbers, 1) }
10
+
11
+ context '.serialize_function' do
12
+ let(:result) { numbers.map(&:to_s) }
13
+
14
+ it 'string' do
15
+ expect(rdd.map('lambda{|x| x.to_s}').collect).to eql(result)
16
+ end
17
+
18
+ it 'symbol' do
19
+ expect(rdd.map(:to_s).collect).to eql(result)
20
+ end
21
+
22
+ it 'lambda' do
23
+ expect(rdd.map(lambda{|x| x.to_s}).collect).to eql(result)
24
+ end
25
+
26
+ it 'method' do
27
+ expect(rdd.map(method(:to_s_method)).collect).to eql(result)
28
+ end
29
+ end
30
+
31
+ context '.bind' do
32
+ it 'number' do
33
+ number = rand(0..10000000)
34
+ rdd2 = rdd.map(lambda{|x| x * number}).bind(number: number)
35
+
36
+ expect(rdd2.collect).to eq(numbers.map{|x| x * number})
37
+ end
38
+
39
+ it 'open struct' do
40
+ require 'ostruct'
41
+
42
+ struct = OpenStruct.new
43
+ struct.number = 3
44
+ struct.string = '3'
45
+ struct.array = [1, 2, 3]
46
+
47
+ func = lambda{|item|
48
+ item * struct.number + struct.string.to_i + struct.array[0]
49
+ }
50
+
51
+ rdd2 = rdd.add_library('ostruct')
52
+ rdd2 = rdd2.map(func)
53
+ rdd2 = rdd2.bind(struct: struct)
54
+
55
+ expect(rdd2.collect).to eq(numbers.map(&func))
56
+ end
57
+
58
+ it 'different naming' do
59
+ array = [1, 2, 3]
60
+
61
+ rdd2 = rdd.map(lambda{|_| my_array.size})
62
+ rdd2 = rdd2.bind(my_array: array)
63
+
64
+ expect(rdd2.sum).to eq(numbers.size * array.size)
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ RSpec::describe Spark::Config do
4
+
5
+ before(:context) do
6
+ Spark.stop
7
+ end
8
+
9
+ after(:context) do
10
+ spark_start
11
+ end
12
+
13
+ it "should be stopped" do
14
+ expect(Spark.started?).to be_falsy
15
+ end
16
+
17
+ context "new config" do
18
+
19
+ let(:configuration) do
20
+ {
21
+ "test.test1" => "test1",
22
+ "test.test2" => "test2",
23
+ "test.test3" => "test3"
24
+ }
25
+ end
26
+
27
+ before(:each) do
28
+ Spark.clear_config
29
+ end
30
+
31
+ it "throught methods" do
32
+ configuration.each do |key, value|
33
+ Spark.config.set(key, value)
34
+ end
35
+
36
+ configuration.each do |key, value|
37
+ expect(Spark.config.get(key)).to eql(value)
38
+ end
39
+ end
40
+
41
+ it "throught hash style" do
42
+ configuration.each do |key, value|
43
+ Spark.config[key] = value
44
+ end
45
+
46
+ configuration.each do |key, value|
47
+ expect(Spark.config[key]).to eql(value)
48
+ end
49
+ end
50
+
51
+ it "throught dsl" do
52
+ configuration.each do |key, value|
53
+ Spark.config {
54
+ set key, value
55
+ }
56
+ end
57
+
58
+ configuration.each do |key, value|
59
+ expect(Spark.config[key]).to eql(value)
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Spark::Context do
4
+
5
+ it '.run_job' do
6
+ workers = 5
7
+ numbers = (0...100).to_a
8
+ func = lambda{|part| part.size}
9
+
10
+ ser = Spark::Serializer.build { __batched__(__marshal__, 1) }
11
+
12
+ rdd = $sc.parallelize(numbers, workers, ser)
13
+
14
+ rdd_result = $sc.run_job(rdd, func)
15
+ result = numbers.each_slice(numbers.size/workers).map(&func)
16
+ expect(rdd_result).to eql(result)
17
+
18
+ parts = [0, 2]
19
+ func = lambda{|part| part.to_s}
20
+
21
+ rdd_result = $sc.run_job(rdd, func, parts)
22
+ result = []
23
+ sliced_numbers = numbers.each_slice(numbers.size/workers).to_a
24
+ parts.each do |part|
25
+ result << func.call(sliced_numbers[part])
26
+ end
27
+
28
+ expect(rdd_result).to eql(result)
29
+ end
30
+
31
+ it '.broadcast' do
32
+ workers = rand(1..5)
33
+
34
+ values1 = [1,2,3]
35
+ values2 = [4,5,6]
36
+
37
+ broadcast1 = $sc.broadcast(values1)
38
+ broadcast2 = $sc.broadcast(values2)
39
+
40
+ rdd = $sc.parallelize(0..5, workers)
41
+ rdd = rdd.bind(broadcast1: broadcast1, broadcast2: broadcast2)
42
+ rdd = rdd.map_partitions(lambda{|_| broadcast1.value + broadcast2.value })
43
+
44
+ expect(rdd.sum).to eql(
45
+ (values1 + values2).reduce(:+) * workers
46
+ )
47
+ end
48
+
49
+ context '.accumulator' do
50
+ it 'test' do
51
+ accum1 = $sc.accumulator(0,)
52
+ accum2 = $sc.accumulator(1, :*, 1)
53
+ accum3 = $sc.accumulator(0, lambda{|max, val| val > max ? val : max})
54
+
55
+ accum1 += 1
56
+
57
+ accum2.add(2)
58
+ accum2.add(2)
59
+ accum2.add(2)
60
+
61
+ accum3.add(9)
62
+ accum3.add(6)
63
+ accum3.add(7)
64
+
65
+ expect(accum1.value).to eql(1)
66
+ expect(accum2.value).to eql(8)
67
+ expect(accum3.value).to eql(9)
68
+
69
+ func = Proc.new do |_, index|
70
+ accum1.add(1)
71
+ accum2.add(2)
72
+ accum3.add(index * 10)
73
+ end
74
+
75
+ rdd = $sc.parallelize(0..4, 4)
76
+ rdd = rdd.bind(accum1: accum1, accum2: accum2, accum3: accum3)
77
+ rdd = rdd.map_partitions_with_index(func)
78
+ rdd.collect
79
+
80
+ # http://stackoverflow.com/questions/28560133/ruby-server-java-scala-client-deadlock
81
+ sleep(1)
82
+
83
+ expect(accum1.value).to eql(5)
84
+ expect(accum2.value).to eql(128)
85
+ expect(accum3.value).to eql(30)
86
+ end
87
+
88
+ context 'accum param' do
89
+ it 'symbol' do
90
+ accum1 = $sc.accumulator(1, :+, 0)
91
+ accum2 = $sc.accumulator(5, :-, 3)
92
+ accum3 = $sc.accumulator(1, :*, 1)
93
+ accum4 = $sc.accumulator(1.0, :/, 1.0)
94
+ accum5 = $sc.accumulator(2, :**, 2)
95
+
96
+ func = Proc.new do |_|
97
+ accum1.add(1)
98
+ accum2.add(1)
99
+ accum3.add(2)
100
+ accum4.add(2)
101
+ accum5.add(2)
102
+ end
103
+
104
+ rdd = $sc.parallelize(0..4, 2)
105
+ rdd = rdd.bind(accum1: accum1, accum2: accum2, accum3: accum3, accum4: accum4, accum5: accum5)
106
+ rdd = rdd.map_partitions(func)
107
+ rdd.collect
108
+
109
+ # http://stackoverflow.com/questions/28560133/ruby-server-java-scala-client-deadlock
110
+ sleep(1)
111
+
112
+ expect(accum1.value).to eq(3)
113
+ expect(accum2.value).to eq(1)
114
+ expect(accum3.value).to eq(4)
115
+ expect(accum4.value).to eq(4)
116
+ expect(accum5.value).to eq(65536)
117
+ end
118
+
119
+ it 'proc' do
120
+ accum1 = $sc.accumulator(1, lambda{|mem, val| mem + val}, 0)
121
+ accum2 = $sc.accumulator('a', lambda{|mem, val| mem + val}, '')
122
+ accum3 = $sc.accumulator([], lambda{|mem, val| mem << val}, [])
123
+
124
+ func = Proc.new do |_|
125
+ accum1.add(1)
126
+ accum2.add('a')
127
+ accum3.add(1)
128
+ end
129
+
130
+ rdd = $sc.parallelize(0..4, 2)
131
+ rdd = rdd.bind(accum1: accum1, accum2: accum2, accum3: accum3)
132
+ rdd = rdd.map_partitions(func)
133
+ rdd.collect
134
+
135
+ # http://stackoverflow.com/questions/28560133/ruby-server-java-scala-client-deadlock
136
+ sleep(1)
137
+
138
+ expect(accum1.value).to eq(3)
139
+ expect(accum2.value).to eq('aaa')
140
+ expect(accum3.value).to eq([[1], [1]])
141
+ end
142
+
143
+ it 'string' do
144
+ expect { $sc.accumulator(1, '0') }.to raise_error(Spark::SerializeError)
145
+
146
+ accum = $sc.accumulator(1, 'lambda{|mem, val| mem + val}', 0)
147
+
148
+ func = Proc.new do |_|
149
+ accum.add(1)
150
+ end
151
+
152
+ rdd = $sc.parallelize(0..4, 2)
153
+ rdd = rdd.bind(accum: accum)
154
+ rdd = rdd.map_partitions(func)
155
+ rdd.collect
156
+
157
+ # http://stackoverflow.com/questions/28560133/ruby-server-java-scala-client-deadlock
158
+ sleep(1)
159
+
160
+ expect(accum.value).to eq(3)
161
+ end
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Array do
4
+
5
+ it ".deep_copy" do
6
+ data = ["a", "b", "c"]
7
+ new_data = data.dup
8
+
9
+ data[0] << "a"
10
+
11
+ expect(data).to eql(new_data)
12
+
13
+ new_data = data.deep_copy
14
+
15
+ data[1] << "b"
16
+
17
+ expect(data).to_not eql(new_data)
18
+ end
19
+
20
+ end
21
+
22
+ RSpec.describe Hash do
23
+
24
+ it ".stringify_keys!" do
25
+ data = {
26
+ a: "a",
27
+ b: "b",
28
+ c: "c"
29
+ }
30
+
31
+ data.stringify_keys!
32
+
33
+ expect(data).to eql({
34
+ "a" => "a",
35
+ "b" => "b",
36
+ "c" => "c"
37
+ })
38
+ end
39
+
40
+ end
41
+
42
+ RSpec.describe String do
43
+
44
+ it ".camelize" do
45
+ data = "aaa_bbb_ccc".camelize
46
+ expect(data).to eql("AaaBbbCcc")
47
+ end
48
+
49
+ end
50
+
51
+ RSpec.describe IO do
52
+
53
+ it 'serialize' do
54
+ file = Tempfile.new('serialize')
55
+ file.binmode
56
+
57
+ file.write_int(1)
58
+ file.write_long(2)
59
+ file.write_string("3")
60
+ file.write_data([4])
61
+
62
+ file.rewind
63
+
64
+ expect(file.read_int).to eq(1)
65
+ expect(file.read_long).to eq(2)
66
+ expect(file.read_string).to eq("3")
67
+ expect(file.read_data).to eq([4])
68
+
69
+ file.unlink
70
+ end
71
+
72
+ end