sequence 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test.rb ADDED
@@ -0,0 +1,609 @@
1
+ #eric's original test code; I can't say I understand it
2
+ BEGIN{exit}
3
+ # $Id$
4
+
5
+ require 'test/unit'
6
+ require 'sequence'
7
+ require 'sequence/usedeleteinsert'
8
+
9
+ # :stopdoc:
10
+
11
+ module Test
12
+ module Unit
13
+ class TestSuite
14
+ def run(result, &progress_block)
15
+ yield(STARTED, name)
16
+ if @tests.size>0 and @tests[0].class.respond_to?:random
17
+ catch(:stop_suite) {
18
+ (@tests[0].class.random*@tests.size).to_i.times do
19
+ test = @tests[rand(@tests.size)]
20
+ catch(:invalid_test) {
21
+ test.run(result, &progress_block)
22
+ }
23
+ end
24
+ }
25
+ else
26
+ @tests.each do |test|
27
+ test.run(result, &progress_block)
28
+ end
29
+ end
30
+ yield(FINISHED, name)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ ArgArray = Class.new(Array)
37
+
38
+ class Sequence
39
+ class Test < ::Test::Unit::TestCase
40
+ def self.suite(random_iterations=8,random_seed=0,klass='',methods='',flags=0)
41
+ return(::Test::Unit::TestSuite.new()) if !self.respond_to?:seed
42
+ if !(@@output_level||=nil)
43
+ @@output_level = ::Test::Unit::UI::SILENT
44
+ ObjectSpace.each_object(::Test::Unit::AutoRunner) { |runner|
45
+ @@output_level = runner.instance_eval { @output_level }
46
+ }
47
+ end
48
+ if !(@@random_iterations||=nil)
49
+ @@random_iterations = random_iterations.to_f
50
+ end
51
+ if !(@@random_seed||=nil)
52
+ @@random_seed = random_seed.to_i.nonzero? || (srand;srand)
53
+ puts("random_seed: #{@@random_seed}") if @@output_level>=::Test::Unit::UI::NORMAL
54
+ srand(@@random_seed)
55
+ end
56
+ @klass = Regexp.new(klass)
57
+ methods = Regexp.new(methods)
58
+ @reject ||= nil
59
+ public_instance_methods(true).each { |m|
60
+ if matchdata = /^test_\d*(.*)/.match(m.to_s)
61
+ undef_method(m) if @reject&&@reject=~matchdata[1] ||
62
+ !(methods=~matchdata[1])
63
+ end
64
+ }
65
+ @flags = flags.to_i
66
+ @use_positions = @flags[0].zero?
67
+ @use_branches = true
68
+ @allow_pruning = false
69
+ self.plant
70
+ super()
71
+ end
72
+ def self.plant
73
+ before = sequence(0,1.5)
74
+ after = sequence(0,1.5,before.class.new)
75
+ seqs = seed(before,after)
76
+ if @klass
77
+ seqs.reject! { |seq| !(@klass===seq.class.to_s) }
78
+ end
79
+ return(self.plant) if seqs.empty?
80
+ if @@output_level>=::Test::Unit::UI::NORMAL
81
+ puts("\nnew(#{before.inspect}+#{after.inspect}) -> self")
82
+ end
83
+ @seqs_root = {
84
+ :trunk => seqs,
85
+ :positions => [],
86
+ :branches => [],
87
+ }
88
+ end
89
+ def self.element(offset=0,weight=1)
90
+ elements[rand((weight*(elements.size+offset)).to_i)]
91
+ end
92
+ def self.sequence(offset=0,weight=2,value=empty)
93
+ until (v = element(offset,weight)).nil?
94
+ value << v
95
+ end
96
+ value
97
+ end
98
+ def self.random
99
+ @@random_iterations
100
+ end
101
+ def self.reject(name,*args,&block)
102
+ false
103
+ end
104
+ def setup
105
+ seqs_tree = self.class.instance_eval{@seqs_root}
106
+ level = 0
107
+ @prune = proc{}
108
+ while (branches = seqs_tree[:branches]).size.nonzero? and
109
+ self.class.instance_eval{@use_branches}&&rand(3).zero?
110
+ i = rand(branches.size)
111
+
112
+ if _closed?(branches[i][:trunk])
113
+ branches.slice!(i)
114
+ break
115
+ else
116
+ @prune = proc { branches.slice!(i) }
117
+ seqs_tree = branches[i]
118
+ level += 1
119
+ end
120
+ end
121
+ if (positions = seqs_tree[:positions]).size.nonzero? and
122
+ self.class.instance_eval{@use_positions}&&rand(3).zero?
123
+ i = rand(positions.size)
124
+ if _closed?(positions[i])
125
+ positions.slice!(i)
126
+ else
127
+ @prune = proc { positions.slice!(i) }
128
+ seqs_tree = {
129
+ :trunk => positions[i],
130
+ :positions => seqs_tree[:positions],
131
+ :branches => seqs_tree[:branches],
132
+ }
133
+ level += 1
134
+ end
135
+ end
136
+ @seqs_tree = seqs_tree
137
+ @seqs = seqs_tree[:trunk]
138
+ @positions = seqs_tree[:positions]
139
+ @branches = seqs_tree[:branches]
140
+ @level = level
141
+ @state = ""
142
+ @exec = nil
143
+ end
144
+ def teardown
145
+ if not passed?
146
+ if @@output_level>=::Test::Unit::UI::PROGRESS_ONLY
147
+ puts("\n#{self}")
148
+ puts("random_seed: #{@@random_seed}")
149
+ puts(@call)
150
+ end
151
+ throw(:stop_suite)
152
+ end
153
+ end
154
+
155
+ private
156
+ def _closed?(seqs)
157
+ ret0 = nil
158
+ seqs.each_with_index { |seq,i|
159
+ i==0 ? ret0 = seq.closed? : assert_equal(ret0,seq.closed?)
160
+ }
161
+ ret0
162
+ end
163
+ def _inspect_short(obj,_self=nil)
164
+ if _self and _self.equal?(obj)
165
+ "self"
166
+ else
167
+ obj.inspect.sub(/\A\#\<([\w\:]+?\:0x[\da-f]+).*\>\Z/,'#<\\1>')
168
+ end
169
+ end
170
+ def _inspect_self(obj,_self=nil)
171
+ if _self and _self.equal?(obj)
172
+ "self"
173
+ else
174
+ obj.inspect
175
+ end
176
+ end
177
+ def _inspect_merge(objects,selves=nil)
178
+ _inspect_short(objects[0],selves&&selves[0])
179
+ end
180
+ def _multi_test(name,*args0,&assertion)
181
+ block = args0.pop
182
+ throw(:invalid_test) if self.class.reject(name,*args0,&block)
183
+ seqs = @seqs
184
+ call = @level.zero? ? "self." : "#{_inspect_merge(@seqs)}."
185
+ call += "{" if @exec
186
+ call += name.to_s
187
+ args = args0.collect { |arg|
188
+ ArgArray===arg ? _inspect_merge(arg) : _inspect_short(arg)
189
+ }
190
+ call += "(#{args.join(',')})" if not args.empty?
191
+ call += " {#{block.inspect.sub(/\A\#<Proc\:0x[\da-f]+\@(.*?)\>\Z/,'\\1')}}" if block
192
+ call += "}" if @exec
193
+ @call = call
194
+ print("\n#{call} ") if @@output_level==::Test::Unit::UI::NORMAL
195
+ state = @state
196
+ ret = ArgArray.new
197
+ puts if @@output_level>=::Test::Unit::UI::VERBOSE
198
+ @seqs.each_with_index do |seq,i|
199
+ @state = state.clone
200
+ initial = seq.inspect
201
+ args = args0.collect { |arg|
202
+ ArgArray===arg ? arg[i] :
203
+ begin
204
+ arg.clone
205
+ rescue TypeError
206
+ arg
207
+ end
208
+ }
209
+ call = ""
210
+ call += "{" if @exec
211
+ call += name.to_s
212
+ call += "(#{args.inspect[1..-2]})" if not args.empty?
213
+ call += " #{block.inspect}" if block
214
+ call += "}" if @exec
215
+ if @@output_level>=::Test::Unit::UI::VERBOSE
216
+ puts(initial)
217
+ print("#{call} ")
218
+ end
219
+ @seq = seq
220
+ if @exec
221
+ ret << @exec.call(seq,name,*args,&block)
222
+ else
223
+ ret << seq.__send__(name,*args,&block)
224
+ end
225
+ message = [initial,call,seq.inspect].join("\n")
226
+ puts("-> #{_inspect_self(ret[-1],seq)}") if @@output_level>=::Test::Unit::UI::VERBOSE
227
+ #puts(seq.inspect) if @@output_level>=::Test::Unit::UI::VERBOSE
228
+ assertion[i,ret[-1],seq,message]
229
+ end
230
+ @call += "-> #{_inspect_merge(ret,@seqs)}"
231
+ print("-> #{_inspect_merge(ret,@seqs)}") if @@output_level==::Test::Unit::UI::NORMAL
232
+ @prune[] if self.class.instance_eval{@allow_pruning}&&rand(2).zero?
233
+ ret
234
+ end
235
+ def _test_equal(name,*args,&block)
236
+ ret0 = nil
237
+ _multi_test(name,*(args << block)) {
238
+ |i,ret,seq,message|
239
+ i==0 ? ret0 = ret : assert_equal(ret0,ret,message)
240
+ }
241
+ end
242
+ def _test_matchdata(name,*args,&block)
243
+ ret0 = nil
244
+ _multi_test(name,*(args << block)) {
245
+ |i,ret,seq,message|
246
+ if i==0
247
+ ret0 = ret
248
+ elsif ret0.nil?
249
+ assert_nil(ret)
250
+ else
251
+ assert_equal(ret0.to_a,ret.to_a)
252
+ end
253
+ }
254
+ end
255
+ def _test_match(name,*args,&block)
256
+ ret0 = nil
257
+ _multi_test(name,*(args << block)) {
258
+ |i,ret,seq,message|
259
+ if i==0
260
+ ret0 = ret
261
+ elsif ret0.nil?
262
+ assert_nil(ret)
263
+ else
264
+ assert_equal(ret0[0,ret0.size-1],ret[0,ret.size-1])
265
+ end
266
+ }
267
+ end
268
+ def _exec_position?(seq,name,*args,&block)
269
+ seq.position? { seq.__send__(name,*args,&block) }
270
+ end
271
+ def _test_position?(name,*args,&block)
272
+ ret0 = nil
273
+ @exec = method(:_exec_position?)
274
+ _multi_test(name,*(args << block)) {
275
+ |i,ret,seq,message|
276
+ i==0 ? ret0 = ret : assert_equal(ret0,ret,message)
277
+ }
278
+ end
279
+ def _test_self(name,*args,&block)
280
+ ret0 = nil
281
+ _multi_test(name,*(args << block)) {
282
+ |i,ret,seq,message|
283
+ ret0 = ret||nil if i==0
284
+ assert_same(ret0&&seq,ret,message)
285
+ }
286
+ end
287
+ def _test_position(name,*args,&block)
288
+ new_seqs = ArgArray.new
289
+ ret0 = nil
290
+ _multi_test(name,*(args << block)) {
291
+ |i,ret,seq,message|
292
+ ret0 = ret if i==0
293
+ if not ret0
294
+ assert_nil(ret,message)
295
+ else
296
+ assert_not_nil(ret,message)
297
+ new_seqs << ret
298
+ end
299
+ }
300
+ @positions << new_seqs if ret0
301
+ end
302
+ def _test_branch(name,*args,&block)
303
+ new_seqs = ArgArray.new
304
+ ret0 = nil
305
+ _multi_test(name,*(args << block)) {
306
+ |i,ret,seq,message|
307
+ ret0 = ret if i==0
308
+ if not ret0
309
+ assert_nil(ret,message)
310
+ else
311
+ assert_not_nil(ret,message)
312
+ new_seqs << ret
313
+ end
314
+ }
315
+ @branches << {
316
+ :trunk => new_seqs,
317
+ :positions => [],
318
+ :branches => [],
319
+ } if ret0
320
+ end
321
+ def _test_close(name,*args,&block)
322
+ ret0 = nil
323
+ _multi_test(name,*(args << block)) {
324
+ |i,ret,seq,message|
325
+ i==0 ? ret0 = ret : assert_equal(ret0,ret,message)
326
+ }
327
+ assert_same(true,_closed?(@seqs))
328
+ if @level==0
329
+ self.class.plant
330
+ end
331
+ ret0
332
+ end
333
+
334
+
335
+ def _opt(*args,&block)
336
+ args = args[0,rand(args.size+1)]
337
+ block and rand(2).zero? and args << block[]
338
+ args
339
+ end
340
+ def _ornil(arg)
341
+ rand(2).zero? ? arg : nil
342
+ end
343
+ # responds to ==element
344
+ def _element
345
+ self.class.element
346
+ end
347
+ # responds to ==element
348
+ def _scan_element
349
+ self.class.element
350
+ end
351
+ # responds to [element]
352
+ def _replacer
353
+ lookup = {}
354
+ self.class.elements.each { |e|
355
+ lookup[e] = self.class.element(1)
356
+ }
357
+ lookup
358
+ end
359
+ # responds to <(int), abs (which responds to >(int))
360
+ def _len
361
+ rand(5)-2
362
+ end
363
+ # responds to if and the like (everything)
364
+ def _boolean
365
+ rand(2).zero?
366
+ end
367
+ def _booleannil
368
+ case rand(3)
369
+ when 0 then false
370
+ when 1 then true
371
+ when 2 then nil
372
+ end
373
+ end
374
+ # responds to [int]
375
+ def _read_sequence
376
+ self.class.sequence(0,3)
377
+ end
378
+ # responds to <<element
379
+ def _write_sequence
380
+ self.class.sequence
381
+ end
382
+ # responds to [Integer] returning ==element responder
383
+ def _scan_sequence
384
+ self.class.sequence
385
+ end
386
+ # responds to [Integer] returning ==element responder
387
+ def _scan_sequence
388
+ self.class.sequence
389
+ end
390
+ # responds to [Integer] returning ==element responder
391
+ def _each_sequence
392
+ value = self.class.empty
393
+ value << self.class.element
394
+ while v = self.class.element(0,2)
395
+ value << v
396
+ end
397
+ value
398
+ end
399
+ # responds to [int]
400
+ def _read_pattern_sequence
401
+ self.class.sequence(0,3,"")
402
+ rescue TypeError
403
+ throw(:invalid_test)
404
+ end
405
+ def _pattern(variable)
406
+ n = 0
407
+ seq1 = self.class.sequence(0,2,"")
408
+ n = seq1.size
409
+ seq1 = Regexp.escape(seq1)
410
+ if n>=1 and rand(2).zero?
411
+ seq1 = "[#{seq1}]"
412
+ n = 1
413
+ end
414
+ alt1 = self.class.sequence(0,2,"")
415
+ alt2 = self.class.sequence(0,2,"")
416
+ n += alt1.size>alt2.size ? alt1.size : alt2.size
417
+ alt1 = Regexp.escape(alt1)
418
+ alt2 = Regexp.escape(alt2)
419
+ if alt1.empty?
420
+ if alt2.empty?
421
+ seq2 = ""
422
+ else
423
+ seq2 = "(#{alt2})?"
424
+ end
425
+ else
426
+ if alt2.empty?
427
+ seq2 = "(#{alt1})?"
428
+ else
429
+ if alt1[0]==alt2[0]
430
+ seq2 = alt1
431
+ else
432
+ seq2 = "(#{alt1}|#{alt2})"
433
+ end
434
+ end
435
+ end
436
+ if rand(2).zero?
437
+ pat = seq1+seq2
438
+ else
439
+ pat = seq2+seq1
440
+ end
441
+ pat = "(?:#{pat})*" if variable
442
+ pat = '\A'+pat if false==variable && rand(2).zero?
443
+ pat = Regexp.new(pat)
444
+ n += rand(2)
445
+ n = -n if rand(2).zero?
446
+ [pat,n]
447
+ rescue TypeError
448
+ throw(:invalid_test)
449
+ end
450
+ def _pos
451
+ pos = rand(
452
+ self.class.instance_eval{@seqs_root}[:trunk][0].size.abs.to_i+1
453
+ )
454
+ rand(2).zero? ? -(pos.nonzero?||0.0) : pos
455
+ end
456
+ def _prop_name
457
+ rand(2).zero? ? :first : :last
458
+ end
459
+ def _prop_value
460
+ rand(2).zero? ? "john" : "henry"
461
+ end
462
+ def _indexedwrite
463
+ args = [_ornil(_pos)]
464
+ args << _len if rand(2).zero?
465
+ args << (args[1] ? _write_sequence : _element)
466
+ end
467
+ def _anyposition
468
+ i = rand(@positions.size.nonzero?||throw(:invalid_test))
469
+ @positions[i]
470
+ end
471
+ def _position
472
+ i = rand(@positions.size.nonzero?||throw(:invalid_test))
473
+ if _closed?(@positions[i])
474
+ @positions.slice!(i)
475
+ throw(:invalid_test)
476
+ end
477
+ @positions[i]
478
+ end
479
+ def _deleteposition
480
+ i = rand(@positions.size.nonzero?||throw(:invalid_test))
481
+ if _closed?(@positions[i])
482
+ @positions.slice!(i)
483
+ throw(:invalid_test)
484
+ end
485
+ @positions.slice!(i)
486
+ end
487
+ def _each_code
488
+ proc { |v0| nil } # what to do?
489
+ end
490
+ def _each2_code
491
+ proc { |v0| nil } # what to do?
492
+ end
493
+ def _collect_code
494
+ lookup = {}
495
+ elements = self.class.elements
496
+ elements.each_with_index { |e,i|
497
+ lookup[e] = elements[i+1]
498
+ }
499
+ proc { |v0| lookup[v0] }
500
+ end
501
+ def _collect2_code
502
+ proc { |v0| v0.slice!(0);v0 }
503
+ end
504
+ def _position_code
505
+ elements = self.class.elements
506
+ proc {
507
+ @seq.scan1next(elements[0]) ||
508
+ @seq.position? { @seq.read1next==elements[1] }
509
+ }
510
+ end
511
+ def _pos_code
512
+ elements = self.class.elements
513
+ proc {
514
+ @seq.scan1next(elements[0]) ||
515
+ @seq.position? { @seq.read1next==elements[1] }
516
+ }
517
+ end
518
+
519
+
520
+ public
521
+ define_method("test_delete1after?" ){_test_equal(:delete1after?)}
522
+ define_method("test_delete1before?"){_test_equal(:delete1before?)}
523
+ define_method("test_insert1before" ){_test_equal(:insert1before,_element)}
524
+ define_method("test_insert1after" ){_test_equal(:insert1after,_element)}
525
+ define_method("test_read1next" ){_test_equal(:read1next)}
526
+ define_method("test_read1prev" ){_test_equal(:read1prev)}
527
+ define_method("test_write1next!" ){_test_equal(:write1next!,_element)}
528
+ define_method("test_write1prev!" ){_test_equal(:write1prev!,_element)}
529
+ define_method("test_write1next" ){_test_equal(:write1next,_element)}
530
+ define_method("test_write1prev" ){_test_equal(:write1prev,_element)}
531
+ define_method("test_skip1next" ){_test_equal(:skip1next)}
532
+ define_method("test_skip1prev" ){_test_equal(:skip1prev)}
533
+ define_method("test_delete1after" ){_test_equal(:delete1after)}
534
+ define_method("test_delete1before" ){_test_equal(:delete1before)}
535
+ define_method("test_read1after" ){_test_equal(:read1after)}
536
+ define_method("test_read1before" ){_test_equal(:read1before)}
537
+ define_method("test_write1next?" ){_test_equal(:write1next?,_element)}
538
+ define_method("test_write1prev?" ){_test_equal(:write1prev?,_element)}
539
+ define_method("test_write1after!" ){_test_equal(:write1after!,_element)}
540
+ define_method("test_write1before!" ){_test_equal(:write1before!,_element)}
541
+ define_method("test_write1after" ){_test_equal(:write1after,_element)}
542
+ define_method("test_write1before" ){_test_equal(:write1before,_element)}
543
+ define_method("test_skip1after" ){_test_equal(:skip1after)}
544
+ define_method("test_skip1before" ){_test_equal(:skip1before)}
545
+ define_method("test_write1after?" ){_test_equal(:write1after?,_element)}
546
+ define_method("test_write1before?" ){_test_equal(:write1before?,_element)}
547
+ define_method("test_scan1next" ){_test_equal(:scan1next,_scan_element)}
548
+ define_method("test_scan1prev" ){_test_equal(:scan1prev,_scan_element)}
549
+ define_method("test_modify1next" ){_test_equal(:modify1next,_replacer)}
550
+ define_method("test_modify1prev" ){_test_equal(:modify1prev,_replacer)}
551
+ define_method("test_read" ){_test_equal(:read,_len,*_opt(_booleannil,_read_sequence))}
552
+ define_method("test_read!" ){_test_equal(:read!,*_opt(_boolean,_booleannil,_read_sequence))}
553
+ define_method("test_skip" ){_test_equal(:skip,_len,*_opt(_booleannil))}
554
+ define_method("test_skip!" ){_test_equal(:skip!,*_opt(_boolean,_booleannil))}
555
+ define_method("test_write" ){_test_equal(:write,_write_sequence,*_opt(_boolean,_booleannil,_boolean))}
556
+ define_method("test_write?" ){_test_equal(:write?,_write_sequence,*_opt(_boolean,_boolean,_read_sequence))}
557
+ define_method("test_scan" ){_test_equal(:scan,_scan_sequence,*_opt(_boolean,_booleannil,_read_sequence))}
558
+ define_method("test_scan_until" ){_test_equal(:scan_until,_scan_sequence,*_opt(_boolean,_booleannil,_read_sequence))}
559
+ define_method("test_1scan_pattern"){_test_equal(:scan_pattern,*(_pattern(false)+_opt(_boolean)))}
560
+ define_method("test_2scan_pattern"){_test_matchdata(:scan_pattern,*(_pattern(false) << _boolean << _read_pattern_sequence))}
561
+ define_method("test_1scan_pattern_until"){_test_equal(:scan_pattern_until,*(_pattern(nil)+_opt(_boolean)))}
562
+ define_method("test_2scan_pattern_until"){_test_match(:scan_pattern_until,*(_pattern(nil)+[_boolean]+[_read_pattern_sequence]+_opt(rand(2))))}
563
+ define_method("test_scan_pattern_while"){_test_equal(:scan_pattern_while,*(_pattern(true)+_opt(_boolean,_read_pattern_sequence,rand(2))))}
564
+ define_method("test_1pos" ){_test_equal(:pos,*_opt(_boolean))}
565
+ define_method("test_2pos" ){_test_equal(:pos,*_opt(_boolean),&_pos_code)}
566
+ define_method("test_pos=" ){_test_equal(:pos=,_pos)}
567
+ define_method("test_1pos?" ){_test_equal(:pos?,_pos+rand(5)-2)}
568
+ define_method("test_2pos?" ){_test_equal(:pos?,*_opt(_boolean),&_pos_code)}
569
+ define_method("test_to_i" ){_test_equal(:to_i)}
570
+ define_method("test_to_s" ){_test_equal(:to_s)}
571
+ define_method("test_prop" ){_test_equal(:prop,_prop_name,*_opt(_prop_value))}
572
+ define_method("test_closed?" ){_test_equal(:closed?)}
573
+ define_method("test_close" ){_test_close(:close)}
574
+ define_method("test_1position" ){_test_position(:position,*_opt(_boolean))}
575
+ define_method("test_2position" ){_test_equal(:position,*_opt{_boolean},&_position_code)}
576
+ define_method("test_position=" ){_test_equal(:position=,_position)}
577
+ define_method("test_1position?" ){_test_equal(:position?,_anyposition)}
578
+ define_method("test_2position?" ){_test_equal(:position?,*_opt{_boolean},&_position_code)}
579
+ define_method("test_<=>" ){_test_equal(:<=>,_position)}
580
+ define_method("test_-" ){_test_equal(:-,_position)}
581
+ define_method("test_+" ){_test_position(:+,_len)}
582
+ define_method("test_succ" ){_test_position(:succ)}
583
+ define_method("test_pred" ){_test_position(:pred)}
584
+ define_method("test_begin" ){_test_position(:begin)}
585
+ define_method("test_end" ){_test_position(:end)}
586
+ define_method("test_size" ){_test_equal(:size)}
587
+ define_method("test_length" ){_test_equal(:length)}
588
+ define_method("test_empty?" ){_test_equal(:empty?)}
589
+ define_method("test_clear" ){_test_equal(:clear)}
590
+ define_method("test_replace" ){_test_self(:replace,_write_sequence)}
591
+ define_method("test_data" ){_test_equal(:data)}
592
+ define_method("test_<<" ){_test_self(:<< ,_element)}
593
+ define_method("test_>>" ){_test_self(:>> ,_element)}
594
+ define_method("test_slice" ){_test_equal(:slice,*_opt(_ornil(_pos),_len))}
595
+ define_method("test_[]" ){_test_equal(:[],*_opt(_ornil(_pos),_len))}
596
+ define_method("test_slice!" ){_test_equal(:slice!,*_opt(_ornil(_pos),_len))}
597
+ define_method("test_1[]=" ){_test_equal(:[]=,*(_opt(_pos) << _element))}
598
+ define_method("test_2[]=" ){_test_equal(:[]=,_ornil(_pos),_len,_write_sequence)}
599
+ define_method("test_1each" ){_test_equal(:each,_ornil(_pos),_boolean,&_each_code)}
600
+ define_method("test_2each" ){_test_equal(:each,_ornil(_pos),_boolean,_each_sequence,&_each2_code)}
601
+ define_method("test_1collect!" ){_test_self(:collect!,_ornil(_pos),_boolean,&_collect_code)}
602
+ define_method("test_2collect!" ){_test_self(:collect!,_ornil(_pos),_boolean,_each_sequence,&_collect2_code)}
603
+ define_method("test_1map!" ){_test_self(:map!,_ornil(_pos),_boolean,&_collect_code)}
604
+ define_method("test_2map!" ){_test_self(:map!,_ornil(_pos),_boolean,_each_sequence,&_collect2_code)}
605
+ end
606
+ end
607
+
608
+ # :startdoc:
609
+
data/test/test_all.rb ADDED
@@ -0,0 +1,6 @@
1
+ # Copyright (C) 2006 Caleb Clausen
2
+ # Distributed under the terms of Ruby's license.
3
+ require 'test/test_rexscan.rb'
4
+ require 'test/test_seqrex.rb'
5
+ require 'test/test_changes.rb'
6
+
@@ -0,0 +1,44 @@
1
+ # Copyright (C) 2006 Caleb Clausen
2
+ # Distributed under the terms of Ruby's license.
3
+ $VERBOSE=1
4
+ require 'test/unit'
5
+ # require 'rubygems'
6
+ require 'sequence'
7
+ require 'sequence/indexed'
8
+
9
+ class TC_NilContentsTest < Test::Unit::TestCase
10
+ def setup
11
+ @c=Sequence::Indexed.new([1,2,3,nil,4,5,6])
12
+ end
13
+
14
+ # def teardown
15
+ # end
16
+
17
+ def test_nilcontents
18
+ @c.pos=0
19
+ assert_equal(7,@c.size)
20
+ assert_equal([1,2,3],@c.read(3))
21
+ assert(!@c.eof?)
22
+ assert_equal([nil],@c.read(1))
23
+ assert_equal([4,5,6],@c.read(3))
24
+ assert(@c.eof?)
25
+ assert_equal([],@c.read(3))
26
+ assert(@c.eof?)
27
+ assert_equal(7,@c.pos)
28
+ end
29
+ end
30
+
31
+
32
+ class TC_ChangeListTest #< Test::Unit::TestCase
33
+ def setup
34
+ @c= Sequence::Indexed.new([1,2,3,nil,4,5,6])
35
+ @chgs= [0...0,[0], 1..2,[20,25,30], 3,[3.5], 4,[], 5..6,[50], 7,[70,80]]
36
+ end
37
+
38
+
39
+ def test_changelist
40
+ @c.changelist(*@chgs)
41
+ assert_equal @c.data!, [0,1,20,25,30,3.5,50,70,80]
42
+ end
43
+
44
+ end