rachinations 0.0.3 → 0.0.4
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/Gemfile +1 -16
- data/Gemfile.lock +2 -0
- data/lib/rachinations/domain/diagrams/diagram.rb +46 -14
- data/lib/rachinations/domain/edges/edge.rb +34 -20
- data/lib/rachinations/domain/modules/common/hash_init.rb +2 -1
- data/lib/rachinations/domain/modules/common/invariant.rb +2 -2
- data/lib/rachinations/domain/modules/common/refiners/number_modifiers.rb +22 -0
- data/lib/rachinations/domain/nodes/converter.rb +5 -5
- data/lib/rachinations/domain/nodes/gate.rb +77 -0
- data/lib/rachinations/domain/nodes/node.rb +69 -36
- data/lib/rachinations/domain/nodes/pool.rb +121 -74
- data/lib/rachinations/domain/nodes/resourceful_node.rb +0 -1
- data/lib/rachinations/domain/nodes/sink.rb +3 -0
- data/lib/rachinations/domain/nodes/source.rb +3 -2
- data/lib/rachinations/domain/resource_bag.rb +3 -4
- data/lib/rachinations/dsl/bad_dsl.rb +2 -0
- data/lib/rachinations/dsl/bootstrap.rb +59 -0
- data/lib/rachinations/dsl/diagram_shorthand_methods.rb +107 -0
- data/lib/rachinations/dsl/helpers/parser.rb +170 -0
- data/lib/rachinations/extras/constant_hash.rb +25 -0
- data/lib/rachinations/extras/fifo.rb +25 -19
- data/lib/rachinations/helpers/edge_helper.rb +40 -0
- data/lib/rachinations/utils/string_helper.rb +7 -0
- data/lib/rachinations/version.rb +1 -1
- data/lib/rachinations.rb +13 -5
- data/rachinations.gemspec +3 -2
- data/testing/simulations/modelo1.rb +1 -1
- data/testing/simulations/sequencial.rb +1 -1
- data/testing/simulations/sobonito.rb +1 -1
- data/testing/simulations/sobonitowhile.rb +1 -1
- data/testing/simulations/whatIwish1.rb +2 -2
- data/testing/spec/canon/conditions_spec.rb +3 -4
- data/testing/spec/converter_spec.rb +3 -4
- data/testing/spec/diagram_spec.rb +293 -238
- data/testing/spec/edge_spec.rb +28 -14
- data/testing/spec/gate_spec.rb +34 -0
- data/testing/spec/pool_spec.rb +8 -10
- data/testing/spec/release1/dsl_spec.rb +204 -0
- data/testing/spec/spec_helper.rb +1 -0
- data/testing/spec/xexeo_spec.rb +39 -40
- metadata +30 -8
- data/lib/rachinations/domain/edges/random_edge.rb +0 -4
- data/lib/rachinations/dsl/dsl.rb +0 -63
- data/testing/spec/canon/trigger_spec.rb +0 -128
@@ -1,404 +1,407 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
describe Diagram do
|
4
|
+
using NumberModifiers
|
5
|
+
using ProcConvenienceMethods
|
4
6
|
|
5
|
-
it 'can be empty' do
|
6
|
-
d = Diagram.new 'empty'
|
7
|
-
expect(d.name).to eq 'empty'
|
8
|
-
end
|
9
7
|
|
10
|
-
|
8
|
+
context 'integration' do
|
11
9
|
|
12
|
-
|
10
|
+
it 'can be empty' do
|
11
|
+
d = Diagram.new 'empty'
|
12
|
+
expect(d.name).to eq 'empty'
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
:name => 'source'
|
16
|
-
}
|
15
|
+
it 'should be created with a source and a pool and run n times with no errors' do
|
17
16
|
|
18
|
-
|
19
|
-
:name => 'deposit',
|
20
|
-
:initial_value => 0
|
21
|
-
}
|
17
|
+
d=Diagram.new 'simple'
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
:to => 'deposit'
|
27
|
-
}
|
19
|
+
d.add_node! Source, {
|
20
|
+
:name => 'source'
|
21
|
+
}
|
28
22
|
|
29
|
-
|
23
|
+
d.add_node! Pool, {
|
24
|
+
:name => 'deposit',
|
25
|
+
:initial_value => 0
|
26
|
+
}
|
30
27
|
|
31
|
-
|
32
|
-
|
28
|
+
d.add_edge! Edge, {
|
29
|
+
:name => 'connector',
|
30
|
+
:from => 'source',
|
31
|
+
:to => 'deposit'
|
32
|
+
}
|
33
33
|
|
34
|
-
|
34
|
+
d.run!(10)
|
35
35
|
|
36
|
-
|
36
|
+
expect(d.resource_count).to eq 10
|
37
|
+
expect(d.get_node('deposit').resource_count).to eq 10
|
37
38
|
|
38
|
-
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
it "runs for 2 turns with two pools using PULL and there's the correct amount of resources at the end" do
|
41
42
|
|
42
|
-
|
43
|
+
d = Diagram.new 'some_name'
|
43
44
|
|
44
|
-
|
45
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5
|
45
46
|
|
46
|
-
|
47
|
+
d.add_node! Pool, name: 'pool2', activation: :automatic
|
47
48
|
|
48
|
-
|
49
|
-
expect(d.get_node('pool2').resource_count).to eq 2
|
49
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
50
50
|
|
51
|
-
|
51
|
+
d.run!(2)
|
52
52
|
|
53
|
-
|
53
|
+
expect(d.get_node('pool1').resource_count).to eq 3
|
54
|
+
expect(d.get_node('pool2').resource_count).to eq 2
|
54
55
|
|
55
|
-
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
+
it "runs for 2 turns with two pools using PULL and add the correct amount" do
|
58
59
|
|
59
|
-
|
60
|
+
d = Diagram.new
|
60
61
|
|
61
|
-
|
62
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5
|
62
63
|
|
63
|
-
|
64
|
+
d.add_node! Pool, name: 'pool2', activation: :automatic
|
64
65
|
|
65
|
-
|
66
|
-
expect(d.get_node('pool2').resources_added).to eq 2
|
66
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
67
67
|
|
68
|
-
|
69
|
-
expect(d.get_node('pool1').resources_removed).to eq 2
|
68
|
+
d.run!(2)
|
70
69
|
|
71
|
-
|
70
|
+
expect(d.get_node('pool1').resources_added).to eq 0
|
71
|
+
expect(d.get_node('pool2').resources_added).to eq 2
|
72
|
+
expect(d.get_node('pool2').resources_removed).to eq 0
|
73
|
+
expect(d.get_node('pool1').resources_removed).to eq 2
|
72
74
|
|
73
|
-
|
75
|
+
end
|
74
76
|
|
75
|
-
|
77
|
+
it "runs for 2 turns with source and pool using PULL and add and remove the correct amount" do
|
76
78
|
|
77
|
-
|
79
|
+
d = Diagram.new 'some_name'
|
78
80
|
|
79
|
-
|
81
|
+
d.add_node! Source, name: 's1', activation: :automatic
|
80
82
|
|
81
|
-
|
83
|
+
d.add_node! Pool, name: 'pool2'
|
82
84
|
|
83
|
-
|
85
|
+
d.add_edge! Edge, name: 'edge', from: 's1', to: 'pool2'
|
84
86
|
|
87
|
+
d.run!(2)
|
85
88
|
|
86
|
-
expect(d.get_node('s1').resources_added).to eq 0
|
87
|
-
expect(d.get_node('pool2').resources_added).to eq 2
|
88
|
-
expect(d.get_node('pool2').resources_removed).to eq 0
|
89
|
-
expect(d.get_node('s1').resources_removed).to eq 2
|
90
89
|
|
91
|
-
|
90
|
+
expect(d.get_node('s1').resources_added).to eq 0
|
91
|
+
expect(d.get_node('pool2').resources_added).to eq 2
|
92
|
+
expect(d.get_node('pool2').resources_removed).to eq 0
|
93
|
+
expect(d.get_node('s1').resources_removed).to eq 2
|
92
94
|
|
93
|
-
|
95
|
+
end
|
94
96
|
|
95
|
-
|
97
|
+
it "runs for two turns with two pools using PUSH and there's the correct amount of resources at the end" do
|
96
98
|
|
97
|
-
|
99
|
+
d = Diagram.new 'some_name'
|
98
100
|
|
99
|
-
|
101
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5, mode: :push_any, activation: :automatic
|
100
102
|
|
101
|
-
|
103
|
+
d.add_node! Pool, name: 'pool2'
|
102
104
|
|
103
|
-
|
105
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
104
106
|
|
105
|
-
|
106
|
-
expect(d.get_node('pool2').resource_count).to eq 2
|
107
|
+
d.run!(2)
|
107
108
|
|
108
|
-
|
109
|
+
expect(d.get_node('pool1').resource_count).to eq 3
|
110
|
+
expect(d.get_node('pool2').resource_count).to eq 2
|
109
111
|
|
110
|
-
|
111
|
-
p = Diagram.new('one source two pools')
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
+
it "runs for a single turn with one source and two pools and there's the correct amount of resources at the end" do
|
115
|
+
p = Diagram.new('one source two pools')
|
114
116
|
|
115
|
-
|
117
|
+
p.add_node!(Source, {name: 'source'})
|
116
118
|
|
117
|
-
|
119
|
+
p.add_node!(Pool, {name: 'pool1'})
|
118
120
|
|
119
|
-
|
121
|
+
p.add_node!(Pool, {name: 'pool2', activation: :automatic})
|
120
122
|
|
121
|
-
|
123
|
+
p.add_edge!(Edge, {name: 'edge1', from: 'source', to: 'pool1'})
|
122
124
|
|
123
|
-
|
125
|
+
p.add_edge!(Edge, {name: 'connector2', from: 'pool1', to: 'pool2'})
|
124
126
|
|
125
|
-
|
126
|
-
expect(p.get_node('pool2').resource_count).to eq 0
|
127
|
+
p.run!(1)
|
127
128
|
|
128
|
-
|
129
|
+
expect(p.get_node('pool1').resource_count).to eq 1
|
130
|
+
expect(p.get_node('pool2').resource_count).to eq 0
|
129
131
|
|
130
|
-
|
132
|
+
end
|
131
133
|
|
132
|
-
|
134
|
+
it 'takes staging and commit steps into account when run with 3 pools for 1 turn only' do
|
133
135
|
|
134
|
-
|
136
|
+
d = Diagram.new
|
135
137
|
|
136
|
-
|
138
|
+
d.add_node! Pool, name: 'pool1', initial_value: 2, mode: :push_any, activation: :automatic
|
137
139
|
|
138
|
-
|
140
|
+
d.add_node! Pool, name: 'pool2'
|
139
141
|
|
140
|
-
|
142
|
+
d.add_node! Pool, name: 'pool3', activation: :automatic
|
141
143
|
|
142
|
-
|
144
|
+
d.add_edge! Edge, name: 'edge1', from: 'pool1', to: 'pool2'
|
143
145
|
|
144
|
-
|
146
|
+
d.add_edge! Edge, name: 'edge2', from: 'pool2', to: 'pool3'
|
145
147
|
|
146
|
-
|
147
|
-
expect(d.get_node('pool2').resource_count).to eq 1
|
148
|
-
expect(d.get_node('pool3').resource_count).to eq 0
|
148
|
+
d.run!(1)
|
149
149
|
|
150
|
-
|
150
|
+
expect(d.get_node('pool1').resource_count).to eq 1
|
151
|
+
expect(d.get_node('pool2').resource_count).to eq 1
|
152
|
+
expect(d.get_node('pool3').resource_count).to eq 0
|
151
153
|
|
152
|
-
|
154
|
+
end
|
153
155
|
|
154
|
-
|
156
|
+
it 'takes staging and commit steps into account when run with 3 pools for 4 turns' do
|
155
157
|
|
156
|
-
|
158
|
+
d = Diagram.new
|
157
159
|
|
158
|
-
|
160
|
+
d.add_node! Pool, name: 'pool1', initial_value: 10, mode: :push_any, activation: :automatic
|
159
161
|
|
160
|
-
|
162
|
+
d.add_node! Pool, name: 'pool2'
|
161
163
|
|
162
|
-
|
164
|
+
d.add_node! Pool, name: 'pool3', activation: :automatic
|
163
165
|
|
164
|
-
|
166
|
+
d.add_edge! Edge, name: 'edge1', from: 'pool1', to: 'pool2'
|
165
167
|
|
168
|
+
d.add_edge! Edge, name: 'edge2', from: 'pool2', to: 'pool3'
|
166
169
|
|
167
|
-
d.run!(4)
|
168
170
|
|
169
|
-
|
170
|
-
expect(d.get_node('pool2').resource_count).to eq 1
|
171
|
-
expect(d.get_node('pool3').resource_count).to eq 3
|
171
|
+
d.run!(4)
|
172
172
|
|
173
|
+
expect(d.get_node('pool1').resource_count).to eq 6
|
174
|
+
expect(d.get_node('pool2').resource_count).to eq 1
|
175
|
+
expect(d.get_node('pool3').resource_count).to eq 3
|
173
176
|
|
174
|
-
end
|
175
177
|
|
176
|
-
|
178
|
+
end
|
177
179
|
|
178
|
-
|
180
|
+
it 'runs with a source and a pool and have the expected amount of resources at the end' do
|
179
181
|
|
182
|
+
d=Diagram.new
|
180
183
|
|
181
|
-
d.add_node! Source, {
|
182
|
-
:name => 'source'
|
183
|
-
}
|
184
184
|
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
d.add_node! Source, {
|
186
|
+
:name => 'source'
|
187
|
+
}
|
188
188
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
:to => 'deposit'
|
193
|
-
}
|
189
|
+
d.add_node! Pool, {
|
190
|
+
:name => 'deposit',
|
191
|
+
}
|
194
192
|
|
195
|
-
|
193
|
+
d.add_edge! Edge, {
|
194
|
+
:name => 'connector',
|
195
|
+
:from => 'source',
|
196
|
+
:to => 'deposit'
|
197
|
+
}
|
196
198
|
|
197
|
-
|
199
|
+
d.run!(10)
|
198
200
|
|
199
|
-
|
201
|
+
expect(d.get_node('deposit').resource_count).to eq 10
|
200
202
|
|
201
|
-
|
202
|
-
d=Diagram.new 'simple'
|
203
|
-
d.add_node! Pool, {
|
204
|
-
:name => 'deposit',
|
205
|
-
:initial_value => 0
|
206
|
-
}
|
207
|
-
d.add_node! Source, {
|
208
|
-
:name => 'source'
|
209
|
-
}
|
210
|
-
d.add_edge! Edge, {
|
211
|
-
:name => 'connector',
|
212
|
-
:from => 'source',
|
213
|
-
:to => 'deposit'
|
214
|
-
}
|
215
|
-
|
216
|
-
d.run_while! { d.get_node('deposit').resource_count < 10 }
|
217
|
-
expect(d.get_node('deposit').resource_count).to eq 10
|
203
|
+
end
|
218
204
|
|
219
|
-
|
205
|
+
it 'can be run until a given condition is true' do
|
220
206
|
|
221
|
-
|
207
|
+
d=Diagram.new
|
222
208
|
|
223
|
-
|
224
|
-
|
209
|
+
d.add_node! Pool, {
|
210
|
+
:name => 'deposit',
|
211
|
+
:initial_value => 0
|
212
|
+
}
|
213
|
+
d.add_node! Source, {
|
214
|
+
:name => 'source'
|
215
|
+
}
|
216
|
+
d.add_edge! Edge, {
|
217
|
+
:name => 'connector',
|
218
|
+
:from => 'source',
|
219
|
+
:to => 'deposit'
|
220
|
+
}
|
225
221
|
|
226
|
-
|
227
|
-
|
228
|
-
:initial_value => 0
|
229
|
-
}
|
230
|
-
d.add_node! Source, {
|
231
|
-
:name => 'source'
|
232
|
-
}
|
233
|
-
d.add_edge! Edge, {
|
234
|
-
:name => 'connector',
|
235
|
-
:from => 'source',
|
236
|
-
:to => 'deposit'
|
237
|
-
}
|
222
|
+
d.run_while! { d.get_node('deposit').resource_count < 10 }
|
223
|
+
expect(d.get_node('deposit').resource_count).to eq 10
|
238
224
|
|
239
|
-
|
225
|
+
end
|
240
226
|
|
241
|
-
|
242
|
-
expect(d.get_node('deposit').resource_count).to eq 9
|
227
|
+
it 'aborts after specified turns as a safeguard against infinite loops given as stopping condition' do
|
243
228
|
|
244
|
-
|
229
|
+
d=Diagram.new
|
245
230
|
|
246
|
-
|
231
|
+
d.max_iterations=9
|
247
232
|
|
248
|
-
|
233
|
+
d.add_node! Pool, {
|
234
|
+
:name => 'deposit',
|
235
|
+
:initial_value => 0
|
236
|
+
}
|
237
|
+
d.add_node! Source, {
|
238
|
+
:name => 'source'
|
239
|
+
}
|
240
|
+
d.add_edge! Edge, {
|
241
|
+
:name => 'connector',
|
242
|
+
:from => 'source',
|
243
|
+
:to => 'deposit'
|
244
|
+
}
|
249
245
|
|
250
|
-
|
246
|
+
d.run_while! { true == true }
|
251
247
|
|
252
|
-
|
248
|
+
#not hanging on forever is the success condition.
|
249
|
+
expect(d.get_node('deposit').resource_count).to eq 9
|
253
250
|
|
254
|
-
|
251
|
+
end
|
255
252
|
|
256
|
-
|
253
|
+
it 'does not raise errors when active pushes or pulls are not possible' do
|
257
254
|
|
258
|
-
|
255
|
+
d = Diagram.new 'no errors'
|
259
256
|
|
260
|
-
|
257
|
+
d.add_node! Pool, name: 'Poor fella', initial_value: 5
|
261
258
|
|
262
|
-
|
259
|
+
d.add_node! Pool, name: 'Hungry fella', activation: :automatic
|
263
260
|
|
264
|
-
|
261
|
+
d.add_edge! Edge, from: 'Poor fella', to: 'Hungry fella'
|
265
262
|
|
266
|
-
|
263
|
+
expect { d.run! 10 }.not_to raise_error
|
267
264
|
|
268
|
-
|
265
|
+
expect(d.get_node('Hungry fella').resource_count).to eq 5
|
269
266
|
|
270
|
-
|
271
|
-
name: 'connector1',
|
272
|
-
from: 'source',
|
273
|
-
to: 'pool1'
|
274
|
-
}
|
267
|
+
end
|
275
268
|
|
276
|
-
|
277
|
-
expect { p.get_node('pool') }.to raise_error RuntimeError
|
269
|
+
it "raises an error in case users try to access a node that doesn't exist" do
|
278
270
|
|
279
|
-
|
271
|
+
p = Diagram.new('get invalid node')
|
280
272
|
|
281
|
-
|
273
|
+
p.add_node! Source, name: 'source'
|
282
274
|
|
283
|
-
|
275
|
+
p.add_node! Pool, name: 'pool1'
|
284
276
|
|
285
|
-
|
286
|
-
|
287
|
-
|
277
|
+
p.add_edge! Edge, {
|
278
|
+
name: 'connector1',
|
279
|
+
from: 'source',
|
280
|
+
to: 'pool1'
|
281
|
+
}
|
288
282
|
|
289
|
-
|
283
|
+
# use curly brackets instead of parentheses here.
|
284
|
+
expect { p.get_node('pool') }.to raise_error RuntimeError
|
290
285
|
|
291
|
-
|
292
|
-
expect(p.get_node('pool1').resource_count(Red)).to eq 0
|
286
|
+
end
|
293
287
|
|
294
|
-
|
288
|
+
it 'runs with typed nodes connected by typeless edges' do
|
295
289
|
|
296
|
-
|
290
|
+
p = Diagram.new('one source one pool typed')
|
297
291
|
|
298
|
-
|
292
|
+
p.add_node!(Source, name: 'source', :type => Green)
|
293
|
+
p.add_node!(Pool, name: 'pool1', :types => [Green, Red])
|
294
|
+
p.add_edge!(Edge, name: 'connector1', from: 'source', to: 'pool1')
|
299
295
|
|
300
|
-
|
296
|
+
p.run!(5)
|
301
297
|
|
302
|
-
|
298
|
+
expect(p.get_node('pool1').resource_count(type: Green)).to eq 5
|
299
|
+
expect(p.get_node('pool1').resource_count(type: Red)).to eq 0
|
303
300
|
|
304
|
-
|
301
|
+
end
|
305
302
|
|
306
|
-
|
303
|
+
it "allows untyped nodes to receive typed resources sent to them via untyped edges" do
|
307
304
|
|
308
|
-
|
305
|
+
p = Diagram.new 'balls'
|
309
306
|
|
310
|
-
|
307
|
+
p.add_node!(Source, name: 'source', :type => Football)
|
311
308
|
|
312
|
-
|
309
|
+
p.add_node!(Pool, name: 'pool1')
|
313
310
|
|
314
|
-
|
311
|
+
p.add_edge!(Edge, name: 'connector1', from: 'source', to: 'pool1')
|
315
312
|
|
316
|
-
|
317
|
-
p.add_node! Pool, name: 'pool1', initial_value: {Peach => 20, Mango => 99}
|
313
|
+
p.run!(5)
|
318
314
|
|
319
|
-
|
315
|
+
expect(p.get_node('pool1').resource_count(type: Football)).to eq 5
|
320
316
|
|
321
|
-
|
317
|
+
end
|
322
318
|
|
323
|
-
|
319
|
+
it "allows untyped nodes to receive typed resources sent to them via typed edges" do
|
324
320
|
|
325
|
-
|
326
|
-
expect(p.get_node('pool1').resource_count(Mango)).to eq 99
|
327
|
-
expect(p.get_node('pool2').resource_count(Peach)).to eq 5
|
321
|
+
p = Diagram.new 'fruits'
|
328
322
|
|
329
|
-
|
323
|
+
#by declaring initial values, we're implicitly declaring types.
|
324
|
+
p.add_node! Pool, name: 'pool1', initial_value: {Peach => 20, Mango => 99}
|
330
325
|
|
331
|
-
|
326
|
+
p.add_node! Pool, name: 'pool2', activation: :automatic
|
332
327
|
|
333
|
-
|
328
|
+
p.add_edge!(Edge, name: 'connector1', from: 'pool1', to: 'pool2', types: [Peach])
|
334
329
|
|
335
|
-
|
336
|
-
:name => 'source',
|
337
|
-
:activation => :start
|
338
|
-
}
|
330
|
+
p.run!(5)
|
339
331
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
}
|
332
|
+
expect(p.get_node('pool1').resource_count(type: Peach)).to eq 15
|
333
|
+
expect(p.get_node('pool1').resource_count(type: Mango)).to eq 99
|
334
|
+
expect(p.get_node('pool2').resource_count(type: Peach)).to eq 5
|
344
335
|
|
345
|
-
|
346
|
-
:name => 'connector',
|
347
|
-
:from => 'source',
|
348
|
-
:to => 'deposit'
|
349
|
-
}
|
336
|
+
end
|
350
337
|
|
351
|
-
|
338
|
+
it "executes start nodes only once" do
|
352
339
|
|
340
|
+
d=Diagram.new 'simple'
|
353
341
|
|
354
|
-
|
342
|
+
d.add_node! Source, {
|
343
|
+
:name => 'source',
|
344
|
+
:activation => :start
|
345
|
+
}
|
355
346
|
|
356
|
-
|
347
|
+
d.add_node! Pool, {
|
348
|
+
:name => 'deposit',
|
349
|
+
:initial_value => 0
|
350
|
+
}
|
357
351
|
|
352
|
+
d.add_edge! Edge, {
|
353
|
+
:name => 'connector',
|
354
|
+
:from => 'source',
|
355
|
+
:to => 'deposit'
|
356
|
+
}
|
358
357
|
|
358
|
+
d.run!(10)
|
359
|
+
|
360
|
+
expect(d.get_node('deposit').resource_count).to eq 1
|
361
|
+
|
362
|
+
end
|
359
363
|
|
360
|
-
context 'integration' do
|
361
364
|
|
362
365
|
it ' makes a train run' do
|
363
366
|
|
364
367
|
d = Diagram.new 'dia'
|
365
368
|
|
366
369
|
d.add_node! Pool, {
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
370
|
+
name: 'p1',
|
371
|
+
mode: :push_any,
|
372
|
+
activation: :automatic,
|
373
|
+
initial_value: 8
|
371
374
|
}
|
372
375
|
|
373
376
|
d.add_node! Pool, {
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
+
name: 'p2',
|
378
|
+
mode: :push_any,
|
379
|
+
activation: :automatic
|
377
380
|
}
|
378
381
|
|
379
382
|
d.add_node! Pool, {
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
+
name: 'p3',
|
384
|
+
mode: :push_any,
|
385
|
+
activation: :automatic
|
383
386
|
}
|
384
387
|
|
385
388
|
d.add_node! Pool, {
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
+
name: 'p4',
|
390
|
+
mode: :push_any,
|
391
|
+
activation: :automatic
|
389
392
|
}
|
390
393
|
|
391
|
-
d.add_edge! Edge,{
|
394
|
+
d.add_edge! Edge, {
|
392
395
|
name: 'e1',
|
393
396
|
from: 'p1',
|
394
397
|
to: 'p2'
|
395
398
|
}
|
396
|
-
|
399
|
+
d.add_edge! Edge, {
|
397
400
|
name: 'e2',
|
398
401
|
from: 'p2',
|
399
402
|
to: 'p3'
|
400
403
|
}
|
401
|
-
|
404
|
+
d.add_edge! Edge, {
|
402
405
|
name: 'e3',
|
403
406
|
from: 'p3',
|
404
407
|
to: 'p4'
|
@@ -413,9 +416,6 @@ describe Diagram do
|
|
413
416
|
|
414
417
|
end
|
415
418
|
|
416
|
-
end
|
417
|
-
|
418
|
-
context 'simple converter behaviour' do
|
419
419
|
it 'runs an untyped converter connected to two pools' do
|
420
420
|
|
421
421
|
d=Diagram.new 'simple'
|
@@ -430,7 +430,7 @@ describe Diagram do
|
|
430
430
|
:initial_value => 0
|
431
431
|
}
|
432
432
|
|
433
|
-
d.add_node! Converter,{
|
433
|
+
d.add_node! Converter, {
|
434
434
|
:name => 'c',
|
435
435
|
:activation => :automatic
|
436
436
|
}
|
@@ -453,8 +453,63 @@ describe Diagram do
|
|
453
453
|
|
454
454
|
end
|
455
455
|
|
456
|
+
describe 'diagrams with probabilistic edges' do
|
456
457
|
|
457
|
-
|
458
|
+
it 'accepts random edges with percentages' do
|
459
|
+
|
460
|
+
d = Diagram.new
|
461
|
+
|
462
|
+
d.add_node! Source, name: 's'
|
463
|
+
d.add_node! Gate, name: 'g'
|
464
|
+
d.add_node! Pool, name: 'p'
|
465
|
+
d.add_edge! Edge, from: 's', to: 'g'
|
466
|
+
d.add_edge! Edge, from: 'g', to: 'p', label: 50.percent
|
467
|
+
|
468
|
+
d.run!(20)
|
469
|
+
|
470
|
+
expect(d.p.resource_count).to (be > 1).and(be < 20)
|
471
|
+
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
|
476
|
+
describe 'Comprehensive examples'do
|
477
|
+
|
478
|
+
it 'example using pull_all and activators' do
|
479
|
+
|
480
|
+
d = Diagram.new
|
481
|
+
|
482
|
+
d.add_node! Pool, mode: :pull_all, name: 'p1', activation: :automatic
|
483
|
+
d.add_node! Pool, name: 'p2', initial_value: 7
|
484
|
+
d.add_node! Pool, name: 'p3', initial_value: 2
|
485
|
+
d.add_node! Pool, name: 'p4', initial_value: 2
|
486
|
+
d.add_node! Pool, name: 'p5', activation: :automatic, initial_value: 6, mode: :push_any
|
487
|
+
|
488
|
+
d.add_edge! Edge, from: 'p2',to:'p1'
|
489
|
+
d.add_edge! Edge, from: 'p3',to:'p1'
|
490
|
+
d.add_edge! Edge, from: 'p4',to:'p1'
|
458
491
|
|
492
|
+
d.add_edge! Edge, from: 'p5',to:'p3'
|
493
|
+
d.add_edge! Edge, from: 'p5',to:'p4'
|
494
|
+
|
495
|
+
d.p5.attach_condition{ d.p3.resource_count < 1 && d.p4.resource_count < 1 }
|
496
|
+
|
497
|
+
d.run! 8
|
498
|
+
|
499
|
+
expect(d.p1.resource_count).to eq 15
|
500
|
+
expect(d.p2.resource_count).to eq 2
|
501
|
+
expect(d.p3.resource_count).to eq 0
|
502
|
+
expect(d.p4.resource_count).to eq 0
|
503
|
+
expect(d.p5.resource_count).to eq 0
|
504
|
+
|
505
|
+
end
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
end
|
459
514
|
|
460
515
|
end
|