ruby_ex 0.4.6.1 → 0.4.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +4 -0
- data/SPEC.yml +3 -3
- data/lib/module/hierarchy.rb +283 -286
- data/lib/ruby_ex.rb +2 -2
- data/lib/sym_tbl_gsub.rb +22 -2
- data/lib/uri/generic_ex.rb +5 -3
- data/test/algorithms/simulated_annealing_test.rb +74 -78
- data/test/unit-suite.yml +2 -2
- metadata +2 -3
- data/SPEC.gemspec +0 -14
data/NEWS
CHANGED
data/SPEC.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
---
|
2
2
|
Author: The Uttk Team.
|
3
3
|
License: Ruby License
|
4
|
-
Revision: '$Id: /w/fey/ruby_ex/trunk/SPEC.yml
|
4
|
+
Revision: '$Id: /w/fey/ruby_ex/trunk/SPEC.yml 22445 2006-03-11T15:56:04.480135Z pouillar $'
|
5
5
|
|
6
|
-
version: !feydakins.org,2006/version dev-ruby/ruby_ex-0.
|
6
|
+
version: !feydakins.org,2006/version dev-ruby/ruby_ex-0.4_p2
|
7
7
|
|
8
8
|
title: RubyEx -- General purpose Ruby extensions.
|
9
9
|
summary: RubyEx contains general purpose Ruby extensions.
|
@@ -17,7 +17,7 @@ root_test_suite: test/check-pkg-ruby_ex.yml
|
|
17
17
|
rdoc_dir: doc/html
|
18
18
|
tags_url: svn://svn.feydakins.org/ruby_ex/tags
|
19
19
|
trunk_url: svn://svn.feydakins.org/ruby_ex/trunk
|
20
|
-
|
20
|
+
version_id.rb: !path lib/ruby_ex.rb
|
21
21
|
|
22
22
|
rdoc_files: !filelist
|
23
23
|
- README
|
data/lib/module/hierarchy.rb
CHANGED
@@ -1,339 +1,336 @@
|
|
1
|
-
# Copyright
|
2
|
-
# Author
|
3
|
-
# License
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
# Copyright:: Copyright (c) 2004, 2006 Nicolas Despres. All rights reserved.
|
2
|
+
# Author:: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/module/hierarchy.rb 22446 2006-03-11T18:07:59.270837Z pouillar $
|
5
|
+
|
6
|
+
class Module
|
7
|
+
|
8
|
+
# Extend the Module class with method to manipulate inheritance relation
|
9
|
+
# between constants of a module.
|
10
|
+
module Hierarchy
|
11
|
+
|
12
|
+
# Return the list of all sub classes of base_class (including itself).
|
13
|
+
# If force_autoload is false, not yet loaded constants will be ignored.
|
14
|
+
# If recursive is true sub modules will also be traversed.
|
15
|
+
def sub_classes(base_class, force_autoload=false, recursive=false)
|
16
|
+
check_const_is_class?(base_class)
|
17
|
+
result = []
|
18
|
+
constants.each do |const_name|
|
19
|
+
if autoload?(const_name).nil? or force_autoload
|
20
|
+
const = const_get(const_name)
|
21
|
+
if const.is_a?(Module)
|
22
|
+
if const.is_a?(Class)
|
23
|
+
result << const if const.ancestors.include?(base_class)
|
24
|
+
elsif recursive
|
25
|
+
result += const.sub_classes(base_class, force_autoload, recursive)
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
result
|
30
31
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
|
33
|
+
# Remove a class from the hierarchy using remove_const. Sub classes of this
|
34
|
+
# class are also removed. It returns an array of the removed class name.
|
35
|
+
# See sub_classes for a description of the recursive argument.
|
36
|
+
def remove_class(base_class, recursive=false)
|
37
|
+
subs = sub_classes(base_class, true, recursive)
|
38
|
+
re = /^#{name}::/
|
39
|
+
result = []
|
40
|
+
subs.each do |sub|
|
41
|
+
sub_name = sub.to_s.sub!(re, '')
|
42
|
+
if sub_name =~ /^(.+)::(.+)$/
|
43
|
+
const_get($1).module_eval { remove_const($2.to_sym) }
|
44
|
+
else
|
45
|
+
remove_const(sub_name.to_sym)
|
46
|
+
end
|
47
|
+
result << sub_name
|
47
48
|
end
|
48
|
-
result
|
49
|
+
result
|
49
50
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
subs = sub_classes(base_class, force_autoload, recursive)
|
114
|
-
sub_classes_tree_rec([base_class], subs)
|
115
|
-
end
|
116
|
-
|
117
|
-
private
|
118
|
-
def sub_classes_tree_rec(base_classes, csts)
|
119
|
-
result = {}
|
120
|
-
next_csts = Set.new
|
121
|
-
base_classes.each do |b|
|
122
|
-
next_base_classes = Set.new
|
123
|
-
csts.each do |c|
|
124
|
-
c.superclass == b ? next_base_classes << c : next_csts << c;
|
125
|
-
end
|
126
|
-
result[b] = sub_classes_tree_rec(next_base_classes, next_csts)
|
51
|
+
|
52
|
+
# Return the inheritance tree of the base_class.
|
53
|
+
# Example:
|
54
|
+
#
|
55
|
+
# module M
|
56
|
+
# class A; end
|
57
|
+
# class B < A; end
|
58
|
+
# class C < B; end
|
59
|
+
# class D < B; end
|
60
|
+
# class E < A; end
|
61
|
+
# module N
|
62
|
+
# class F < A; end
|
63
|
+
# class G < F; end
|
64
|
+
# class H < D; end
|
65
|
+
# class I < H; end
|
66
|
+
# class J < E; end
|
67
|
+
# class Y; end
|
68
|
+
# end
|
69
|
+
# class Z; end
|
70
|
+
# FOO = 42
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# M.sub_classes_tree(M::A)
|
74
|
+
#
|
75
|
+
# produces:
|
76
|
+
#
|
77
|
+
# {
|
78
|
+
# M::A => {
|
79
|
+
# M::B => {
|
80
|
+
# M::D => {},
|
81
|
+
# M::C => {}
|
82
|
+
# },
|
83
|
+
# M::E => {}
|
84
|
+
# }
|
85
|
+
# }
|
86
|
+
#
|
87
|
+
# and
|
88
|
+
#
|
89
|
+
# M.sub_classes_tree(M::A, false, true)
|
90
|
+
#
|
91
|
+
# produces:
|
92
|
+
#
|
93
|
+
# {
|
94
|
+
# M::A => {
|
95
|
+
# M::N::F => {
|
96
|
+
# M::N::G => {}
|
97
|
+
# },
|
98
|
+
# M::B => {
|
99
|
+
# M::C => {},
|
100
|
+
# M::D => {
|
101
|
+
# M::N::H => {
|
102
|
+
# M::N::I => {}
|
103
|
+
# }
|
104
|
+
# }
|
105
|
+
# },
|
106
|
+
# M::E => {
|
107
|
+
# M::N::J => {}
|
108
|
+
# }
|
109
|
+
# }
|
110
|
+
# }
|
111
|
+
def sub_classes_tree(base_class, force_autoload=false, recursive=false)
|
112
|
+
subs = sub_classes(base_class, force_autoload, recursive)
|
113
|
+
sub_classes_tree_rec([base_class], subs)
|
127
114
|
end
|
128
|
-
result
|
129
|
-
end
|
130
115
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
116
|
+
private
|
117
|
+
def sub_classes_tree_rec(base_classes, csts)
|
118
|
+
result = {}
|
119
|
+
next_csts = Set.new
|
120
|
+
base_classes.each do |b|
|
121
|
+
next_base_classes = Set.new
|
122
|
+
csts.each do |c|
|
123
|
+
c.superclass == b ? next_base_classes << c : next_csts << c;
|
124
|
+
end
|
125
|
+
result[b] = sub_classes_tree_rec(next_base_classes, next_csts)
|
126
|
+
end
|
127
|
+
result
|
135
128
|
end
|
136
|
-
end
|
137
129
|
|
138
|
-
|
130
|
+
private
|
131
|
+
def check_const_is_class?(*base_classes)
|
132
|
+
base_classes.each do |b|
|
133
|
+
raise(TypeError, "`#{b}' - not a class") unless b.is_a?(Class)
|
134
|
+
end
|
135
|
+
end
|
139
136
|
|
140
|
-
|
137
|
+
end # module Hierarchy
|
141
138
|
|
142
139
|
include Hierarchy
|
143
140
|
|
144
|
-
|
145
|
-
|
146
|
-
module Hierarchy
|
147
|
-
|
148
|
-
test_section __FILE__ do
|
141
|
+
module Hierarchy
|
149
142
|
|
150
|
-
|
143
|
+
test_section __FILE__ do
|
151
144
|
|
145
|
+
require 'diff'
|
152
146
|
|
153
|
-
class HierarchyTest < Test::Unit::TestCase
|
154
147
|
|
155
|
-
|
148
|
+
class HierarchyTest < Test::Unit::TestCase
|
156
149
|
|
157
|
-
|
158
|
-
class B < A; end
|
159
|
-
class C; end
|
160
|
-
FOO = 42
|
150
|
+
module M
|
161
151
|
|
162
|
-
|
152
|
+
class A; end
|
153
|
+
class B < A; end
|
154
|
+
class C; end
|
155
|
+
FOO = 42
|
163
156
|
|
164
|
-
def test_sub_classes
|
165
|
-
sub_classes = M.sub_classes(HierarchyTest::M::A)
|
166
|
-
assert_equal(2, sub_classes.size)
|
167
|
-
[HierarchyTest::M::B, HierarchyTest::M::A].each do |x|
|
168
|
-
assert(sub_classes.include?(x))
|
169
157
|
end
|
170
|
-
assert_equal([HierarchyTest::M::C], M.sub_classes(M::C))
|
171
|
-
end
|
172
158
|
|
173
|
-
|
159
|
+
def test_sub_classes
|
160
|
+
sub_classes = M.sub_classes(HierarchyTest::M::A)
|
161
|
+
assert_equal(2, sub_classes.size)
|
162
|
+
[HierarchyTest::M::B, HierarchyTest::M::A].each do |x|
|
163
|
+
assert(sub_classes.include?(x))
|
164
|
+
end
|
165
|
+
assert_equal([HierarchyTest::M::C], M.sub_classes(M::C))
|
166
|
+
end
|
174
167
|
|
175
|
-
|
176
|
-
class B < A; end
|
177
|
-
autoload(:C, '/foo')
|
178
|
-
FOO = 42
|
168
|
+
module Mautoload
|
179
169
|
|
180
|
-
|
170
|
+
class A; end
|
171
|
+
class B < A; end
|
172
|
+
autoload(:C, '/foo')
|
173
|
+
FOO = 42
|
181
174
|
|
182
|
-
def test_sub_classes_force_autoload
|
183
|
-
sub_classes = Mautoload.sub_classes(Mautoload::A)
|
184
|
-
assert_equal(2, sub_classes.size)
|
185
|
-
[Mautoload::B, Mautoload::A].each do |x|
|
186
|
-
assert(sub_classes.include?(x))
|
187
175
|
end
|
188
|
-
assert_equal(4, Mautoload.constants.size)
|
189
|
-
assert_not_nil(Mautoload.autoload?(:C))
|
190
|
-
assert_raise(MissingSourceFile, LoadError) { Mautoload.sub_classes(Mautoload::A, true) }
|
191
|
-
assert_equal(3, Mautoload.constants.size)
|
192
|
-
assert_nil(Mautoload.autoload?(:C))
|
193
|
-
end
|
194
176
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
177
|
+
def test_sub_classes_force_autoload
|
178
|
+
sub_classes = Mautoload.sub_classes(Mautoload::A)
|
179
|
+
assert_equal(2, sub_classes.size)
|
180
|
+
[Mautoload::B, Mautoload::A].each do |x|
|
181
|
+
assert(sub_classes.include?(x))
|
182
|
+
end
|
183
|
+
assert_equal(4, Mautoload.constants.size)
|
184
|
+
assert_not_nil(Mautoload.autoload?(:C))
|
185
|
+
assert_raise(MissingSourceFile, LoadError) { Mautoload.sub_classes(Mautoload::A, true) }
|
186
|
+
assert_equal(3, Mautoload.constants.size)
|
187
|
+
assert_nil(Mautoload.autoload?(:C))
|
203
188
|
end
|
204
|
-
class Z; end
|
205
|
-
FOO = 42
|
206
|
-
end
|
207
189
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
190
|
+
module Mrec
|
191
|
+
class A; end
|
192
|
+
class B < A; end
|
193
|
+
module M
|
194
|
+
class C < A; end
|
195
|
+
class D < B; end
|
196
|
+
class E < D; end
|
197
|
+
class Y; end
|
198
|
+
end
|
199
|
+
class Z; end
|
200
|
+
FOO = 42
|
218
201
|
end
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
202
|
+
|
203
|
+
def test_sub_classes_recursive
|
204
|
+
sub_classes = Mrec.sub_classes(Mrec::A)
|
205
|
+
assert_equal(2, sub_classes.size)
|
206
|
+
[Mrec::B, Mrec::A].each do |x|
|
207
|
+
assert(sub_classes.include?(x))
|
208
|
+
end
|
209
|
+
sub_classes = Mrec.sub_classes(Mrec::A, false, true)
|
210
|
+
assert_equal(5, sub_classes.size)
|
211
|
+
[Mrec::B, Mrec::A, Mrec::M::C, Mrec::M::D, Mrec::M::E].each do |x|
|
212
|
+
assert(sub_classes.include?(x))
|
213
|
+
end
|
214
|
+
r = Mrec.remove_class(Mrec::A, true)
|
215
|
+
assert_equal(5, r.size)
|
216
|
+
['B', 'A', 'M::E', 'M::C', 'M::D'].each do |x|
|
217
|
+
assert(r.include?(x))
|
218
|
+
end
|
219
|
+
assert_equal(3, Mrec.constants.size)
|
220
|
+
['FOO', 'M', 'Z'].each { |x| assert(Mrec.constants.include?(x)) }
|
221
|
+
assert_equal(1, Mrec::M.constants.size)
|
222
|
+
['Y'].each { |x| assert(Mrec::M.constants.include?(x)) }
|
223
223
|
end
|
224
|
-
assert_equal(3, Mrec.constants.size)
|
225
|
-
['FOO', 'M', 'Z'].each { |x| assert(Mrec.constants.include?(x)) }
|
226
|
-
assert_equal(1, Mrec::M.constants.size)
|
227
|
-
['Y'].each { |x| assert(Mrec::M.constants.include?(x)) }
|
228
|
-
end
|
229
224
|
|
230
|
-
|
225
|
+
module Tree
|
231
226
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
227
|
+
class A; end
|
228
|
+
class B < A; end
|
229
|
+
class C < B; end
|
230
|
+
class D < B; end
|
231
|
+
class E < A; end
|
232
|
+
module M
|
233
|
+
class F < A; end
|
234
|
+
class G < F; end
|
235
|
+
class H < D; end
|
236
|
+
class I < H; end
|
237
|
+
class J < E; end
|
238
|
+
class Y; end
|
239
|
+
end
|
240
|
+
class Z; end
|
241
|
+
FOO = 42
|
247
242
|
|
248
|
-
|
243
|
+
end
|
249
244
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
245
|
+
def test_sub_classes_tree_rec
|
246
|
+
r = Tree.sub_classes_tree(HierarchyTest::Tree::A, false, true)
|
247
|
+
ref = {
|
248
|
+
HierarchyTest::Tree::A => {
|
249
|
+
HierarchyTest::Tree::M::F => {
|
250
|
+
HierarchyTest::Tree::M::G => {}
|
251
|
+
},
|
252
|
+
HierarchyTest::Tree::B => {
|
253
|
+
HierarchyTest::Tree::C => {},
|
254
|
+
HierarchyTest::Tree::D => {
|
255
|
+
HierarchyTest::Tree::M::H => {
|
256
|
+
HierarchyTest::Tree::M::I=>{}
|
257
|
+
}
|
262
258
|
}
|
259
|
+
},
|
260
|
+
HierarchyTest::Tree::E=> {
|
261
|
+
HierarchyTest::Tree::M::J=>{}
|
263
262
|
}
|
264
|
-
},
|
265
|
-
HierarchyTest::Tree::E=> {
|
266
|
-
HierarchyTest::Tree::M::J=>{}
|
267
263
|
}
|
268
264
|
}
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
end
|
265
|
+
d = r.diff(ref)
|
266
|
+
assert_equal({}, d[:different])
|
267
|
+
assert_equal({}, d[:additional])
|
268
|
+
assert_equal({}, d[:missing])
|
269
|
+
end
|
275
270
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
271
|
+
def test_sub_classes_tree
|
272
|
+
r = Tree.sub_classes_tree(HierarchyTest::Tree::A)
|
273
|
+
ref = {
|
274
|
+
HierarchyTest::Tree::A => {
|
275
|
+
HierarchyTest::Tree::B => {
|
276
|
+
HierarchyTest::Tree::D => {},
|
277
|
+
HierarchyTest::Tree::C => {}
|
278
|
+
},
|
279
|
+
HierarchyTest::Tree::E => {}
|
280
|
+
}
|
285
281
|
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
assert_equal({}, d[:missing])
|
291
|
-
end
|
292
|
-
|
293
|
-
module Error
|
294
|
-
module M; end
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_sub_classes_error
|
298
|
-
assert_raise(TypeError) do
|
299
|
-
Error.sub_classes_tree(HierarchyTest::Error::M)
|
282
|
+
d = r.diff(ref)
|
283
|
+
assert_equal({}, d[:different])
|
284
|
+
assert_equal({}, d[:additional])
|
285
|
+
assert_equal({}, d[:missing])
|
300
286
|
end
|
301
|
-
|
302
|
-
|
287
|
+
|
288
|
+
module Error
|
289
|
+
module M; end
|
303
290
|
end
|
304
|
-
|
305
|
-
|
291
|
+
|
292
|
+
def test_sub_classes_error
|
293
|
+
assert_raise(TypeError) do
|
294
|
+
Error.sub_classes_tree(HierarchyTest::Error::M)
|
295
|
+
end
|
296
|
+
assert_raise(TypeError) do
|
297
|
+
Error.sub_classes(HierarchyTest::Error::M)
|
298
|
+
end
|
299
|
+
assert_raise(TypeError) do
|
300
|
+
Error.remove_class(HierarchyTest::Error::M)
|
301
|
+
end
|
306
302
|
end
|
307
|
-
end
|
308
303
|
|
309
|
-
|
304
|
+
module RemoveClass
|
310
305
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
306
|
+
class A; end
|
307
|
+
class B < A; end
|
308
|
+
class C < B; end
|
309
|
+
class D < B; end
|
310
|
+
class E < D; end
|
311
|
+
class F < A; end
|
312
|
+
class Z; end
|
313
|
+
module M
|
314
|
+
class Y; end
|
315
|
+
end
|
316
|
+
BAR = 51
|
322
317
|
|
323
|
-
|
318
|
+
end
|
324
319
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
320
|
+
def test_remove_class
|
321
|
+
r = RemoveClass.remove_class(HierarchyTest::RemoveClass::B)
|
322
|
+
assert_equal(4, r.size)
|
323
|
+
['B', 'D', 'E', 'C'].each { |x| assert(r.include?(x)) }
|
324
|
+
assert_equal(5, RemoveClass.constants.size)
|
325
|
+
['A', 'F', 'Z', 'M', 'BAR'].each do |x|
|
326
|
+
assert(RemoveClass.constants.include?(x))
|
327
|
+
end
|
332
328
|
end
|
333
|
-
end
|
334
329
|
|
335
|
-
|
330
|
+
end # class HierarchyTest
|
331
|
+
|
332
|
+
end
|
336
333
|
|
337
|
-
end
|
334
|
+
end # module Hierarchy
|
338
335
|
|
339
|
-
end #
|
336
|
+
end # class Module
|
data/lib/ruby_ex.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/ruby_ex.rb 22445 2006-03-11T15:56:04.480135Z pouillar $
|
5
5
|
|
6
6
|
require 'pathname'
|
7
7
|
|
@@ -57,7 +57,7 @@ module RubyEx
|
|
57
57
|
i.fixed_cases 'URI', 'DRuby', 'MySQL', 'PgSQL', 'FTP', 'HTTP', 'DRb'
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
VersionId = ::Version.parse("dev-ruby/ruby_ex-0.4_p2")
|
61
61
|
|
62
62
|
dir.load_path!
|
63
63
|
(dir + 'module').load_path!
|
data/lib/sym_tbl_gsub.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
2
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
3
|
# License:: Ruby License
|
4
|
-
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/sym_tbl_gsub.rb 22444 2006-03-11T15:54:37.116683Z pouillar $
|
5
5
|
|
6
6
|
module SymTblGsub
|
7
7
|
|
@@ -10,13 +10,24 @@ module SymTblGsub
|
|
10
10
|
attr_accessor :symtbl
|
11
11
|
|
12
12
|
def assert_symtbl ( my, ref )
|
13
|
+
my_copy = Marshal.load(Marshal.dump(my))
|
13
14
|
assert_equal ref, my.do_symtbl_gsub(symtbl)
|
15
|
+
assert_equal my, my_copy,
|
16
|
+
'substitution not inplace has changed the object'
|
14
17
|
end
|
15
18
|
|
16
19
|
def assert_symtbl_nil ( my )
|
17
20
|
assert_nil my.symtbl_gsub(symtbl)
|
18
21
|
end
|
19
22
|
|
23
|
+
def assert_symtbl! ( my, ref )
|
24
|
+
assert_equal ref, my.do_symtbl_gsub!(symtbl)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_symtbl_nil! ( my )
|
28
|
+
assert_nil my.symtbl_gsub!(symtbl)
|
29
|
+
end
|
30
|
+
|
20
31
|
end # module Assertions
|
21
32
|
|
22
33
|
end # module SymTblGsub
|
@@ -123,7 +134,8 @@ class Pathname
|
|
123
134
|
end
|
124
135
|
|
125
136
|
def symtbl_gsub ( symtbl )
|
126
|
-
|
137
|
+
x = Pathname.new(@path.dup)
|
138
|
+
x.symtbl_gsub!(symtbl)
|
127
139
|
end
|
128
140
|
|
129
141
|
end # class Pathname
|
@@ -266,6 +278,14 @@ module SymTblGsub
|
|
266
278
|
assert_symtbl '<<dne>> <<foo>>', '<<dne>> bar'
|
267
279
|
end
|
268
280
|
class Foo
|
281
|
+
include Comparable
|
282
|
+
attr_reader :y
|
283
|
+
def initialize
|
284
|
+
@y = rand
|
285
|
+
end
|
286
|
+
def <=> ( x )
|
287
|
+
@y <=> x.y
|
288
|
+
end
|
269
289
|
end
|
270
290
|
def test_object
|
271
291
|
f = Foo.new
|
data/lib/uri/generic_ex.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/uri/generic_ex.rb
|
4
|
+
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/uri/generic_ex.rb 22448 2006-03-11T18:09:23.325348Z pouillar $
|
5
5
|
|
6
6
|
module URI
|
7
7
|
|
@@ -142,10 +142,12 @@ module URI
|
|
142
142
|
def test_lazy_loading_full
|
143
143
|
PathList[__FILE__.to_path.dirname.parent + '(uri/**/*).rb'].each do |full, path|
|
144
144
|
assert_nothing_raised do
|
145
|
-
|
145
|
+
next if path.to_s == 'uri/generic_ex'
|
146
|
+
class_name = path.to_s.gsub(/_ex$/, '').camelize
|
146
147
|
class_object = class_name.constantize
|
147
148
|
assert_equal class_name, class_object.name
|
148
|
-
assert_match(/URI::Generic(Ex)?/, class_object.superclass.name
|
149
|
+
assert_match(/URI::Generic(Ex)?/, class_object.superclass.name,
|
150
|
+
"Superclass of #{class_object}")
|
149
151
|
end
|
150
152
|
end
|
151
153
|
end
|
@@ -7,95 +7,91 @@ require 'yaml'
|
|
7
7
|
require 'stringio'
|
8
8
|
require 'test/unit'
|
9
9
|
|
10
|
-
|
10
|
+
class SimulatedAnnealingTest < Test::Unit::TestCase
|
11
11
|
|
12
|
-
class
|
12
|
+
class BasicFunction
|
13
|
+
include Algorithms::SimulatedAnnealing::Support
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@f = fun
|
22
|
-
@cur_pos = (@min..@max).choose
|
23
|
-
end
|
24
|
-
|
25
|
-
def choose_transition ( generator=nil )
|
26
|
-
@cur_pos + @step_width.choose(generator) - (@step_width / 2)
|
27
|
-
end
|
28
|
-
|
29
|
-
def apply_transition ( transition )
|
30
|
-
@cur_pos = transition
|
31
|
-
end
|
32
|
-
|
33
|
-
def transition_cost ( current_cost, transition )
|
34
|
-
@f[transition] - current_cost
|
35
|
-
end
|
36
|
-
|
37
|
-
def cost
|
38
|
-
@f[@cur_pos]
|
39
|
-
end
|
15
|
+
def initialize ( &fun )
|
16
|
+
@max = 100000
|
17
|
+
@min = -@max
|
18
|
+
@step_width = 500
|
19
|
+
@f = fun
|
20
|
+
@cur_pos = (@min..@max).choose
|
21
|
+
end
|
40
22
|
|
41
|
-
|
42
|
-
|
43
|
-
|
23
|
+
def choose_transition ( generator=nil )
|
24
|
+
@cur_pos + @step_width.choose(generator) - (@step_width / 2)
|
25
|
+
end
|
44
26
|
|
45
|
-
|
27
|
+
def apply_transition ( transition )
|
28
|
+
@cur_pos = transition
|
29
|
+
end
|
46
30
|
|
47
|
-
def
|
48
|
-
|
49
|
-
SimulatedAnnealing.new(
|
50
|
-
:support => obj,
|
51
|
-
:output => out,
|
52
|
-
:global_threshold => 20,
|
53
|
-
:step_multiplicator => 0.63,
|
54
|
-
:initial_temperature => 10,
|
55
|
-
:initial_cost => obj.cost,
|
56
|
-
:iteration_modulus => 10,
|
57
|
-
:step_modulus => 5000
|
58
|
-
)
|
31
|
+
def transition_cost ( current_cost, transition )
|
32
|
+
@f[transition] - current_cost
|
59
33
|
end
|
60
34
|
|
61
|
-
def
|
62
|
-
|
63
|
-
strm, sa = nil, nil
|
64
|
-
assert_nothing_raised do
|
65
|
-
sa = factory(out, &fun)
|
66
|
-
end
|
67
|
-
assert_nothing_raised do
|
68
|
-
sa.run
|
69
|
-
end
|
70
|
-
assert_nothing_raised do
|
71
|
-
sa.summary
|
72
|
-
end
|
73
|
-
out.flush
|
74
|
-
out.rewind
|
75
|
-
assert_nothing_raised do
|
76
|
-
strm = YAML::load_stream(out.read)
|
77
|
-
end
|
78
|
-
assert_kind_of(YAML::Stream, strm)
|
79
|
-
docs = strm.documents
|
80
|
-
assert_equal(2, docs.size)
|
81
|
-
docs[0] = [] if docs[0].nil?
|
82
|
-
assert_kind_of(Array, docs[0])
|
83
|
-
assert(docs[0].all? { |x| x.is_a?(Hash) })
|
84
|
-
docs[0].all? do |x|
|
85
|
-
ks = x.keys.delete_if { |y| y.is_a? Integer or y =~ /\|/ }
|
86
|
-
assert_equal(%w[cost prob temp thres], ks.sort)
|
87
|
-
end
|
88
|
-
assert_kind_of(Hash, docs[1])
|
35
|
+
def cost
|
36
|
+
@f[@cur_pos]
|
89
37
|
end
|
90
38
|
|
91
|
-
def
|
92
|
-
|
39
|
+
def copy_of_the_current_solution
|
40
|
+
@cur_pos
|
93
41
|
end
|
94
42
|
|
95
|
-
|
96
|
-
|
43
|
+
end # class BasicFunction
|
44
|
+
|
45
|
+
def factory ( out, &fun )
|
46
|
+
obj = BasicFunction.new(&fun)
|
47
|
+
Algorithms::SimulatedAnnealing.new(
|
48
|
+
:support => obj,
|
49
|
+
:output => out,
|
50
|
+
:global_threshold => 20,
|
51
|
+
:step_multiplicator => 0.63,
|
52
|
+
:initial_temperature => 10,
|
53
|
+
:initial_cost => obj.cost,
|
54
|
+
:iteration_modulus => 10,
|
55
|
+
:step_modulus => 5000
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def basic_checker ( &fun )
|
60
|
+
out = StringIO.new
|
61
|
+
strm, sa = nil, nil
|
62
|
+
assert_nothing_raised do
|
63
|
+
sa = factory(out, &fun)
|
64
|
+
end
|
65
|
+
assert_nothing_raised do
|
66
|
+
sa.run
|
67
|
+
end
|
68
|
+
assert_nothing_raised do
|
69
|
+
sa.summary
|
97
70
|
end
|
71
|
+
out.flush
|
72
|
+
out.rewind
|
73
|
+
assert_nothing_raised do
|
74
|
+
strm = YAML::load_stream(out.read)
|
75
|
+
end
|
76
|
+
assert_kind_of(YAML::Stream, strm)
|
77
|
+
docs = strm.documents
|
78
|
+
assert_equal(2, docs.size)
|
79
|
+
docs[0] = [] if docs[0].nil?
|
80
|
+
assert_kind_of(Array, docs[0])
|
81
|
+
assert(docs[0].all? { |x| x.is_a?(Hash) })
|
82
|
+
docs[0].all? do |x|
|
83
|
+
ks = x.keys.delete_if { |y| y.is_a? Integer or y =~ /\|/ }
|
84
|
+
assert_equal(%w[cost prob temp thres], ks.sort)
|
85
|
+
end
|
86
|
+
assert_kind_of(Hash, docs[1])
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_square
|
90
|
+
basic_checker { |x| x ** 2 }
|
91
|
+
end
|
98
92
|
|
99
|
-
|
93
|
+
def test_poly4
|
94
|
+
basic_checker { |x| (x - 1) * (x - 300) * (x - 10000) * (x + 300) }
|
95
|
+
end
|
100
96
|
|
101
|
-
end #
|
97
|
+
end # class SimulatedAnnealingTest
|
data/test/unit-suite.yml
CHANGED
@@ -10,6 +10,6 @@ RubyEx Unit Test Suite: !S::Iterate
|
|
10
10
|
load_path: [<<pwd>>/../lib, <<pwd>>/algorithms]
|
11
11
|
requires: <<pwd>>/../lib/ruby_ex # The full path is here to ensure we
|
12
12
|
# load the good one.
|
13
|
-
input: !path <<it_name
|
14
|
-
uttk_unit_options: --uttk no
|
13
|
+
input: !path <<it_name>>.rb
|
14
|
+
uttk_unit_options: --uttk no --mode import
|
15
15
|
verbose: true
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby_ex
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.6.
|
7
|
-
date: 2006-03-
|
6
|
+
version: 0.4.6.2
|
7
|
+
date: 2006-03-11 00:00:00 +01:00
|
8
8
|
summary: RubyEx contains general purpose Ruby extensions.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- test/sanity/single-requires.yml
|
168
168
|
- test/sanity/multiple-requires.yml
|
169
169
|
- NEWS
|
170
|
-
- SPEC.gemspec
|
171
170
|
- Rakefile
|
172
171
|
- README
|
173
172
|
- AUTHORS
|
data/SPEC.gemspec
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = %q{ruby_ex}
|
3
|
-
s.version = "0.4.6.1"
|
4
|
-
s.date = %q{2006-03-10}
|
5
|
-
s.summary = %q{RubyEx contains general purpose Ruby extensions.}
|
6
|
-
s.email = ["nicolas.despres@gmail.com", "ertai@feydakins.org"]
|
7
|
-
s.homepage = %q{http://api.feydakins.org/ruby_ex}
|
8
|
-
s.rubyforge_project = %q{ruby_ex}
|
9
|
-
s.description = %q{}
|
10
|
-
s.authors = ["Nicolas Despr\350s", "Nicolas Pouillard"]
|
11
|
-
s.files = ["lib/file_type.rb", "lib/config_file.rb", "lib/labeled_node.rb", "lib/diff.rb", "lib/spring_set.rb", "lib/genpasswd.rb", "lib/sendmail.rb", "lib/auto_object.rb", "lib/concrete.rb", "lib/commands.rb", "lib/generate_id.rb", "lib/ruby_ex.rb", "lib/verbose_object.rb", "lib/md5sum.rb", "lib/daemon.rb", "lib/syn_flow.rb", "lib/html_encode.rb", "lib/hooker.rb", "lib/d_logger.rb", "lib/cache.rb", "lib/diff_tools.rb", "lib/mocks.rb", "lib/choose.rb", "lib/safe_eval.rb", "lib/histogram.rb", "lib/regex_path.rb", "lib/timeout_ex.rb", "lib/text.rb", "lib/observable.rb", "lib/r_path.rb", "lib/indexed_node.rb", "lib/io_marshal.rb", "lib/ioo.rb", "lib/logger_observer.rb", "lib/abstract.rb", "lib/service_manager.rb", "lib/node.rb", "lib/meta_factory.rb", "lib/hash_eval.rb", "lib/object_monitor.rb", "lib/hookable.rb", "lib/pp_hierarchy.rb", "lib/ordered_hash.rb", "lib/spring.rb", "lib/shuffle.rb", "lib/observable_pool.rb", "lib/object_monitor_activity.rb", "lib/sym_tbl.rb", "lib/blank_slate.rb", "lib/sym_tbl_gsub.rb", "lib/attributed_class.rb", "lib/drb_ex.rb", "lib/random_generators.rb", "lib/method_call.rb", "lib/const_regexp.rb", "lib/regex_list.rb", "lib/abstract_node.rb", "lib/kill_all.rb", "lib/trace.rb", "lib/drb/undumped_attributes.rb", "lib/drb/insecure_protected_methods.rb", "lib/drb/observable.rb", "lib/drb/service.rb", "lib/drb/observable_pool.rb", "lib/drb/undumped_indexed_object.rb", "lib/uri/ftp_ex.rb", "lib/uri/pgsql.rb", "lib/uri/rsync.rb", "lib/uri/file.rb", "lib/uri/druby.rb", "lib/uri/generic_ex.rb", "lib/uri/http_ex.rb", "lib/uri/ssh.rb", "lib/uri/svn.rb", "lib/uri/mysql.rb", "lib/yaml/yregexpath.rb", "lib/yaml/chop_header.rb", "lib/yaml/transform.rb", "lib/mocks/observer.rb", "lib/mocks/assertions.rb", "lib/mocks/mock.rb", "lib/mocks/method_logger.rb", "lib/mocks/object.rb", "lib/commands/datas.rb", "lib/commands/helpers.rb", "lib/commands/seq.rb", "lib/commands/command.rb", "lib/commands/factory.rb", "lib/commands/pipe.rb", "lib/commands/runners.rb", "lib/commands/datas/data.rb", "lib/commands/datas/composite.rb", "lib/commands/datas/temp.rb", "lib/commands/datas/factory.rb", "lib/commands/datas/pipe.rb", "lib/commands/runners/popen.rb", "lib/commands/runners/system.rb", "lib/commands/runners/exec.rb", "lib/commands/runners/no_run.rb", "lib/commands/runners/fork.rb", "lib/commands/runners/mockable.rb", "lib/commands/runners/runner.rb", "lib/algorithms/simulated_annealing.rb", "lib/module/instance_method_visibility.rb", "lib/module/hierarchy.rb", "lib/module/autoload_tree.rb", "lib/random_generators/random_generator.rb", "lib/random_generators/ruby.rb", "test/unit-suite.yml", "test/check-ruby_ex.yml", "test/functional", "test/algorithms", "test/stress-tests", "test/fixtures", "test/sanity", "test/sanity-suite.yml", "test/check-pkg-ruby_ex.yml", "test/algorithms/simulated_annealing_test.rb", "test/stress-tests/threads_and_exceptions.yml", "test/fixtures/tar.gz.log", "test/fixtures/foo.tar.bz2", "test/fixtures/foo.rb.gz", "test/fixtures/my_diff.patch", "test/fixtures/foo.bz2", "test/fixtures/foo.tar", "test/fixtures/foo.txt", "test/fixtures/foo.gz.zip", "test/fixtures/foo.tar.gz", "test/fixtures/autoload_tree", "test/fixtures/autoload_tree/foo", "test/fixtures/autoload_tree/A.rb", "test/fixtures/autoload_tree/B.rb", "test/fixtures/autoload_tree/foo/C.rb", "test/sanity/single-requires.yml", "test/sanity/multiple-requires.yml", "NEWS", "SPEC.gemspec", "Rakefile", "README", "AUTHORS", "SPEC.yml", "ChangeLog"]
|
12
|
-
s.add_dependency(%q<highline>, ["~> 1.0.1"])
|
13
|
-
s.add_dependency(%q<core_ex>, ["~> 0.5.5"])
|
14
|
-
end
|