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,51 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../../lib')
4
+
5
+ require 'xqsr3/extensions/string/to_symbol'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+ class Test_String_to_symbol < Test::Unit::TestCase
11
+
12
+ def test_empty_string
13
+
14
+ assert_nil ''.to_symbol
15
+ end
16
+
17
+ def test_simple_string
18
+
19
+ assert_equal :a, 'a'.to_symbol
20
+ end
21
+
22
+ def test_string_with_spaces
23
+
24
+ assert_equal :some_symbol, 'some symbol'.to_symbol
25
+ assert_nil 'some symbol'.to_symbol(reject_spaces: true)
26
+ assert_nil 'some symbol'.to_symbol(reject_whitespace: true)
27
+ end
28
+
29
+ def test_string_with_tabs
30
+
31
+ assert_equal :some_symbol, "some\tsymbol".to_symbol
32
+ assert_nil "some\tsymbol".to_symbol(reject_tabs: true)
33
+ assert_nil "some\tsymbol".to_symbol(reject_whitespace: true)
34
+ end
35
+
36
+ def test_string_with_hyphens
37
+
38
+ assert_equal :some_symbol, 'some-symbol'.to_symbol
39
+ assert_nil 'some-symbol'.to_symbol(reject_hyphens: true)
40
+ end
41
+
42
+ def test_string_with_transform_characters
43
+
44
+ assert_nil 'some#funky$symbol'.to_symbol
45
+ assert_nil 'some#funky$symbol'.to_symbol transform_characters: [ ?', ?$ ]
46
+ assert_nil 'some#funky$symbol'.to_symbol transform_characters: [ ?#, ?' ]
47
+ assert_equal :some_funky_symbol, 'some#funky$symbol'.to_symbol(transform_characters: [ ?#, ?$ ])
48
+ end
49
+ end
50
+
51
+
@@ -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,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,200 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/io/writelines'
6
+
7
+ require 'test/unit'
8
+ require 'stringio'
9
+
10
+ include ::Xqsr3::IO
11
+
12
+ class Test_Xqsr3_IO_writelines < Test::Unit::TestCase
13
+
14
+ def test_single_string
15
+
16
+ input = 'abc'
17
+
18
+ s = StringIO.new '', 'a'
19
+
20
+ r = ::Xqsr3::IO.writelines s, input
21
+
22
+ assert_equal 1, r
23
+ assert_equal "abc\n", s.string
24
+ end
25
+
26
+ def test_single_string_in_array
27
+
28
+ input = [ 'abc' ]
29
+
30
+ s = StringIO.new '', 'a'
31
+
32
+ r = ::Xqsr3::IO.writelines s, input
33
+
34
+ assert_equal 1, r
35
+ assert_equal "abc\n", s.string
36
+ end
37
+
38
+ def test_single_string_in_hash
39
+
40
+ input = { 'abc' => '' }
41
+
42
+ s = StringIO.new '', 'a'
43
+
44
+ r = ::Xqsr3::IO.writelines s, input
45
+
46
+ assert_equal 1, r
47
+ assert_equal "abc\n", s.string
48
+ end
49
+
50
+ def test_two_strings_in_array
51
+
52
+ input = [ 'abc', 'def' ]
53
+
54
+ s = StringIO.new '', 'a'
55
+
56
+ r = ::Xqsr3::IO.writelines s, input
57
+
58
+ assert_equal 2, r
59
+ assert_equal "abc\ndef\n", s.string
60
+ end
61
+
62
+ def test_two_strings_in_array_with_suppressed_eol
63
+
64
+ input = [ 'abc', 'def' ]
65
+
66
+ s = StringIO.new '', 'a'
67
+
68
+ r = ::Xqsr3::IO.writelines s, input, line_separator: ''
69
+
70
+ assert_equal 2, r
71
+ assert_equal "abcdef", s.string
72
+ end
73
+
74
+ def test_two_strings_in_hash
75
+
76
+ input = { 'ab' => 'c', 'de' => 'f' }
77
+
78
+ s = StringIO.new '', 'a'
79
+
80
+ r = ::Xqsr3::IO.writelines s, input
81
+
82
+ assert_equal 2, r
83
+ assert_equal "abc\ndef\n", s.string
84
+ end
85
+
86
+ def test_two_strings_in_hash_with_col_sep
87
+
88
+ input = { 'ab' => 'c', 'de' => 'f' }
89
+
90
+ s = StringIO.new '', 'a'
91
+
92
+ r = ::Xqsr3::IO.writelines s, input, column_separator: "\t"
93
+
94
+ assert_equal 2, r
95
+ assert_equal "ab\tc\nde\tf\n", s.string
96
+ end
97
+
98
+ def test_ten_strings_in_array
99
+
100
+ input = (0...10).map { |i| i.to_s }
101
+
102
+ s = StringIO.new
103
+
104
+ r = ::Xqsr3::IO.writelines s, input
105
+
106
+ assert_equal 10, r
107
+ assert_equal "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", s.string
108
+ end
109
+
110
+ def test_strings_with_cr_in_array
111
+
112
+ input = [ "abc\n", "def\n", "ghi\n" ]
113
+
114
+ s = StringIO.new
115
+
116
+ r = ::Xqsr3::IO.writelines s, input
117
+
118
+ assert_equal 3, r
119
+ assert_equal "abc\ndef\nghi\n", s.string
120
+ end
121
+
122
+ def test_strings_with_cr_in_array_and_line_sep
123
+
124
+ input = [ "abc\n", "def\n", "ghi\n" ]
125
+
126
+ s = StringIO.new
127
+
128
+ r = ::Xqsr3::IO.writelines s, input, line_separator: '|'
129
+
130
+ assert_equal 3, r
131
+ assert_equal "abc\n|def\n|ghi\n|", s.string
132
+ end
133
+
134
+ def test_many_strings_in_array_with_eol
135
+
136
+ input = []
137
+
138
+ (0...1000).each { |n| input << "entry-#{n.to_s().rjust(4, '0')}\n" }
139
+
140
+ assert_equal 1000, input.size
141
+
142
+ s = StringIO.new
143
+
144
+ r = ::Xqsr3::IO.writelines s, input
145
+
146
+ assert_equal 1000, r
147
+ assert_equal "entry-0000\nentry-0001\n", s.string[0 ... 22]
148
+ end
149
+
150
+ def test_many_strings_in_array_without_eol
151
+
152
+ input = []
153
+
154
+ (0...1000).each { |n| input << "entry-#{n.to_s().rjust(4, '0')}" }
155
+
156
+ assert_equal 1000, input.size
157
+
158
+ s = StringIO.new
159
+
160
+ r = ::Xqsr3::IO.writelines s, input
161
+
162
+ assert_equal 1000, r
163
+ assert_equal "entry-0000\nentry-0001\n", s.string[0 ... 22]
164
+ end
165
+
166
+ def test_many_strings_in_array_with_eol_and_line_sep
167
+
168
+ input = []
169
+
170
+ (0...1000).each { |n| input << "entry-#{n.to_s().rjust(4, '0')}\n" }
171
+
172
+ assert_equal 1000, input.size
173
+
174
+ s = StringIO.new
175
+
176
+ r = ::Xqsr3::IO.writelines s, input, line_separator: '|'
177
+
178
+ assert_equal 1000, r
179
+ assert_equal "entry-0000\n|entry-0001\n|", s.string[0 ... 24]
180
+ end
181
+
182
+ def test_many_strings_in_array_without_eol_and_line_sep
183
+
184
+ input = []
185
+
186
+ (0...1000).each { |n| input << "entry-#{n.to_s().rjust(4, '0')}" }
187
+
188
+ assert_equal 1000, input.size
189
+
190
+ s = StringIO.new
191
+
192
+ r = ::Xqsr3::IO.writelines s, input, line_separator: '|'
193
+
194
+ assert_equal 1000, r
195
+ assert_equal "entry-0000|entry-0001|", s.string[0 ... 22]
196
+ end
197
+ end
198
+
199
+ # ############################## end of file ############################# #
200
+
@@ -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,181 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../..', 'lib')
4
+
5
+ require 'xqsr3/quality/parameter_checking'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_parameter_checks_as_separate_module < Test::Unit::TestCase
10
+
11
+ module TestConstants
12
+ end
13
+ include TestConstants
14
+
15
+ extend ::Xqsr3::Quality::ParameterChecking
16
+
17
+
18
+ # test 1
19
+
20
+ def check_method_1 a
21
+
22
+ self.class.check_param a, 'a'
23
+ end
24
+
25
+ def test_1
26
+
27
+ assert_raise ArgumentError do
28
+ check_method_1(nil)
29
+ end
30
+
31
+ assert_equal true, check_method_1(true)
32
+ assert_equal '', check_method_1('')
33
+ assert_equal [], check_method_1([])
34
+ assert_equal Hash.new, check_method_1(Hash.new)
35
+ end
36
+
37
+
38
+ # test 2
39
+
40
+ def check_method_2 a, types, options = {}
41
+
42
+ self.class.check_param a, 'a', options.merge({ types: types })
43
+ end
44
+
45
+ def test_2
46
+
47
+ assert_equal true, check_method_2(true, [ ::TrueClass ])
48
+ assert_equal true, check_method_2(true, [ ::TrueClass, ::String, ::Symbol ])
49
+ assert_raise TypeError do
50
+ check_method_2(true, [ ::String, ::Symbol, ::FalseClass ])
51
+ end
52
+ assert_equal true, check_method_2(true, [ ::TrueClass ], nothrow: true)
53
+ assert_nil check_method_2(true, [ ::FalseClass ], nothrow: true)
54
+ end
55
+
56
+
57
+ # test 3
58
+
59
+ def check_method_3 a, types, values, options = {}
60
+
61
+ self.class.check_param a, 'a', options.merge({ types: types, values: values })
62
+ end
63
+
64
+ def test_3
65
+
66
+ assert_raise RangeError do
67
+ check_method_3(-1, nil, [ 0..2 ])
68
+ end
69
+ assert_equal 0, check_method_3(0, nil, [ 0..2 ])
70
+ assert_equal 1, check_method_3(1, nil, [ 0..2 ])
71
+ assert_equal 2, check_method_3(2, nil, [ 0..2 ])
72
+ assert_raise RangeError do
73
+ check_method_3(3, nil, [ 0..2 ])
74
+ end
75
+ end
76
+
77
+
78
+ # test 4
79
+
80
+ def check_method_4 a, types, values, options = {}, &block
81
+
82
+ self.class.check_param a, 'a', options.merge({ types: types, values: values }), &block
83
+ end
84
+
85
+ def test_4
86
+
87
+ assert_equal 0, check_method_4(0, nil, nil)
88
+ assert_equal 0, check_method_4(0, nil, nil) { |n| 0 == n }
89
+
90
+ assert_raise RangeError do
91
+ check_method_4(-1, nil, nil) { |n| 0 == n }
92
+ end
93
+
94
+ assert_raise ArgumentError do
95
+ check_method_4('-1', nil, nil) { |n| 0 == n }
96
+ end
97
+
98
+ assert_raise TypeError do
99
+ check_method_4('-1', [ ::Numeric ], nil)
100
+ end
101
+ assert_raise ArgumentError do
102
+ check_method_4('-1', [ ::String ], [ '-2', '0', '+1', '+2' ])
103
+ end
104
+ assert_equal '-1', check_method_4('-1', [ ::String ], [ '-2', '-1', '0', '+1', '+2' ])
105
+ # assert_raise RangeError do
106
+ # check_method_4('-1', [ ::String ], [ '-2', '0', '+1', '+2' ]) {
107
+ # end
108
+
109
+ # check_param(id, 'id', types: ::Integer) { |v| raise ArgumentError, "'id' must be a positive integer" unless v > 0 }
110
+
111
+ end
112
+
113
+
114
+
115
+ # test 5
116
+
117
+ def check_method_5 a, options = {}
118
+
119
+ self.class.check_param a, 'a', options
120
+ end
121
+
122
+ def test_5
123
+
124
+ assert_equal "", check_method_5("", require_empty: true)
125
+ assert_equal "a", check_method_5("a", reject_empty: true)
126
+
127
+ assert_raise ArgumentError do
128
+ check_method_5("", reject_empty: true)
129
+ end
130
+
131
+ if false
132
+ assert_raise ArgumentError do
133
+ check_method_5(nil)
134
+ end
135
+
136
+ assert_equal true, check_method_5(true)
137
+ assert_equal '', check_method_5('')
138
+ assert_equal [], check_method_5([])
139
+ assert_equal Hash.new, check_method_5(Hash.new)
140
+ end
141
+ end
142
+
143
+
144
+ # test 6
145
+
146
+ def check_method_6 a, types, values, options = {}, &block
147
+
148
+ self.class.check_param a, 'a', options.merge({ types: types, values: values }), &block
149
+ end
150
+
151
+ def test_6
152
+
153
+ begin
154
+ check_method_6 '', [ ::Hash ], []
155
+
156
+ assert(false, 'should not get here')
157
+ rescue TypeError => ax
158
+
159
+ assert_match /^parameter 'a' \(String\) must be an instance of Hash$/, ax.message
160
+ rescue => x
161
+
162
+ assert(false, "wrong exception type (#{x.class})")
163
+ end
164
+
165
+
166
+ begin
167
+ check_method_6 '', [ ::String ], [ 'b', 'c', 'd' ]
168
+
169
+ assert(false, 'should not get here')
170
+ rescue ArgumentError => ax
171
+
172
+ assert_match /^parameter 'a' value '' not found equal\/within any of required values or ranges$/, ax.message
173
+ rescue => x
174
+
175
+ assert(false, "wrong exception type (#{x.class})")
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+