xqsr3 0.8.3

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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +27 -0
  3. data/README.md +26 -0
  4. data/lib/xqsr3/command_line_utilities/map_option_string.rb +137 -0
  5. data/lib/xqsr3/containers/frequency_map.rb +473 -0
  6. data/lib/xqsr3/containers/multi_map.rb +383 -0
  7. data/lib/xqsr3/diagnostics/exception_utilities.rb +216 -0
  8. data/lib/xqsr3/doc_.rb +116 -0
  9. data/lib/xqsr3/extensions/enumerable.rb +4 -0
  10. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +71 -0
  11. data/lib/xqsr3/extensions/enumerable/unique.rb +102 -0
  12. data/lib/xqsr3/extensions/io.rb +3 -0
  13. data/lib/xqsr3/extensions/io/writelines.rb +66 -0
  14. data/lib/xqsr3/extensions/kernel.rb +3 -0
  15. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +68 -0
  16. data/lib/xqsr3/extensions/string.rb +5 -0
  17. data/lib/xqsr3/extensions/string/ends_with.rb +8 -0
  18. data/lib/xqsr3/extensions/string/map_option_string.rb +8 -0
  19. data/lib/xqsr3/extensions/string/starts_with.rb +8 -0
  20. data/lib/xqsr3/extensions/string/to_symbol.rb +8 -0
  21. data/lib/xqsr3/extensions/test/unit.rb +5 -0
  22. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +18 -0
  23. data/lib/xqsr3/extensions/test/unit/assert_not.rb +18 -0
  24. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +18 -0
  25. data/lib/xqsr3/io/writelines.rb +192 -0
  26. data/lib/xqsr3/quality/parameter_checking.rb +343 -0
  27. data/lib/xqsr3/string_utilities/ends_with.rb +134 -0
  28. data/lib/xqsr3/string_utilities/starts_with.rb +127 -0
  29. data/lib/xqsr3/string_utilities/to_symbol.rb +145 -0
  30. data/lib/xqsr3/version.rb +68 -0
  31. data/test/unit/command_line_utilities/tc_map_option_string.rb +39 -0
  32. data/test/unit/command_line_utilities/ts_all.rb +13 -0
  33. data/test/unit/containers/tc_frequency_map.rb +738 -0
  34. data/test/unit/containers/tc_multi_map.rb +640 -0
  35. data/test/unit/containers/ts_all.rb +13 -0
  36. data/test/unit/diagnostics/tc_exception_utilities.rb +221 -0
  37. data/test/unit/diagnostics/ts_all.rb +13 -0
  38. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +36 -0
  39. data/test/unit/extensions/enumerable/tc_unique.rb +47 -0
  40. data/test/unit/extensions/enumerable/ts_all.rb +13 -0
  41. data/test/unit/extensions/io/tc_writelines.rb +110 -0
  42. data/test/unit/extensions/io/ts_all.rb +13 -0
  43. data/test/unit/extensions/kernel/tc_raise_with_options.rb +239 -0
  44. data/test/unit/extensions/kernel/ts_all.rb +13 -0
  45. data/test/unit/extensions/string/tc_ends_with.rb +70 -0
  46. data/test/unit/extensions/string/tc_map_option_string.rb +37 -0
  47. data/test/unit/extensions/string/tc_starts_with.rb +70 -0
  48. data/test/unit/extensions/string/tc_to_symbol.rb +51 -0
  49. data/test/unit/extensions/string/ts_all.rb +13 -0
  50. data/test/unit/extensions/ts_all.rb +13 -0
  51. data/test/unit/io/tc_writelines.rb +200 -0
  52. data/test/unit/io/ts_all.rb +13 -0
  53. data/test/unit/quality/tc_parameter_checking.rb +181 -0
  54. data/test/unit/quality/ts_all.rb +13 -0
  55. data/test/unit/tc_version.rb +37 -0
  56. data/test/unit/ts_all.rb +13 -0
  57. metadata +101 -0
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_file = File.expand_path(__FILE__)
6
+ this_dir = File.expand_path(File.dirname(__FILE__))
7
+
8
+ # all tc_*rb in current directory
9
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
10
+
11
+ # all ts_*rb in immediate sub-directories
12
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
13
+
@@ -0,0 +1,221 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/diagnostics/exception_utilities'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_ExceptionUtilities_raise_with_options < Test::Unit::TestCase
10
+
11
+ include ::Xqsr3::Diagnostics
12
+
13
+ class ArgumentErrorWithOptions < ArgumentError
14
+ def initialize(message = nil, **options)
15
+ super(message)
16
+ options ||= {}
17
+ @options = options
18
+ end
19
+ attr_reader :options
20
+
21
+ def exception(msg = nil, options = nil)
22
+
23
+ return self if msg.nil?
24
+ return self if msg.object_id == self.object_id
25
+
26
+ msg ||= self.message
27
+ options ||= {}
28
+ r = self.class.new msg, self.options.merge(options)
29
+ r
30
+ end
31
+ end
32
+
33
+ def execute(&block)
34
+
35
+ block.call
36
+ end
37
+
38
+ def test_0
39
+
40
+ # standard raise: message-only
41
+ begin
42
+ raise "abc"
43
+
44
+ assert false, "should not get here"
45
+ rescue => x
46
+
47
+ assert_kind_of(RuntimeError, x)
48
+ assert_equal "abc", x.message
49
+ end
50
+
51
+ # RWO: message-only
52
+ begin
53
+ ExceptionUtilities.raise_with_options "abc"
54
+
55
+ assert false, "should not get here"
56
+ rescue => x
57
+
58
+ assert_kind_of(RuntimeError, x)
59
+ assert_equal "abc", x.message
60
+ end
61
+ end
62
+
63
+ def test_1
64
+
65
+ # standard raise: class
66
+ begin
67
+ raise ArgumentError
68
+
69
+ assert false, "should not get here"
70
+ rescue => x
71
+
72
+ assert_kind_of(ArgumentError, x)
73
+ assert_equal "ArgumentError", x.message
74
+ end
75
+
76
+ # RWO: class + message
77
+ begin
78
+ ExceptionUtilities.raise_with_options ArgumentError
79
+
80
+ assert false, "should not get here"
81
+ rescue => x
82
+
83
+ assert_kind_of(ArgumentError, x)
84
+ assert_equal "ArgumentError", x.message
85
+ end
86
+ end
87
+
88
+ def test_2
89
+
90
+ # standard raise: class + message
91
+ begin
92
+ raise ArgumentError, "abc"
93
+
94
+ assert false, "should not get here"
95
+ rescue => x
96
+
97
+ assert_kind_of(ArgumentError, x)
98
+ assert_equal "abc", x.message
99
+ end
100
+
101
+ # RWO: class + message
102
+ begin
103
+ ExceptionUtilities.raise_with_options ArgumentError, "abc"
104
+
105
+ assert false, "should not get here"
106
+ rescue => x
107
+
108
+ assert_kind_of(ArgumentError, x)
109
+ assert_equal "abc", x.message
110
+ end
111
+ end
112
+
113
+ def test_2_b_no_options
114
+
115
+ # standard raise: class + message
116
+ begin
117
+ raise ArgumentErrorWithOptions, "abc"
118
+
119
+ assert false, "should not get here"
120
+ rescue => x
121
+
122
+ assert_kind_of(ArgumentError, x)
123
+ assert_equal "abc", x.message
124
+ end
125
+
126
+ # RWO: class + message
127
+ begin
128
+ ExceptionUtilities.raise_with_options ArgumentErrorWithOptions, "abc"
129
+
130
+ assert false, "should not get here"
131
+ rescue => x
132
+
133
+ assert_kind_of(ArgumentError, x)
134
+ assert_equal "abc", x.message
135
+ end
136
+ end
137
+
138
+ def test_2_b_with_options
139
+
140
+ # standard raise: class + message + options
141
+ begin
142
+ raise ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
143
+
144
+ assert false, "should not get here"
145
+ rescue => x
146
+
147
+ assert_kind_of(ArgumentError, x)
148
+ assert_equal "abc", x.message
149
+ assert_equal ({ :blah => :blech, :id => 23 }), x.options
150
+ end
151
+
152
+ # RWO: class + message + options (raise-way)
153
+ begin
154
+ ExceptionUtilities.raise_with_options ArgumentErrorWithOptions.new("abc", blah: :blech, id: 23)
155
+
156
+ assert false, "should not get here"
157
+ rescue => x
158
+
159
+ assert_kind_of(ArgumentError, x)
160
+ assert_equal "abc", x.message
161
+ assert_equal ({ :blah => :blech, :id => 23 }), x.options
162
+ end
163
+
164
+ # RWO: class + message + options (raise_with_options-way)
165
+ begin
166
+ ExceptionUtilities.raise_with_options ArgumentErrorWithOptions, "abc", blah: :blech, id: 23
167
+
168
+ assert false, "should not get here"
169
+ rescue => x
170
+
171
+ assert_kind_of(ArgumentError, x)
172
+ assert_equal "abc", x.message
173
+ assert_equal ({ :blah => :blech, :id => 23 }), x.options
174
+ end
175
+ end
176
+
177
+
178
+ def test_with_backtrace
179
+ line_number = nil
180
+
181
+ # standard raise: class + message + stack trace
182
+ begin
183
+ begin
184
+ execute { line_number = __LINE__; raise ArgumentError }
185
+ rescue => x
186
+ raise x, "abc", x.backtrace
187
+ end
188
+
189
+ assert false, "should not get here"
190
+ rescue => x
191
+
192
+ assert_kind_of(ArgumentError, x)
193
+ assert_equal "abc", x.message
194
+
195
+ assert $@[0] =~ /^[^:]+:(\d+)/
196
+ assert_equal line_number.to_s, $1.to_s
197
+ end
198
+
199
+ # RWO: class + message + stack trace
200
+ begin
201
+ begin
202
+ execute { line_number = __LINE__; ExceptionUtilities.raise_with_options ArgumentErrorWithOptions, blah: :blech, id: 23 }
203
+
204
+ assert false, "should not get here"
205
+ rescue => x
206
+ raise x, "abc", x.backtrace
207
+ end
208
+
209
+ assert false, "should not get here"
210
+ rescue => x
211
+
212
+ assert_kind_of(ArgumentError, x)
213
+ assert_equal "abc", x.message
214
+ assert_equal ({ :blah => :blech, :id => 23 }), x.options
215
+
216
+ assert $@[0] =~ /^[^:]+:(\d+)/
217
+ assert_equal line_number.to_s, $1.to_s
218
+ end
219
+ end
220
+ end
221
+
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_file = File.expand_path(__FILE__)
6
+ this_dir = File.expand_path(File.dirname(__FILE__))
7
+
8
+ # all tc_*rb in current directory
9
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
10
+
11
+ # all ts_*rb in immediate sub-directories
12
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
13
+
@@ -0,0 +1,36 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/extensions/enumerable/collect_with_index'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_Enumerable_collect_with_index < Test::Unit::TestCase
10
+
11
+ def test_simple
12
+
13
+ ar = [ 1, -2, 3, -4, 5, -6 ]
14
+
15
+ r = ar.collect_with_index do |v, index0|
16
+
17
+ index0 * v.abs
18
+ end
19
+
20
+ assert_equal [ 0, 2, 6, 12, 20, 30 ], r
21
+ end
22
+
23
+ def test_simple_with_offset
24
+
25
+ ar = [ 1, -2, 3, -4, 5, -6 ]
26
+
27
+ r = ar.collect_with_index(1) do |v, index0|
28
+
29
+ index0 * v.abs
30
+ end
31
+
32
+ assert_equal [ 1, 4, 9, 16, 25, 36 ], r
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/extensions/enumerable/unique'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_Enumerable_unique_test < Test::Unit::TestCase
10
+
11
+ def test_empty
12
+
13
+ src = []
14
+
15
+ dest = src.unique
16
+
17
+ assert dest.empty?
18
+ end
19
+
20
+ def test_already_unique
21
+
22
+ src = [ 1, 2, 3, 4 ]
23
+
24
+ dest = src.unique
25
+
26
+ assert_equal src, dest
27
+ end
28
+
29
+ def test_unique_contiguous
30
+
31
+ src = [ 1, 2, 3, 3, 4 ]
32
+
33
+ dest = src.unique
34
+
35
+ assert_equal [ 1, 2, 3, 4], dest
36
+ end
37
+
38
+ def test_unique_noncontiguous
39
+
40
+ src = [ 1, 2, 3, 4, 3 ]
41
+
42
+ dest = src.unique
43
+
44
+ assert_equal [ 1, 2, 3, 4], dest
45
+ end
46
+ end
47
+
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_file = File.expand_path(__FILE__)
6
+ this_dir = File.expand_path(File.dirname(__FILE__))
7
+
8
+ # all tc_*rb in current directory
9
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
10
+
11
+ # all ts_*rb in immediate sub-directories
12
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
13
+
@@ -0,0 +1,110 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/extensions/io/writelines'
6
+
7
+ require 'test/unit'
8
+
9
+ require 'stringio'
10
+
11
+ class Test_IO_writelines < Test::Unit::TestCase
12
+
13
+ def test_single_string
14
+
15
+ input = 'abc'
16
+
17
+ s = StringIO.new '', 'a'
18
+
19
+ r = ::IO.writelines s, input
20
+
21
+ assert_equal 1, r
22
+ assert_equal "abc\n", s.string
23
+ end
24
+
25
+ def test_single_string_in_array
26
+
27
+ input = [ 'abc' ]
28
+
29
+ s = StringIO.new '', 'a'
30
+
31
+ r = ::IO.writelines s, input
32
+
33
+ assert_equal 1, r
34
+ assert_equal "abc\n", s.string
35
+ end
36
+
37
+ def test_single_string_in_hash
38
+
39
+ input = { 'abc' => '' }
40
+
41
+ s = StringIO.new '', 'a'
42
+
43
+ r = ::IO.writelines s, input
44
+
45
+ assert_equal 1, r
46
+ assert_equal "abc\n", s.string
47
+ end
48
+
49
+ def test_two_strings_in_array
50
+
51
+ input = [ 'abc', 'def' ]
52
+
53
+ s = StringIO.new '', 'a'
54
+
55
+ r = ::IO.writelines s, input
56
+
57
+ assert_equal 2, r
58
+ assert_equal "abc\ndef\n", s.string
59
+ end
60
+
61
+ def test_two_strings_in_array_with_suppressed_eol
62
+
63
+ input = [ 'abc', 'def' ]
64
+
65
+ s = StringIO.new '', 'a'
66
+
67
+ r = ::IO.writelines s, input, ''
68
+
69
+ assert_equal 2, r
70
+ assert_equal "abcdef", s.string
71
+ end
72
+
73
+ def test_two_strings_in_hash
74
+
75
+ input = { 'ab' => 'c', 'de' => 'f' }
76
+
77
+ s = StringIO.new '', 'a'
78
+
79
+ r = ::IO.writelines s, input
80
+
81
+ assert_equal 2, r
82
+ assert_equal "abc\ndef\n", s.string
83
+ end
84
+
85
+ def test_ten_strings_in_array
86
+
87
+ input = (0...10).map { |i| i.to_s }
88
+
89
+ s = StringIO.new
90
+
91
+ r = ::IO.writelines s, input
92
+
93
+ assert_equal 10, r
94
+ assert_equal "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", s.string
95
+ end
96
+
97
+ def test_strings_with_cr_in_array
98
+
99
+ input = [ "abc\n", "def\n", "ghi\n" ]
100
+
101
+ s = StringIO.new
102
+
103
+ r = ::IO.writelines s, input
104
+
105
+ assert_equal 3, r
106
+ assert_equal "abc\ndef\nghi\n", s.string
107
+ end
108
+ end
109
+
110
+