casegen 2.0.0 → 3.0.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.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +109 -0
- data/.ruby-version +1 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +51 -6
- data/README.md +10 -119
- data/Rakefile +9 -7
- data/bin/casegen +2 -1
- data/casegen.gemspec +13 -9
- data/doc/bounding_box.rb +37 -0
- data/doc/cart.rb +43 -0
- data/doc/expect_only.rb +28 -0
- data/doc/pricing.rb +50 -0
- data/doc/ruby_array.rb +41 -0
- data/lib/case_gen/combination.rb +38 -0
- data/lib/case_gen/combo_matcher.rb +15 -0
- data/lib/case_gen/exclude_rule.rb +50 -0
- data/lib/case_gen/expect_rule.rb +24 -0
- data/lib/case_gen/generator.rb +40 -0
- data/lib/case_gen/output/exclude.rb +6 -0
- data/lib/case_gen/output/exclude_as_table.rb +13 -0
- data/lib/case_gen/output/exclude_as_text.rb +12 -0
- data/lib/case_gen/output/exclude_inline.rb +13 -0
- data/lib/case_gen/output/exclude_inline_footnotes.rb +20 -0
- data/lib/case_gen/output.rb +66 -0
- data/lib/case_gen/rule_description.rb +11 -0
- data/lib/case_gen/set.rb +16 -0
- data/lib/casegen.rb +15 -183
- data/spec/cart_sample_spec.rb +46 -0
- data/spec/case_gen/combination_spec.rb +11 -0
- data/spec/case_gen/exclude_rule_spec.rb +17 -0
- data/spec/exclude_as_table_spec.rb +39 -0
- data/spec/exclude_as_text_spec.rb +58 -0
- data/spec/exclude_inline_footnotes_spec.rb +58 -0
- data/spec/exclude_inline_spec.rb +50 -0
- data/spec/expect_only_spec.rb +30 -0
- data/spec/spec_helper.rb +113 -0
- metadata +101 -35
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/vcs.xml +0 -7
- data/doc/calc.sample.txt +0 -13
- data/doc/cart.sample.rb +0 -3
- data/doc/cart.sample.txt +0 -33
- data/doc/ruby_array.sample.rb +0 -26
- data/lib/agents/sets/enum/by.rb +0 -244
- data/lib/agents/sets/enum/cluster.rb +0 -164
- data/lib/agents/sets/enum/inject.rb +0 -50
- data/lib/agents/sets/enum/nest.rb +0 -117
- data/lib/agents/sets/enum/op.rb +0 -283
- data/lib/agents/sets/enum/pipe.rb +0 -160
- data/lib/agents/sets/enum/tree.rb +0 -442
- data/lib/agents/sets.rb +0 -313
- data/test/agents/console_output_test.rb +0 -27
- data/test/agents/sets.test.rb +0 -227
- data/test/agents_test.rb +0 -41
- data/test/casegen.tests.rb +0 -0
- data/test/parser_test.rb +0 -163
- data/test/test_helper.rb +0 -2
data/doc/ruby_array.sample.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require_relative '../lib/casegen'
|
2
|
-
|
3
|
-
CLabs::CaseGen::CaseGen.new(DATA.read)
|
4
|
-
|
5
|
-
__END__
|
6
|
-
|
7
|
-
sets
|
8
|
-
----
|
9
|
-
role: admin, standard
|
10
|
-
authorization code: none, invalid, valid
|
11
|
-
submit enabled: true, false
|
12
|
-
|
13
|
-
rules(sets)
|
14
|
-
-----------
|
15
|
-
exclude role = admin AND submit enabled = false
|
16
|
-
Admin role can always submit
|
17
|
-
|
18
|
-
exclude role = standard AND authorization code = none AND submit enabled = true
|
19
|
-
exclude role = standard AND authorization code = invalid AND submit enabled = true
|
20
|
-
exclude role = standard AND authorization code = valid AND submit enabled = false
|
21
|
-
Standard role can only submit when authorization code is valid
|
22
|
-
|
23
|
-
|
24
|
-
ruby_array(rules)
|
25
|
-
-------------
|
26
|
-
DataSubmitCase
|
data/lib/agents/sets/enum/by.rb
DELETED
@@ -1,244 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
module Enumerable
|
4
|
-
|
5
|
-
class LinkedListDelegator
|
6
|
-
include Enumerable
|
7
|
-
|
8
|
-
attr_reader :first, :next_name, :next_map, :args
|
9
|
-
|
10
|
-
def initialize first, next_spec = nil, *args, &next_proc
|
11
|
-
@first = first
|
12
|
-
@args = args
|
13
|
-
|
14
|
-
case next_spec
|
15
|
-
when Symbol
|
16
|
-
@next_name = next_spec
|
17
|
-
when String
|
18
|
-
@next_name = next_spec.intern
|
19
|
-
when nil
|
20
|
-
@next_map = next_proc
|
21
|
-
else
|
22
|
-
unless next_spec.respond_to? :[]
|
23
|
-
raise ArgumentError,
|
24
|
-
"next_spec must be a method name or respond to []."
|
25
|
-
end
|
26
|
-
@next_map = next_spec
|
27
|
-
end
|
28
|
-
|
29
|
-
unless @next_name or @next_map
|
30
|
-
raise ArgumentError,
|
31
|
-
"no next-getter specified."
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def each
|
36
|
-
cur = @first
|
37
|
-
if @next_name
|
38
|
-
next_name = @next_name
|
39
|
-
message = next_name, *@args
|
40
|
-
while cur
|
41
|
-
yield cur
|
42
|
-
cur = cur.send *message
|
43
|
-
end
|
44
|
-
elsif @next_map
|
45
|
-
next_map = @next_map
|
46
|
-
args = @args
|
47
|
-
while cur
|
48
|
-
yield cur
|
49
|
-
cur = next_map[cur, *args]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
self
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
class Object
|
61
|
-
def by next_spec = nil, *args, &next_proc
|
62
|
-
Enumerable::LinkedListDelegator.new self, next_spec, *args, &next_proc
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
=begin
|
68
|
-
|
69
|
-
==class Object
|
70
|
-
===instance method
|
71
|
-
---Object#by next_spec = nil, *args, &next_proc
|
72
|
-
|
73
|
-
Allows use of (({Enumerable})) methods, such as (({each})), (({collect})),
|
74
|
-
(({select})), etc., to iterate over arbitrary objects. The caller supplies a
|
75
|
-
way of calculating the successor of each object, such as an accessor method for
|
76
|
-
the next element of a linked list.
|
77
|
-
|
78
|
-
Object#by returns an (({Enumerable})) object whose (({each})) method
|
79
|
-
iterates over the sequence beginning with (({self})) and continuing as
|
80
|
-
specified by the arguments. Only the current element of the sequence is
|
81
|
-
kept in memory. No attempt is made to avoid cycles.
|
82
|
-
|
83
|
-
If (({next_spec})) is a string or symbol, (({next_proc})) is ignored and
|
84
|
-
(({next_spec})) is treated as a method name. This method name is sent, along
|
85
|
-
with arguments (({args})), to each element of the sequence to generate the next
|
86
|
-
element. The sequence terminates at the first element for which the method
|
87
|
-
returns (({nil})) or (({false})).
|
88
|
-
|
89
|
-
If (({next_spec})) is anything else, except (({nil})), (({next_proc})) is
|
90
|
-
ignored and (({next_spec})) is required to be an object that responds to
|
91
|
-
(({[]})), such as a proc or a hash. The (({[]})) method of (({next_spec}))
|
92
|
-
is called with each element of the sequence in turn as an argument, along
|
93
|
-
with (({args})), to generate the next element. The sequence terminates at
|
94
|
-
the first element for which (({[]})) returns (({nil})) or (({false})).
|
95
|
-
|
96
|
-
If (({next_spec})) is not given, or is (({nil})), a block is required. In this
|
97
|
-
case, the block is converted to a proc and iteration proceeds as in the
|
98
|
-
preceding paragraph.
|
99
|
-
|
100
|
-
The return value is not an array, but an (({Enumerable})) object that refers
|
101
|
-
to the original objects. In this sense, (({Object#by})) is a ((*delegator*)).
|
102
|
-
Typically, (({by})) is used with the (({for .. in ..})) construct, or
|
103
|
-
(equivalently) with (({each})), or with (({collect})), (({select})), and so on.
|
104
|
-
In these cases, the dependence on the original sequence does not matter. To get
|
105
|
-
the array of entries produced by (({by})) as an independent data structure, use
|
106
|
-
(({Enumerable#entries})) or (({Enumerable#to_a})).
|
107
|
-
|
108
|
-
===examples
|
109
|
-
|
110
|
-
require 'enum/by'
|
111
|
-
|
112
|
-
class A; end
|
113
|
-
class B < A; end
|
114
|
-
class C < B; end
|
115
|
-
|
116
|
-
for cl in C.by :superclass
|
117
|
-
print cl, " "
|
118
|
-
end
|
119
|
-
|
120
|
-
# prints: C B A Object
|
121
|
-
|
122
|
-
steps = proc { |x, incr, limit| y = x + incr; y <= limit ? y : nil }
|
123
|
-
p 0.by(steps, 10, 50).to_a
|
124
|
-
|
125
|
-
# prints: [0, 10, 20, 30, 40, 50]
|
126
|
-
|
127
|
-
See the end of the source file for more examples.
|
128
|
-
|
129
|
-
==version
|
130
|
-
|
131
|
-
Enumerable tools 1.6
|
132
|
-
|
133
|
-
The current version of this software can be found at
|
134
|
-
((<"http://redshift.sourceforge.net/enum
|
135
|
-
"|URL:http://redshift.sourceforge.net/enum>)).
|
136
|
-
|
137
|
-
==license
|
138
|
-
This software is distributed under the Ruby license.
|
139
|
-
See ((<"http://www.ruby-lang.org"|URL:http://www.ruby-lang.org>)).
|
140
|
-
|
141
|
-
==author
|
142
|
-
Joel VanderWerf,
|
143
|
-
((<vjoel@users.sourceforge.net|URL:mailto:vjoel@users.sourceforge.net>))
|
144
|
-
|
145
|
-
==acknowledgement
|
146
|
-
Thanks to David Alan Black for his helpful comments on the Ruby mailing
|
147
|
-
list
|
148
|
-
((<"http://blade.nagaokaut.ac.jp/ruby/ruby-talk
|
149
|
-
"|URL:http://blade.nagaokaut.ac.jp/ruby/ruby-talk>)).
|
150
|
-
|
151
|
-
=end
|
152
|
-
|
153
|
-
|
154
|
-
if __FILE__ == $0
|
155
|
-
|
156
|
-
class Foo
|
157
|
-
attr_reader :value, :next_foo
|
158
|
-
|
159
|
-
def initialize value, next_foo = nil
|
160
|
-
@value = value
|
161
|
-
@next_foo = next_foo
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
list = Foo.new(0, Foo.new(1, Foo.new(2, Foo.new(3))))
|
166
|
-
|
167
|
-
puts "Iterating over a linked list by method next_foo:"
|
168
|
-
for foo in list.by :next_foo
|
169
|
-
print "#{foo.value} "
|
170
|
-
end
|
171
|
-
print "\n\n"
|
172
|
-
|
173
|
-
puts "By proc { |foo| foo.next_foo.next_foo }:"
|
174
|
-
for foo in list.by { |foo| foo.next_foo.next_foo }
|
175
|
-
print "#{foo.value} "
|
176
|
-
end
|
177
|
-
print "\n\n"
|
178
|
-
|
179
|
-
puts "Down a tree, taking a random branch at each node:"
|
180
|
-
puts "First, with a proc:"
|
181
|
-
tree = [[0, [1, 2]], 3, [4, 5, [6, 7, 8]], 9]
|
182
|
-
at_random = proc { |x| x.kind_of?(Array) && x.at(rand(x.size)) }
|
183
|
-
for node in tree.by at_random
|
184
|
-
p node
|
185
|
-
end
|
186
|
-
puts "Second, with methods:"
|
187
|
-
class Object
|
188
|
-
def at_random
|
189
|
-
nil
|
190
|
-
end
|
191
|
-
end
|
192
|
-
class Array
|
193
|
-
def at_random
|
194
|
-
at(rand(size))
|
195
|
-
end
|
196
|
-
end
|
197
|
-
for node in tree.by :at_random
|
198
|
-
p node
|
199
|
-
end
|
200
|
-
puts
|
201
|
-
|
202
|
-
puts "With numbers (but watch out for cycles!):"
|
203
|
-
p 0.by { |x| x<10 ? x+1 : nil }.to_a
|
204
|
-
puts
|
205
|
-
|
206
|
-
puts "With numbers using a proc and an argument:"
|
207
|
-
steps = proc { |x, incr, limit| y = x + incr; y <= limit ? y : nil }
|
208
|
-
p 0.by(steps, 10, 50).to_a
|
209
|
-
puts
|
210
|
-
|
211
|
-
puts "Up the superclass relation:"
|
212
|
-
class A; end
|
213
|
-
class B < A; end
|
214
|
-
class C < B; end
|
215
|
-
for cl in C.by :superclass
|
216
|
-
print cl, " "
|
217
|
-
end
|
218
|
-
puts "\n\n"
|
219
|
-
|
220
|
-
puts "Popping down a stack:"
|
221
|
-
p [0,1,2,3,4].by { |y| y.pop; y != [] && y.dup }.entries
|
222
|
-
puts
|
223
|
-
|
224
|
-
puts "#by behaves correctly with self==nil"
|
225
|
-
p nil.by(:something).entries
|
226
|
-
puts
|
227
|
-
|
228
|
-
puts "By hash, or other class responding to []:"
|
229
|
-
h = { :a => :b, :b => :c, :c => :d }
|
230
|
-
p :a.by {|x| h[x]}.entries
|
231
|
-
puts "The same effect, but simpler:"
|
232
|
-
p :a.by(h).entries
|
233
|
-
puts
|
234
|
-
|
235
|
-
puts "Around and around we go..."
|
236
|
-
n = 0;
|
237
|
-
for x in 0.by([1,2,3,4,0])
|
238
|
-
n += 1
|
239
|
-
print x, " "
|
240
|
-
break if n > 12
|
241
|
-
end
|
242
|
-
puts "..."
|
243
|
-
|
244
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
module Enumerable
|
4
|
-
|
5
|
-
def each_cluster n = 2
|
6
|
-
tuple = [nil] * n
|
7
|
-
|
8
|
-
count = n-1
|
9
|
-
each { |x|
|
10
|
-
tuple.shift
|
11
|
-
tuple.push x
|
12
|
-
if count == 0
|
13
|
-
yield tuple
|
14
|
-
else
|
15
|
-
count -= 1
|
16
|
-
end
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
def each_with_neighbors n = 1, empty = nil
|
21
|
-
nbrs = [empty] * (2 * n + 1)
|
22
|
-
offset = n
|
23
|
-
|
24
|
-
each { |x|
|
25
|
-
nbrs.shift
|
26
|
-
nbrs.push x
|
27
|
-
if offset == 0 # offset is now the offset of the first element, x0,
|
28
|
-
yield nbrs # of the sequence from the center of nbrs, or 0,
|
29
|
-
else # if x0 has already passed the center.
|
30
|
-
offset -= 1
|
31
|
-
end
|
32
|
-
}
|
33
|
-
|
34
|
-
n.times {
|
35
|
-
nbrs.shift
|
36
|
-
nbrs.push empty
|
37
|
-
if offset == 0
|
38
|
-
yield nbrs
|
39
|
-
else
|
40
|
-
offset -= 1
|
41
|
-
end
|
42
|
-
}
|
43
|
-
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
=begin
|
51
|
-
|
52
|
-
==module Enumerable
|
53
|
-
===instance methods
|
54
|
-
---Enumerable#each_cluster n = 2
|
55
|
-
---Enumerable#each_with_neighbors n = 1, empty = nil
|
56
|
-
|
57
|
-
Both methods iterate over a collection of arrays whose elements are drawn
|
58
|
-
in sequence from the original collection.
|
59
|
-
|
60
|
-
In the case of (({each_cluster})), the iteration yields all contiguous
|
61
|
-
subsequences of length ((|n|)). If the argument to (({each_cluster})) is 0
|
62
|
-
or larger than the size of the collection, the iteration yields no values.
|
63
|
-
|
64
|
-
In the case of (({each_with_neighbors})), the iteration yields one
|
65
|
-
sequence for each element ((|x|)) of the collection. The yielded sequence
|
66
|
-
includes the ((|n|)) elements before and after ((|x|)). Elements out of
|
67
|
-
bounds are filled with ((|empty|)). The first argument can be any
|
68
|
-
nonnegative integer.
|
69
|
-
|
70
|
-
===examples
|
71
|
-
|
72
|
-
require 'enum/cluster'
|
73
|
-
|
74
|
-
(0..5).each_with_neighbors { |x| p x }
|
75
|
-
|
76
|
-
# prints:
|
77
|
-
# [nil, 0, 1]
|
78
|
-
# [0, 1, 2]
|
79
|
-
# [1, 2, 3]
|
80
|
-
# [2, 3, 4]
|
81
|
-
# [3, 4, 5]
|
82
|
-
# [4, 5, nil]
|
83
|
-
|
84
|
-
[1,2,3,4].each_with_neighbors(8, 0) { |x| p x }
|
85
|
-
|
86
|
-
# prints:
|
87
|
-
# [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0]
|
88
|
-
# [0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
|
89
|
-
# [0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0]
|
90
|
-
# [0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0]
|
91
|
-
|
92
|
-
('a'..'g').each_cluster(5) { |x| p x.join '' }
|
93
|
-
|
94
|
-
# prints:
|
95
|
-
# "abcde"
|
96
|
-
# "bcdef"
|
97
|
-
# "cdefg"
|
98
|
-
|
99
|
-
See the end of the source file for more examples.
|
100
|
-
|
101
|
-
==version
|
102
|
-
|
103
|
-
Enumerable tools 1.6
|
104
|
-
|
105
|
-
The current version of this software can be found at
|
106
|
-
((<"http://redshift.sourceforge.net/enum
|
107
|
-
"|URL:http://redshift.sourceforge.net/enum>)).
|
108
|
-
|
109
|
-
==license
|
110
|
-
This software is distributed under the Ruby license.
|
111
|
-
See ((<"http://www.ruby-lang.org"|URL:http://www.ruby-lang.org>)).
|
112
|
-
|
113
|
-
==author
|
114
|
-
Joel VanderWerf,
|
115
|
-
((<vjoel@users.sourceforge.net|URL:mailto:vjoel@users.sourceforge.net>))
|
116
|
-
|
117
|
-
=end
|
118
|
-
|
119
|
-
|
120
|
-
if __FILE__ == $0
|
121
|
-
|
122
|
-
(0..5).each_with_neighbors { |x| p x }
|
123
|
-
|
124
|
-
puts
|
125
|
-
|
126
|
-
[1,2,3,4].each_with_neighbors(8, 0) { |x| p x }
|
127
|
-
|
128
|
-
puts
|
129
|
-
|
130
|
-
('a'..'g').each_cluster(5) { |x| p x.join '' }
|
131
|
-
|
132
|
-
puts
|
133
|
-
|
134
|
-
begin
|
135
|
-
require 'enum/by'
|
136
|
-
|
137
|
-
# each_with_neighbors is useful for successive comparisons:
|
138
|
-
2.by {|x| x<10000 && x**2}.each_with_neighbors(1, 1) {
|
139
|
-
|prev_x, x, next_x|
|
140
|
-
printf "%d - %d = %d\n", x, prev_x, x - prev_x
|
141
|
-
}
|
142
|
-
puts
|
143
|
-
|
144
|
-
# Construct a doubly linked list:
|
145
|
-
Node = Struct.new "Node", :value, :prev_node, :next_node
|
146
|
-
|
147
|
-
list = (1..10).collect { |i| Node.new i }
|
148
|
-
|
149
|
-
list.each_with_neighbors { |prev_node, node, next_node|
|
150
|
-
node.prev_node = prev_node
|
151
|
-
node.next_node = next_node
|
152
|
-
}
|
153
|
-
|
154
|
-
list[0].by(:next_node).each { |node| print node.value, " " }
|
155
|
-
puts
|
156
|
-
|
157
|
-
# We constructed the list and interated over it without ever
|
158
|
-
# explicitly mentioning nil.
|
159
|
-
|
160
|
-
rescue LoadError
|
161
|
-
puts "File enum/by.rb not available. You're missing the best part!"
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
=begin
|
4
|
-
---Enumerable#inject
|
5
|
-
---Enumerable#sum [block]
|
6
|
-
|
7
|
-
Code adapted from Pickaxe book, p.102.
|
8
|
-
See source file for examples.
|
9
|
-
|
10
|
-
==version
|
11
|
-
|
12
|
-
Enumerable tools 1.6
|
13
|
-
|
14
|
-
=end
|
15
|
-
|
16
|
-
# module Enumerable
|
17
|
-
#
|
18
|
-
# def inject n
|
19
|
-
# each { |i|
|
20
|
-
# n = yield n, i
|
21
|
-
# }
|
22
|
-
# n
|
23
|
-
# end
|
24
|
-
# alias :accumulate :inject
|
25
|
-
#
|
26
|
-
# def sum
|
27
|
-
# if block_given?
|
28
|
-
# inject(0) { |n, i| n + yield(i) }
|
29
|
-
# else
|
30
|
-
# inject(0) { |n, i| n + i }
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# def product
|
35
|
-
# if block_given?
|
36
|
-
# inject(1) { |n, i| n * yield(i) }
|
37
|
-
# else
|
38
|
-
# inject(1) { |n, i| n * i }
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# end
|
43
|
-
|
44
|
-
if __FILE__ == $0
|
45
|
-
|
46
|
-
x = (0..9).collect { |i| [i, i*i] }
|
47
|
-
p x
|
48
|
-
p x.sum { |v| v[1] }
|
49
|
-
|
50
|
-
end
|