sequence 0.1.0

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.
@@ -0,0 +1,89 @@
1
+ #eric's original test code; I can't say I understand it
2
+ BEGIN{exit}
3
+ #!/bin/env ruby
4
+ #
5
+ # $Id$
6
+ #
7
+ # Run this to test circular sequences.
8
+ # Here is a list of the optional arguments:
9
+ #
10
+ # <iterations> : approximate number of times to test each method
11
+ # <seed> : seed for random number generation (0: none)
12
+ # <classRE> : regular expression for the classes to test ('': all)
13
+ # <methodRE> : regular expression for the methods to test ('': all)
14
+ # <flags> : Combination of bits for various flags
15
+ # 1 : disable testing of positions
16
+ # 2 : only test with strings/characters
17
+ #
18
+ # All of the standar Test::Unit auto runner options apply. The --verbose=<level>
19
+ # option is especially useful. Here are the various levels:
20
+ #
21
+ # s[ilent] : don't display anything
22
+ # p[rogress] : show a progress bar. Upon fail, show the test and seed.
23
+ # n[ormal] : show each method (and args) tested
24
+ # v[erbose] : show each method and the object state (inspect)
25
+ #
26
+ # If you want to see a demo for a particular method, usually a good command
27
+ # line would be something like this:
28
+ #
29
+ # ruby sequence/test_circulars.rb --verbose=v 10 0 Indexed '^(<method>|close)$'
30
+
31
+ require 'sequence/test'
32
+ require 'sequence/circular'
33
+ require 'sequence/indexed'
34
+ require 'sequence/circular/indexed'
35
+ require 'sequence/circular/shifting'
36
+ require 'sequence/circular/split'
37
+ require 'sequence/circular/linked'
38
+
39
+ # :stopdoc:
40
+
41
+ class Sequence
42
+ class Test
43
+ class Circulars < Test
44
+ def self.suite
45
+ @reject = /^(scan_until|modify|each|collect!|map!|scan_pattern_(while|until))$/
46
+ $0==__FILE__ ? super(*ARGV) : super()
47
+ end
48
+ def self.seed(before,after)
49
+ sequences = [
50
+ Sequence::Circular::Indexed.new(before+after,before.size),
51
+ Sequence::Circular::Indexed.new(after+before,0),
52
+ Sequence::Circular::Shifting.new(after+before,after.size),
53
+ Sequence::Circular::Split.new(before.clone,after.reverse),
54
+ Sequence::Circular::Linked.new(before.clone,after.reverse),
55
+ Sequence::Circular.new(Sequence::Indexed.new(before+after,before.size)),
56
+ ]
57
+ if rand(2).zero?
58
+ @use_positions = false
59
+ sequences << Sequence::Circular.new(
60
+ Sequence::Indexed.new(before+after,before.size)
61
+ ).position
62
+ else
63
+ @use_positions = @flags[0].zero?
64
+ end
65
+ sequences
66
+ end
67
+ def self.plant
68
+ @characters = @flags[1].nonzero?||rand(2).zero?
69
+ super
70
+ end
71
+ def self.elements
72
+ @flags[1].nonzero? ? [?A,?B,?C] : @characters ? [?\n,?\0,?0] : [false,"",[]]
73
+ end
74
+ def self.empty
75
+ @characters&&(@flags[1].nonzero?||rand(2).zero?) ? "" : []
76
+ end
77
+ def self.reject(name,*args,&block)
78
+ case name
79
+ when :position! then !@use_positions && args[0].nil?
80
+ when :position? then !@use_positions && args[0].nil? && block.nil?
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ # :startdoc:
88
+
89
+