ruby_ex 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/ChangeLog +693 -0
  2. data/NEWS +74 -0
  3. data/SPEC.dyn.yml +6 -6
  4. data/SPEC.gemspec +14 -0
  5. data/SPEC.yml +4 -4
  6. data/lib/abstract.rb +2 -4
  7. data/lib/abstract_node.rb +1 -2
  8. data/lib/algorithms/simulated_annealing.rb +50 -29
  9. data/lib/attributed_class.rb +50 -21
  10. data/lib/auto_object.rb +102 -0
  11. data/lib/blank_slate.rb +102 -0
  12. data/lib/cache.rb +1 -2
  13. data/lib/choose.rb +165 -163
  14. data/lib/commands.rb +2 -3
  15. data/lib/commands/command.rb +47 -20
  16. data/lib/commands/datas.rb +1 -1
  17. data/lib/commands/datas/composite.rb +5 -1
  18. data/lib/commands/datas/data.rb +102 -5
  19. data/lib/commands/datas/factory.rb +13 -6
  20. data/lib/commands/datas/temp.rb +3 -5
  21. data/lib/commands/factory.rb +1 -1
  22. data/lib/commands/helpers.rb +1 -1
  23. data/lib/commands/pipe.rb +10 -1
  24. data/lib/commands/runners.rb +1 -1
  25. data/lib/commands/runners/exec.rb +1 -1
  26. data/lib/commands/runners/fork.rb +3 -16
  27. data/lib/commands/runners/mock.rb +67 -0
  28. data/lib/commands/runners/runner.rb +5 -3
  29. data/lib/commands/runners/system.rb +1 -1
  30. data/lib/commands/seq.rb +2 -1
  31. data/lib/config_file.rb +10 -2
  32. data/lib/const_regexp.rb +1 -2
  33. data/lib/{dlogger.rb → d_logger.rb} +1 -2
  34. data/lib/daemon.rb +1 -2
  35. data/lib/diff.rb +1 -2
  36. data/lib/drb/drb_observable.rb +1 -2
  37. data/lib/drb/drb_observable_pool.rb +2 -2
  38. data/lib/drb/drb_service.rb +1 -2
  39. data/lib/drb/drb_undumped_attributes.rb +1 -2
  40. data/lib/drb/drb_undumped_indexed_object.rb +1 -2
  41. data/lib/drb/insecure_protected_methods.rb +1 -2
  42. data/lib/drb_ex.rb +2 -2
  43. data/lib/file_type.rb +466 -0
  44. data/lib/generate_id.rb +12 -6
  45. data/lib/genpasswd.rb +22 -0
  46. data/lib/hash_eval.rb +83 -0
  47. data/lib/histogram.rb +1 -2
  48. data/lib/hookable.rb +3 -4
  49. data/lib/hooker.rb +1 -3
  50. data/lib/html_encode.rb +191 -0
  51. data/lib/indexed_node.rb +0 -1
  52. data/lib/io_marshal.rb +4 -2
  53. data/lib/ioo.rb +3 -2
  54. data/lib/kill_all.rb +46 -0
  55. data/lib/labeled_node.rb +0 -1
  56. data/lib/logger_observer.rb +8 -4
  57. data/lib/md5sum.rb +3 -3
  58. data/lib/meta_factory.rb +99 -0
  59. data/lib/method_call.rb +87 -0
  60. data/lib/mocks.rb +12 -0
  61. data/lib/mocks/assertions.rb +50 -0
  62. data/lib/mocks/method_logger.rb +40 -0
  63. data/lib/mocks/mock.rb +64 -0
  64. data/lib/mocks/object.rb +47 -0
  65. data/lib/mocks/observer.rb +38 -0
  66. data/lib/module/autoload_tree.rb +30 -29
  67. data/lib/module/hierarchy.rb +176 -171
  68. data/lib/module/instance_method_visibility.rb +39 -38
  69. data/lib/node.rb +0 -1
  70. data/lib/object_monitor.rb +1 -2
  71. data/lib/object_monitor_activity.rb +1 -2
  72. data/lib/observable.rb +1 -2
  73. data/lib/observable_pool.rb +1 -2
  74. data/lib/{orderedhash.rb → ordered_hash.rb} +41 -5
  75. data/lib/pp_hierarchy.rb +7 -2
  76. data/lib/r_path.rb +307 -0
  77. data/lib/random_generators.rb +7 -20
  78. data/lib/random_generators/random_generator.rb +2 -4
  79. data/lib/random_generators/ruby.rb +4 -2
  80. data/lib/regex_path.rb +124 -0
  81. data/lib/ruby_ex.rb +28 -98
  82. data/lib/safe_eval.rb +1 -2
  83. data/lib/sendmail.rb +14 -17
  84. data/lib/service_manager.rb +1 -2
  85. data/lib/shuffle.rb +6 -2
  86. data/lib/spring.rb +1 -2
  87. data/lib/spring_set.rb +1 -2
  88. data/lib/{symtbl.rb → sym_tbl.rb} +90 -5
  89. data/lib/sym_tbl_gsub.rb +227 -0
  90. data/lib/{synflow.rb → syn_flow.rb} +1 -2
  91. data/lib/text.rb +218 -0
  92. data/lib/timeout_ex.rb +1 -2
  93. data/lib/trace.rb +9 -8
  94. data/lib/uri/druby.rb +1 -2
  95. data/lib/uri/file.rb +1 -1
  96. data/lib/uri/ftp_ex.rb +1 -1
  97. data/lib/uri/http_ex.rb +1 -1
  98. data/lib/uri/mysql.rb +121 -0
  99. data/lib/uri/pgsql.rb +19 -38
  100. data/lib/uri/svn.rb +1 -2
  101. data/lib/uri_ex.rb +45 -3
  102. data/lib/verbose_object.rb +181 -38
  103. data/lib/yaml/chop_header.rb +19 -11
  104. data/lib/yaml/transform.rb +17 -11
  105. data/lib/yaml/yregexpath.rb +11 -5
  106. data/test/algorithms/simulated_annealing_test.rb +2 -2
  107. data/test/resources/foo.tar.gz +0 -0
  108. data/test/resources/tar.gz.log +49 -0
  109. data/test/sanity-suite.yml +5 -7
  110. data/test/sanity/multiple-requires.yml +17 -7
  111. data/test/sanity/single-requires.yml +38 -20
  112. data/test/stress-tests/threads_and_exceptions.yml +13 -0
  113. data/test/test-unit-setup.rb +3 -1
  114. data/test/unit-suite.yml +7 -8
  115. metadata +42 -31
  116. data/lib/algorithms.rb +0 -12
  117. data/lib/ask.rb +0 -100
  118. data/lib/checkout.rb +0 -12
  119. data/lib/dumpable_proc.rb +0 -57
  120. data/lib/filetype.rb +0 -229
  121. data/lib/thread_mutex.rb +0 -11
  122. data/lib/yaml/basenode_ext.rb +0 -63
@@ -0,0 +1,102 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: auto_object.rb 339 2005-09-06 23:27:27Z ertai $
5
+
6
+ require 'blank_slate'
7
+ require 'verbose_object'
8
+
9
+ class AutoObject
10
+
11
+ def self.blank_slate_ignore ( name )
12
+ VerboseObject.blank_slate_ignore(name)
13
+ end
14
+
15
+ include BlankSlate
16
+ include Verbosify
17
+
18
+ def initialize ( opts=nil )
19
+ super(:auto_object, opts)
20
+ end
21
+
22
+ def inspect
23
+ "#<#{__blank_slate_class}: #{verbose_object_trace(:inspect)}>"
24
+ end
25
+
26
+ def to_s
27
+ verbose_object_trace(:to_s)
28
+ end
29
+ alias_method :to_str, :to_s
30
+
31
+ def verbose_object_empty_trace ( action=nil )
32
+ (action == :inspect)? "new" : "#{__blank_slate_class}.new"
33
+ end
34
+
35
+ def verbose_object_send ( m, *a, &b )
36
+ __blank_slate_class.new
37
+ end
38
+
39
+ def auto_object?
40
+ true
41
+ end
42
+
43
+ def respond_to? ( meth )
44
+ method_missing(:respond_to?, meth)
45
+ meth != :to_ary
46
+ end
47
+
48
+ end # class AutoObject
49
+
50
+
51
+ class Object
52
+
53
+ def auto_object?
54
+ false
55
+ end
56
+
57
+ end # class Object
58
+
59
+
60
+
61
+ test_section __FILE__ do
62
+ require 'mocks'
63
+ class TestAutoObject < ::Test::Unit::TestCase
64
+ include Mocks::Assertions
65
+
66
+ def setup
67
+ @mock_object = Mocks::MethodLogger.new
68
+ # Uncomment me to debug
69
+ # @mock_object = VerboseObject.new(@mock_object, :no_rec => true)
70
+ assert_nothing_raised do
71
+ @obj = AutoObject.new(:logger => @mock_object)
72
+ end
73
+ end
74
+
75
+ def test_simple
76
+ assert_nothing_raised { @obj.foo.bar(42).baz{}.qux * 42 - 5 }
77
+ end
78
+
79
+ def test_auto_object?
80
+ assert(! 4.auto_object?)
81
+ assert(@obj.auto_object?)
82
+ end
83
+
84
+ def test_verbose
85
+ assert_nothing_raised { @obj.foo.bar(42).baz{}.qux * 42 - 5 }
86
+ assert_mock [:foo], [:bar, 42], [:baz], [:qux], [:*, 42], [:-, 5]
87
+ end
88
+
89
+ def test_inspect
90
+ assert_nothing_raised { @res = @obj.foo.bar(42).baz{}.qux * 42 - 5 }
91
+ assert_equal '#<AutoObject: ((new.foo.bar(42).baz { ... }.qux * 42) - 5)>',
92
+ @res.inspect
93
+ end
94
+
95
+ def test_to_s
96
+ assert_nothing_raised { @res = @obj.foo.bar(42).baz{}.qux * 42 - 5 }
97
+ assert_equal '((AutoObject.new.foo.bar(42).baz { ... }.qux * 42) - 5)',
98
+ @res.to_s
99
+ end
100
+
101
+ end # class TestAutoObject
102
+ end
@@ -0,0 +1,102 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: blank_slate.rb 339 2005-09-06 23:27:27Z ertai $
5
+
6
+
7
+ # This module is inspired from BlankSlate of Jim Weirich.
8
+ #--
9
+ # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).
10
+ # All rights reserved.
11
+
12
+ # Permission is granted for use, copying, modification, distribution,
13
+ # and distribution of modified versions of this work as long as the
14
+ # above copyright notice is included.
15
+ #++
16
+
17
+
18
+ # BlankSlate alter your class and leave you a class with no
19
+ # predefined methods (except for those which begin with <tt>\_\_</tt>.
20
+ # BlankSlate is useful when for a base class which uses
21
+ # <tt>method_missing</tt> (e.g. dynamic proxies).
22
+ module BlankSlate
23
+
24
+ def blank_slate?
25
+ true
26
+ end
27
+
28
+ module ClassMethods
29
+
30
+ def hide ( name )
31
+ return unless instance_methods.include? name.to_s
32
+ return if blank_slate_ignore(name)
33
+ long = "__blank_slate_#{name}"
34
+ alias_method long, name unless instance_methods.include? long
35
+ undef_method name
36
+ end
37
+
38
+ def restore ( name )
39
+ long = "__blank_slate_#{name}"
40
+ if instance_methods.include? long
41
+ alias_method name, long
42
+ end
43
+ end
44
+
45
+ end # module ClassMethods
46
+
47
+ def self.included ( aClass )
48
+ aClass.extend ClassMethods
49
+ aClass.instance_methods.each { |m| aClass.hide(m) }
50
+ end
51
+
52
+ def self.extended ( anObject )
53
+ class << anObject
54
+ include ClassMethods
55
+ instance_methods.each do |name|
56
+ next if blank_slate_ignore(name)
57
+ alias_method "__blank_slate_#{name}", name
58
+ undef_method name
59
+ end
60
+ end
61
+ end
62
+
63
+ end # module BlankSlate
64
+
65
+
66
+ class Object
67
+
68
+ def self.blank_slate_ignore ( name )
69
+ name =~ /^(__|blank_slate\?$)/
70
+ end
71
+
72
+ def blank_slate?
73
+ false
74
+ end
75
+
76
+ end # class Object
77
+
78
+
79
+ # Since Ruby is very dynamic, methods added to the ancestors of
80
+ # BlankSlate <em>after BlankSlate is defined</em> will show up in the
81
+ # list of available BlankSlate methods. We handle this by defining a hook in the Object and Kernel classes that will hide any defined
82
+ # module Kernel #:nodoc:
83
+ # class << self
84
+ # alias_method :ruby_ex_blank_slate_method_added, :method_added
85
+ # def method_added(name)
86
+ # ruby_ex_blank_slate_method_added(name)
87
+ # return if self != Kernel
88
+ # BlankSlate.hide(name)
89
+ # end
90
+ # end
91
+ # end
92
+ #
93
+ # class Object #:nodoc:
94
+ # class << self
95
+ # alias_method :ruby_ex_blank_slate_method_added, :method_added
96
+ # def method_added(name)
97
+ # ruby_ex_blank_slate_method_added(name)
98
+ # return if self != Object
99
+ # BlankSlate.hide(name)
100
+ # end
101
+ # end
102
+ # end
data/lib/cache.rb CHANGED
@@ -3,10 +3,9 @@
3
3
  # License: Gnu General Public License.
4
4
 
5
5
  # $LastChangedBy: ertai $
6
- # $Id: cache.rb 279 2005-06-05 17:46:53Z ertai $
6
+ # $Id: cache.rb 339 2005-09-06 23:27:27Z ertai $
7
7
 
8
8
 
9
- require 'ruby_ex'
10
9
  require 'md5sum'
11
10
 
12
11
 
data/lib/choose.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:: GNU General Public License (GPL).
4
- # Revision:: $Id: choose.rb 279 2005-06-05 17:46:53Z ertai $
4
+ # Revision:: $Id: choose.rb 339 2005-09-06 23:27:27Z ertai $
5
5
 
6
6
 
7
7
  require 'random_generators'
@@ -83,189 +83,191 @@ class Range
83
83
 
84
84
  end # class Array
85
85
 
86
+ module Choose
86
87
 
88
+ test_section __FILE__ do
87
89
 
88
- test_section __FILE__ do
89
-
90
- class MockRandomGenerator < RandomGenerators::RandomGenerator
91
- concrete
92
- attr_reader :ref
93
- def initialize ( tab_i, tab_f )
94
- raise unless tab_i.is_a? Array
95
- raise unless tab_f.is_a? Array
96
- @ref, @ref_f, @pos = tab_i, tab_f, -1
97
- end
98
- def get ( tab )
99
- tab[@pos = (@pos + 1) % tab.size]
100
- end
101
- def choose_integer ( n )
102
- check_choose_integer(n)
103
- get(@ref) % n
104
- end
105
- def choose_float ( f=1.0 )
106
- check_choose_float(f)
107
- get(@ref_f) * f
108
- end
109
- end # class MockRandomGenerator
110
-
111
- class RandomMockRandomGenerator < MockRandomGenerator
112
- def initialize ( n )
113
- tab_i = (0 .. n - 1).to_a.shuffle
114
- tab_f = []
115
- n.times { tab_f << Float.choose() }
116
- super(tab_i, tab_f)
117
- end
118
- end # class RandomMockRandomGenerator
119
-
120
-
121
- require 'test/unit'
122
- require 'set'
123
-
124
- class ChooseTest < Test::Unit::TestCase
125
-
126
- REF_5 = [1, 2, 4, 0, 3]
127
- REF_F_5 = [0.187528345035389, 0.368857819121331, 0.06954449811019,
128
- 0.188887464581057, 0.213757352204993]
129
- REF_50 = [
130
- 28, 12, 17, 10, 1, 37, 46, 25, 47, 2, 45, 36, 20, 5, 30, 14, 18, 39,
131
- 8, 15, 16, 43, 27, 33, 22, 7, 32, 3, 35, 9, 19, 13, 21, 6, 23, 26, 4,
132
- 40, 44, 11, 49, 29, 42, 24, 31, 48, 34, 0, 38, 41
133
- ]
134
- REF_F_50 = [
135
- 0.643785412423313, 0.765736325876787, 0.604515956481919,
136
- 0.133839202811942, 0.350400971015915, 0.966710213804618,
137
- 0.904755113180727, 0.88459848286584, 0.163951952941716,
138
- 0.808023529592901, 0.387806572020054, 0.659689131658524,
139
- 0.289974238490686, 0.813535830006003, 0.565311754588038,
140
- 0.889200099511072, 0.0668127918615937, 0.992091996129602,
141
- 0.604403987759724, 0.89254002738744, 0.601499371463433,
142
- 0.754795648856089, 0.751190354581922, 0.434389552799985,
143
- 0.761369747575372, 0.174903159961104, 0.940325234550983,
144
- 0.536097376374528, 0.957906004507095, 0.693120914744213,
145
- 0.23448576242663, 0.638284107437357, 0.423910334473476,
146
- 0.251349127152935, 0.457931924844161, 0.20579389645718,
147
- 0.256057573715225, 0.584466924890876, 0.609375598141924,
148
- 0.0856487881392241, 0.437958877766505, 0.432312048738822,
149
- 0.81560374982655, 0.142059376928955, 0.118824432371184,
150
- 0.958816710859537, 0.69899930502288, 0.118259542621672,
151
- 0.52218786906451, 0.339233995880932
152
- ]
153
-
154
- def checker_n ( n, ref_i, ref_f, inp, ref, lim=nil )
155
- mrg = MockRandomGenerator.new(ref_i, ref_f)
156
- my = []
157
- if lim == :no
158
- n.times { my << inp.choose(mrg) }
159
- else
160
- n.times { my << inp.choose(lim, mrg) }
90
+ class MockRandomGenerator < RandomGenerators::RandomGenerator
91
+ concrete
92
+ attr_reader :ref
93
+ def initialize ( tab_i, tab_f )
94
+ raise unless tab_i.is_a? Array
95
+ raise unless tab_f.is_a? Array
96
+ @ref, @ref_f, @pos = tab_i, tab_f, -1
161
97
  end
162
- assert_equal(ref, my)
163
- end
164
-
165
- def checker_5 ( inp, ref, lim=nil )
166
- checker_n(5, REF_5, REF_F_5, inp, ref, lim)
167
- end
98
+ def get ( tab )
99
+ tab[@pos = (@pos + 1) % tab.size]
100
+ end
101
+ def choose_integer ( n )
102
+ check_choose_integer(n)
103
+ get(@ref) % n
104
+ end
105
+ def choose_float ( f=1.0 )
106
+ check_choose_float(f)
107
+ get(@ref_f) * f
108
+ end
109
+ end # class MockRandomGenerator
168
110
 
169
- def checker_50 ( inp, ref, lim=nil )
170
- checker_n(50, REF_50, REF_F_50, inp, ref, lim)
171
- end
111
+ class RandomMockRandomGenerator < MockRandomGenerator
112
+ def initialize ( n )
113
+ tab_i = (0 .. n - 1).to_a.shuffle
114
+ tab_f = []
115
+ n.times { tab_f << Float.choose() }
116
+ super(tab_i, tab_f)
117
+ end
118
+ end # class RandomMockRandomGenerator
119
+
120
+
121
+ require 'test/unit'
122
+ require 'set'
123
+
124
+ class ChooseTest < Test::Unit::TestCase
125
+
126
+ REF_5 = [1, 2, 4, 0, 3]
127
+ REF_F_5 = [0.187528345035389, 0.368857819121331, 0.06954449811019,
128
+ 0.188887464581057, 0.213757352204993]
129
+ REF_50 = [
130
+ 28, 12, 17, 10, 1, 37, 46, 25, 47, 2, 45, 36, 20, 5, 30, 14, 18, 39,
131
+ 8, 15, 16, 43, 27, 33, 22, 7, 32, 3, 35, 9, 19, 13, 21, 6, 23, 26, 4,
132
+ 40, 44, 11, 49, 29, 42, 24, 31, 48, 34, 0, 38, 41
133
+ ]
134
+ REF_F_50 = [
135
+ 0.643785412423313, 0.765736325876787, 0.604515956481919,
136
+ 0.133839202811942, 0.350400971015915, 0.966710213804618,
137
+ 0.904755113180727, 0.88459848286584, 0.163951952941716,
138
+ 0.808023529592901, 0.387806572020054, 0.659689131658524,
139
+ 0.289974238490686, 0.813535830006003, 0.565311754588038,
140
+ 0.889200099511072, 0.0668127918615937, 0.992091996129602,
141
+ 0.604403987759724, 0.89254002738744, 0.601499371463433,
142
+ 0.754795648856089, 0.751190354581922, 0.434389552799985,
143
+ 0.761369747575372, 0.174903159961104, 0.940325234550983,
144
+ 0.536097376374528, 0.957906004507095, 0.693120914744213,
145
+ 0.23448576242663, 0.638284107437357, 0.423910334473476,
146
+ 0.251349127152935, 0.457931924844161, 0.20579389645718,
147
+ 0.256057573715225, 0.584466924890876, 0.609375598141924,
148
+ 0.0856487881392241, 0.437958877766505, 0.432312048738822,
149
+ 0.81560374982655, 0.142059376928955, 0.118824432371184,
150
+ 0.958816710859537, 0.69899930502288, 0.118259542621672,
151
+ 0.52218786906451, 0.339233995880932
152
+ ]
153
+
154
+ def checker_n ( n, ref_i, ref_f, inp, ref, lim=nil )
155
+ mrg = MockRandomGenerator.new(ref_i, ref_f)
156
+ my = []
157
+ if lim == :no
158
+ n.times { my << inp.choose(mrg) }
159
+ else
160
+ n.times { my << inp.choose(lim, mrg) }
161
+ end
162
+ assert_equal(ref, my)
163
+ end
172
164
 
165
+ def checker_5 ( inp, ref, lim=nil )
166
+ checker_n(5, REF_5, REF_F_5, inp, ref, lim)
167
+ end
173
168
 
169
+ def checker_50 ( inp, ref, lim=nil )
170
+ checker_n(50, REF_50, REF_F_50, inp, ref, lim)
171
+ end
174
172
 
175
173
 
176
- def test_integer
177
- checker_5 Integer, REF_5, 5
178
- checker_50 Integer, REF_50, 50
179
- assert(Integer.choose(1000) < 1000)
180
- end
181
174
 
182
- def test_float
183
- checker_5 Float, REF_F_5, 1.0
184
- checker_50 Float, REF_F_50, 1.0
185
- assert(Float.choose(2.0) < 2)
186
- assert(Float.choose < 1)
187
- end
188
175
 
189
- def test_array_5
190
- checker_5 [4], [4] * 5, 5
191
- checker_5 [4, 5], [5, 4, 4, 4, 5], 5
192
- checker_5 [4, 5, 6], [5, 6, 5, 4, 4], 5
193
- checker_5 [2, 1, 0, 5, 4, 3], [1, 0, 4, 2, 5], 5
194
- 10.times { assert(REF_50.include?(REF_50.choose)) }
195
- end
176
+ def test_integer
177
+ checker_5 Integer, REF_5, 5
178
+ checker_50 Integer, REF_50, 50
179
+ assert(Integer.choose(1000) < 1000)
180
+ end
196
181
 
197
- def test_set_5
198
- checker_5 Set[4], [4] * 5, 5
199
- checker_5 Set[4, 5], [4, 5, 5, 5, 4], 5
200
- checker_5 Set[4, 5, 6], [6, 4, 6, 5, 5], 5
201
- checker_5 Set[2, 1, 0, 5, 4, 3], [0, 1, 3, 5, 2], 5
202
- set = REF_50.to_set
203
- 10.times { assert(set.include?(set.choose)) }
204
- end
182
+ def test_float
183
+ checker_5 Float, REF_F_5, 1.0
184
+ checker_50 Float, REF_F_50, 1.0
185
+ assert(Float.choose(2.0) < 2)
186
+ assert(Float.choose < 1)
187
+ end
205
188
 
206
- def test_hash
207
- checker_5({ 1 => 2 }, [2] * 5, 5)
208
- checker_5({ 1 => 2, 3 => 4 }, [4, 2, 2, 2, 4], 5)
209
- end
189
+ def test_array_5
190
+ checker_5 [4], [4] * 5, 5
191
+ checker_5 [4, 5], [5, 4, 4, 4, 5], 5
192
+ checker_5 [4, 5, 6], [5, 6, 5, 4, 4], 5
193
+ checker_5 [2, 1, 0, 5, 4, 3], [1, 0, 4, 2, 5], 5
194
+ 10.times { assert(REF_50.include?(REF_50.choose)) }
195
+ end
210
196
 
211
- def test_array_50
212
- checker_50 [4], [4] * 50, 50
213
- checker_50 [
214
- 36, 16, 15, 6, 27, 33, 17, 10, 18, 39, 8, 43, 19, 23, 49, 40, 46, 37,
215
- 9, 41, 35, 0, 38, 26, 22, 4, 7, 25, 21, 12, 42, 45, 28, 5, 31, 24, 34,
216
- 48, 32, 30, 13, 29, 11, 2, 1, 20, 3, 44, 47, 14
217
- ], [
218
- 21, 19, 37, 8, 16, 48, 3, 4, 44, 15, 20, 34, 35, 33, 42, 49, 9, 30,
219
- 18, 40, 46, 2, 25, 5, 38, 10, 28, 6, 24, 39, 41, 23, 0, 17, 26, 7, 27,
220
- 13, 1, 43, 14, 12, 11, 22, 45, 47, 31, 36, 32, 29
221
- ], 50
222
- end
197
+ def test_set_5
198
+ checker_5 Set[4], [4] * 5, 5
199
+ checker_5 Set[4, 5], [4, 5, 5, 5, 4], 5
200
+ checker_5 Set[4, 5, 6], [6, 4, 6, 5, 5], 5
201
+ checker_5 Set[2, 1, 0, 5, 4, 3], [0, 1, 3, 5, 2], 5
202
+ set = REF_50.to_set
203
+ 10.times { assert(set.include?(set.choose)) }
204
+ end
223
205
 
224
- def test_integer_instances
225
- assert_raise(ArgumentError) { checker_5 0, [], :no }
226
- checker_5 1, [0] * 5, :no
227
- checker_5 4, [1, 2, 0, 0, 3], :no
228
- checker_5 10, REF_5, :no
229
- assert(1000.choose < 1000)
230
- end
206
+ def test_hash
207
+ checker_5({ 1 => 2 }, [2] * 5, 5)
208
+ checker_5({ 1 => 2, 3 => 4 }, [4, 2, 2, 2, 4], 5)
209
+ end
231
210
 
232
- def test_float_instances
233
- assert_raise(ArgumentError) { checker_5 0.0, [], :no }
234
- checker_5 1.0, [ 0.187528345035389, 0.368857819121331, 0.06954449811019,
235
- 0.188887464581057, 0.213757352204993 ], :no
236
- assert(2.0.choose < 2)
237
- end
211
+ def test_array_50
212
+ checker_50 [4], [4] * 50, 50
213
+ checker_50 [
214
+ 36, 16, 15, 6, 27, 33, 17, 10, 18, 39, 8, 43, 19, 23, 49, 40, 46, 37,
215
+ 9, 41, 35, 0, 38, 26, 22, 4, 7, 25, 21, 12, 42, 45, 28, 5, 31, 24, 34,
216
+ 48, 32, 30, 13, 29, 11, 2, 1, 20, 3, 44, 47, 14
217
+ ], [
218
+ 21, 19, 37, 8, 16, 48, 3, 4, 44, 15, 20, 34, 35, 33, 42, 49, 9, 30,
219
+ 18, 40, 46, 2, 25, 5, 38, 10, 28, 6, 24, 39, 41, 23, 0, 17, 26, 7, 27,
220
+ 13, 1, 43, 14, 12, 11, 22, 45, 47, 31, 36, 32, 29
221
+ ], 50
222
+ end
238
223
 
239
- def test_integer_range_instances
240
- checker_5 1..1, [1] * 5, :no
241
- checker_5 1..2, [2, 1, 1, 1, 2], :no
242
- checker_5 0..1, [1, 0, 0, 0, 1], :no
243
- checker_5 0..4, [1, 2, 4, 0, 3], :no
244
- end
224
+ def test_integer_instances
225
+ assert_raise(ArgumentError) { checker_5 0, [], :no }
226
+ checker_5 1, [0] * 5, :no
227
+ checker_5 4, [1, 2, 0, 0, 3], :no
228
+ checker_5 10, REF_5, :no
229
+ assert(1000.choose < 1000)
230
+ end
245
231
 
246
- class Xs
247
- include Comparable
248
- attr_reader :length
249
- def initialize ( n )
250
- @length = n
232
+ def test_float_instances
233
+ assert_raise(ArgumentError) { checker_5 0.0, [], :no }
234
+ checker_5 1.0, [ 0.187528345035389, 0.368857819121331, 0.06954449811019,
235
+ 0.188887464581057, 0.213757352204993 ], :no
236
+ assert(2.0.choose < 2)
251
237
  end
252
- def succ
253
- Xs.new(@length.succ)
238
+
239
+ def test_integer_range_instances
240
+ checker_5 1..1, [1] * 5, :no
241
+ checker_5 1..2, [2, 1, 1, 1, 2], :no
242
+ checker_5 0..1, [1, 0, 0, 0, 1], :no
243
+ checker_5 0..4, [1, 2, 4, 0, 3], :no
254
244
  end
255
- def <=> ( rhs )
256
- @length <=> rhs.length
245
+
246
+ class Xs
247
+ include Comparable
248
+ attr_reader :length
249
+ def initialize ( n )
250
+ @length = n
251
+ end
252
+ def succ
253
+ Xs.new(@length.succ)
254
+ end
255
+ def <=> ( rhs )
256
+ @length <=> rhs.length
257
+ end
258
+ def inspect
259
+ 'x' * @length
260
+ end
257
261
  end
258
- def inspect
259
- 'x' * @length
262
+
263
+ def test_range_instances
264
+ checker_5 'a'..'a', ['a'] * 5, :no
265
+ checker_5 'a'..'b', ['b', 'a', 'a', 'a', 'b'], :no
266
+ checker_5 Xs.new(1)..Xs.new(4), [2, 3, 1, 1, 4].map { |x| Xs.new(x) }, :no
260
267
  end
261
- end
262
268
 
263
- def test_range_instances
264
- checker_5 'a'..'a', ['a'] * 5, :no
265
- checker_5 'a'..'b', ['b', 'a', 'a', 'a', 'b'], :no
266
- checker_5 Xs.new(1)..Xs.new(4), [2, 3, 1, 1, 4].map { |x| Xs.new(x) }, :no
267
- end
269
+ end # class ChooseTest
268
270
 
269
- end # class ChooseTest
271
+ end
270
272
 
271
- end
273
+ end # module Choose