rachinations 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +6 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +93 -0
- data/LICENSE.txt +21 -0
- data/README.md +18 -0
- data/Rakefile +16 -0
- data/lib/rachinations.rb +49 -0
- data/lib/rachinations/domain/diagrams/diagram.rb +167 -0
- data/lib/rachinations/domain/diagrams/non_deterministic_diagram.rb +16 -0
- data/lib/rachinations/domain/diagrams/verbose_diagram.rb +9 -0
- data/lib/rachinations/domain/edge_collection.rb +12 -0
- data/lib/rachinations/domain/edges/edge.rb +159 -0
- data/lib/rachinations/domain/edges/random_edge.rb +4 -0
- data/lib/rachinations/domain/exceptions/bad_options.rb +3 -0
- data/lib/rachinations/domain/exceptions/no_elements_found.rb +2 -0
- data/lib/rachinations/domain/exceptions/no_elements_matching_condition_error.rb +2 -0
- data/lib/rachinations/domain/exceptions/no_elements_of_given_type.rb +3 -0
- data/lib/rachinations/domain/exceptions/unsupported_type_error.rb +2 -0
- data/lib/rachinations/domain/modules/common/hash_init.rb +88 -0
- data/lib/rachinations/domain/modules/common/invariant.rb +17 -0
- data/lib/rachinations/domain/modules/diagrams/verbose.rb +30 -0
- data/lib/rachinations/domain/node_collection.rb +30 -0
- data/lib/rachinations/domain/nodes/converter.rb +276 -0
- data/lib/rachinations/domain/nodes/gate.rb +6 -0
- data/lib/rachinations/domain/nodes/node.rb +166 -0
- data/lib/rachinations/domain/nodes/pool.rb +267 -0
- data/lib/rachinations/domain/nodes/resourceful_node.rb +96 -0
- data/lib/rachinations/domain/nodes/resourceless_node.rb +11 -0
- data/lib/rachinations/domain/nodes/sink.rb +17 -0
- data/lib/rachinations/domain/nodes/source.rb +161 -0
- data/lib/rachinations/domain/nodes/trader.rb +6 -0
- data/lib/rachinations/domain/resource_bag.rb +131 -0
- data/lib/rachinations/domain/resources/token.rb +51 -0
- data/lib/rachinations/domain/strategies/strategy.rb +5 -0
- data/lib/rachinations/domain/strategies/valid_types.rb +69 -0
- data/lib/rachinations/dsl/dsl.rb +63 -0
- data/lib/rachinations/extras/fifo.rb +27 -0
- data/lib/rachinations/version.rb +3 -0
- data/machinations_diagrams/apenas_bonito.xml +22 -0
- data/machinations_diagrams/behavior_converter.xml +53 -0
- data/machinations_diagrams/behavior_converter_fim.xml +10 -0
- data/machinations_diagrams/canon/README.md +8 -0
- data/machinations_diagrams/canon/converters_differences.xml +27 -0
- data/machinations_diagrams/canon/converters_differences2.xml +34 -0
- data/machinations_diagrams/canon/converters_similarities.xml +63 -0
- data/machinations_diagrams/canon/converters_similarities2.xml +21 -0
- data/machinations_diagrams/canon/nodes_and_edges_differences.xml +15 -0
- data/machinations_diagrams/canon/nodes_and_edges_similarities.xml +20 -0
- data/machinations_diagrams/deterministic_example.xml +46 -0
- data/machinations_diagrams/economies_of_scale.xml +32 -0
- data/machinations_diagrams/feature_ou_bug.xml +5 -0
- data/machinations_diagrams/loop_in_trigger.xml +21 -0
- data/machinations_diagrams/naficadevendo.xml +12 -0
- data/machinations_diagrams/noreporting_equivalent.xml +22 -0
- data/machinations_diagrams/pull_all_example.xml +7 -0
- data/machinations_diagrams/sketch_of_memory.xml +41 -0
- data/machinations_diagrams/software_engineering_process 2.xml +130 -0
- data/machinations_diagrams/software_engineering_process v3.xml +168 -0
- data/machinations_diagrams/software_engineering_process v4.xml +192 -0
- data/machinations_diagrams/software_engineering_process.xml +65 -0
- data/machinations_diagrams/software_engineering_process_with_rework_after_test.xml +195 -0
- data/machinations_diagrams/startup_marketing.xml +35 -0
- data/machinations_diagrams/triggers_allow_multiple_stages_at_same_round.xml +19 -0
- data/machinations_diagrams/um_de_cada_vez_vs_todos_de_uma_vez.xml +20 -0
- data/rachinations.gemspec +35 -0
- data/testing/features/step_definitions/step_definitions.rb +11 -0
- data/testing/simulations/modelo1.rb +20 -0
- data/testing/simulations/modelo2.rb +49 -0
- data/testing/simulations/noreporting.rb +51 -0
- data/testing/simulations/sequencial.rb +19 -0
- data/testing/simulations/sobonito.rb +28 -0
- data/testing/simulations/sobonitowhile.rb +28 -0
- data/testing/simulations/whatIwish1.rb +20 -0
- data/testing/spec/canon/converter_spec.rb +33 -0
- data/testing/spec/canon/pool_spec.rb +68 -0
- data/testing/spec/conditions_spec.rb +10 -0
- data/testing/spec/converter_spec.rb +223 -0
- data/testing/spec/diagram_spec.rb +671 -0
- data/testing/spec/edge_spec.rb +256 -0
- data/testing/spec/hash_init_spec.rb +59 -0
- data/testing/spec/node_spec.rb +31 -0
- data/testing/spec/non_deterministic_diagram_spec.rb +112 -0
- data/testing/spec/pool_spec.rb +233 -0
- data/testing/spec/source_spec.rb +132 -0
- data/testing/spec/spec_helper.rb +34 -0
- data/testing/spec/xexeo_spec.rb +193 -0
- metadata +283 -0
@@ -0,0 +1,671 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Diagram do
|
4
|
+
|
5
|
+
it 'can be empty' do
|
6
|
+
d = Diagram.new 'empty'
|
7
|
+
expect(d.name).to eq 'empty'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should be created with a source and a pool and run n times with no errors' do
|
11
|
+
|
12
|
+
d=Diagram.new 'simple'
|
13
|
+
|
14
|
+
d.add_node! Source, {
|
15
|
+
:name => 'source'
|
16
|
+
}
|
17
|
+
|
18
|
+
d.add_node! Pool, {
|
19
|
+
:name => 'deposit',
|
20
|
+
:initial_value => 0
|
21
|
+
}
|
22
|
+
|
23
|
+
d.add_edge! Edge, {
|
24
|
+
:name => 'connector',
|
25
|
+
:from => 'source',
|
26
|
+
:to => 'deposit'
|
27
|
+
}
|
28
|
+
|
29
|
+
d.run!(10)
|
30
|
+
|
31
|
+
expect(d.resource_count).to eq 10
|
32
|
+
expect(d.get_node('deposit').resource_count).to eq 10
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
it "runs for 2 turns with two pools using PULL and there's the correct amount of resources at the end" do
|
37
|
+
|
38
|
+
d = Diagram.new 'some_name'
|
39
|
+
|
40
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5
|
41
|
+
|
42
|
+
d.add_node! Pool, name: 'pool2', activation: :automatic
|
43
|
+
|
44
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
45
|
+
|
46
|
+
d.run!(2)
|
47
|
+
|
48
|
+
expect(d.get_node('pool1').resource_count).to eq 3
|
49
|
+
expect(d.get_node('pool2').resource_count).to eq 2
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
it "runs for 2 turns with two pools using PULL and add the correct amount" do
|
54
|
+
|
55
|
+
d = Diagram.new 'some_name'
|
56
|
+
|
57
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5
|
58
|
+
|
59
|
+
d.add_node! Pool, name: 'pool2', activation: :automatic
|
60
|
+
|
61
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
62
|
+
|
63
|
+
d.run!(2)
|
64
|
+
|
65
|
+
expect(d.get_node('pool1').resources_added).to eq 0
|
66
|
+
expect(d.get_node('pool2').resources_added).to eq 2
|
67
|
+
|
68
|
+
expect(d.get_node('pool2').resources_removed).to eq 0
|
69
|
+
expect(d.get_node('pool1').resources_removed).to eq 2
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
it "runs for 2 turns with source and pool using PULL and add and remove the correct amount" do
|
74
|
+
|
75
|
+
d = Diagram.new 'some_name'
|
76
|
+
|
77
|
+
d.add_node! Source, name: 's1', activation: :automatic
|
78
|
+
|
79
|
+
d.add_node! Pool, name: 'pool2'
|
80
|
+
|
81
|
+
d.add_edge! Edge, name: 'edge', from: 's1', to: 'pool2'
|
82
|
+
|
83
|
+
d.run!(2)
|
84
|
+
|
85
|
+
|
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
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
it "runs for two turns with two pools using PUSH and there's the correct amount of resources at the end" do
|
94
|
+
|
95
|
+
d = Diagram.new 'some_name'
|
96
|
+
|
97
|
+
d.add_node! Pool, name: 'pool1', initial_value: 5, mode: :push_any, activation: :automatic
|
98
|
+
|
99
|
+
d.add_node! Pool, name: 'pool2'
|
100
|
+
|
101
|
+
d.add_edge! Edge, name: 'edge', from: 'pool1', to: 'pool2'
|
102
|
+
|
103
|
+
d.run!(2)
|
104
|
+
|
105
|
+
expect(d.get_node('pool1').resource_count).to eq 3
|
106
|
+
expect(d.get_node('pool2').resource_count).to eq 2
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
it "runs for a single turn with one source and two pools and there's the correct amount of resources at the end" do
|
111
|
+
p = Diagram.new('one source two pools')
|
112
|
+
|
113
|
+
p.add_node!(Source, {name: 'source'})
|
114
|
+
|
115
|
+
p.add_node!(Pool, {name: 'pool1'})
|
116
|
+
|
117
|
+
p.add_node!(Pool, {name: 'pool2', activation: :automatic})
|
118
|
+
|
119
|
+
p.add_edge!(Edge, {name: 'edge1', from: 'source', to: 'pool1'})
|
120
|
+
|
121
|
+
p.add_edge!(Edge, {name: 'connector2', from: 'pool1', to: 'pool2'})
|
122
|
+
|
123
|
+
p.run!(1)
|
124
|
+
|
125
|
+
expect(p.get_node('pool1').resource_count).to eq 1
|
126
|
+
expect(p.get_node('pool2').resource_count).to eq 0
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'takes staging and commit steps into account when run with 3 pools for 1 turn only' do
|
131
|
+
|
132
|
+
d = Diagram.new 'some_name'
|
133
|
+
|
134
|
+
d.add_node! Pool, name: 'pool1', initial_value: 2, mode: :push_any, activation: :automatic
|
135
|
+
|
136
|
+
d.add_node! Pool, name: 'pool2'
|
137
|
+
|
138
|
+
d.add_node! Pool, name: 'pool3', activation: :automatic
|
139
|
+
|
140
|
+
d.add_edge! Edge, name: 'edge1', from: 'pool1', to: 'pool2'
|
141
|
+
|
142
|
+
d.add_edge! Edge, name: 'edge2', from: 'pool2', to: 'pool3'
|
143
|
+
|
144
|
+
d.run!(1)
|
145
|
+
|
146
|
+
expect(d.get_node('pool1').resource_count).to eq 1
|
147
|
+
expect(d.get_node('pool2').resource_count).to eq 1
|
148
|
+
expect(d.get_node('pool3').resource_count).to eq 0
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'takes staging and commit steps into account when run with 3 pools for 4 turns' do
|
153
|
+
|
154
|
+
d = Diagram.new 'some_name'
|
155
|
+
|
156
|
+
d.add_node! Pool, name: 'pool1', initial_value: 10, mode: :push_any, activation: :automatic
|
157
|
+
|
158
|
+
d.add_node! Pool, name: 'pool2'
|
159
|
+
|
160
|
+
d.add_node! Pool, name: 'pool3', activation: :automatic
|
161
|
+
|
162
|
+
d.add_edge! Edge, name: 'edge1', from: 'pool1', to: 'pool2'
|
163
|
+
|
164
|
+
d.add_edge! Edge, name: 'edge2', from: 'pool2', to: 'pool3'
|
165
|
+
|
166
|
+
|
167
|
+
d.run!(4)
|
168
|
+
|
169
|
+
expect(d.get_node('pool1').resource_count).to eq 6
|
170
|
+
expect(d.get_node('pool2').resource_count).to eq 1
|
171
|
+
expect(d.get_node('pool3').resource_count).to eq 3
|
172
|
+
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'runs with a source and a pool and have the expected amount of resources at the end' do
|
177
|
+
|
178
|
+
d=Diagram.new 'simple'
|
179
|
+
|
180
|
+
|
181
|
+
d.add_node! Source, {
|
182
|
+
:name => 'source'
|
183
|
+
}
|
184
|
+
|
185
|
+
d.add_node! Pool, {
|
186
|
+
:name => 'deposit',
|
187
|
+
}
|
188
|
+
|
189
|
+
d.add_edge! Edge, {
|
190
|
+
:name => 'connector',
|
191
|
+
:from => 'source',
|
192
|
+
:to => 'deposit'
|
193
|
+
}
|
194
|
+
|
195
|
+
d.run!(10)
|
196
|
+
|
197
|
+
expect(d.get_node('deposit').resource_count).to eq 10
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'can be run until a given condition is true' do
|
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
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'aborts after specified turns as a safeguard against infinite loops given as stopping condition' do
|
222
|
+
|
223
|
+
d=Diagram.new 'simple'
|
224
|
+
d.max_iterations=9
|
225
|
+
|
226
|
+
d.add_node! Pool, {
|
227
|
+
:name => 'deposit',
|
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
|
+
}
|
238
|
+
|
239
|
+
d.run_while! { true == true }
|
240
|
+
|
241
|
+
#not hanging on forever is the success condition.
|
242
|
+
expect(d.get_node('deposit').resource_count).to eq 9
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'does not raise errors when active pushes or pulls are not possible' do
|
247
|
+
|
248
|
+
d = Diagram.new 'no errors'
|
249
|
+
|
250
|
+
d.add_node! Pool, name: 'Poor fella', initial_value: 5
|
251
|
+
|
252
|
+
d.add_node! Pool, name: 'Hungry fella', activation: :automatic
|
253
|
+
|
254
|
+
d.add_edge! Edge, name: 'edge1', from: 'Poor fella', to: 'Hungry fella'
|
255
|
+
|
256
|
+
expect { d.run! 10 }.not_to raise_error
|
257
|
+
|
258
|
+
expect(d.get_node('Hungry fella').resource_count).to eq 5
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
it "raises an error in case users try to access a node that doesn't exist" do
|
263
|
+
|
264
|
+
p = Diagram.new('get invalid node')
|
265
|
+
|
266
|
+
p.add_node! Source, name: 'source'
|
267
|
+
|
268
|
+
p.add_node! Pool, name: 'pool1'
|
269
|
+
|
270
|
+
p.add_edge! Edge, {
|
271
|
+
name: 'connector1',
|
272
|
+
from: 'source',
|
273
|
+
to: 'pool1'
|
274
|
+
}
|
275
|
+
|
276
|
+
# use curly brackets instead of parentheses here.
|
277
|
+
expect { p.get_node('pool') }.to raise_error RuntimeError
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'runs with typed nodes connected by typeless edges' do
|
282
|
+
|
283
|
+
p = Diagram.new('one source one pool typed')
|
284
|
+
|
285
|
+
p.add_node!(Source, name: 'source', :type => Green)
|
286
|
+
p.add_node!(Pool, name: 'pool1', :types => [Green, Red])
|
287
|
+
p.add_edge!(Edge, name: 'connector1', from: 'source', to: 'pool1')
|
288
|
+
|
289
|
+
p.run!(5)
|
290
|
+
|
291
|
+
expect(p.get_node('pool1').resource_count(Green)).to eq 5
|
292
|
+
expect(p.get_node('pool1').resource_count(Red)).to eq 0
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
it "allows untyped nodes to receive typed resources sent to them via untyped edges" do
|
297
|
+
|
298
|
+
p = Diagram.new 'balls'
|
299
|
+
|
300
|
+
p.add_node!(Source, name: 'source', :type => Football)
|
301
|
+
|
302
|
+
p.add_node!(Pool, name: 'pool1')
|
303
|
+
|
304
|
+
p.add_edge!(Edge, name: 'connector1', from: 'source', to: 'pool1')
|
305
|
+
|
306
|
+
p.run!(5)
|
307
|
+
|
308
|
+
expect(p.get_node('pool1').resource_count(Football)).to eq 5
|
309
|
+
|
310
|
+
end
|
311
|
+
|
312
|
+
it "allows untyped nodes to receive typed resources sent to them via typed edges" do
|
313
|
+
|
314
|
+
p = Diagram.new 'fruits'
|
315
|
+
|
316
|
+
#by declaring initial values, we're implicitly declaring types.
|
317
|
+
p.add_node! Pool, name: 'pool1', initial_value: {Peach => 20, Mango => 99}
|
318
|
+
|
319
|
+
p.add_node! Pool, name: 'pool2', activation: :automatic
|
320
|
+
|
321
|
+
p.add_edge!(Edge, name: 'connector1', from: 'pool1', to: 'pool2', types: [Peach])
|
322
|
+
|
323
|
+
p.run!(5)
|
324
|
+
|
325
|
+
expect(p.get_node('pool1').resource_count(Peach)).to eq 15
|
326
|
+
expect(p.get_node('pool1').resource_count(Mango)).to eq 99
|
327
|
+
expect(p.get_node('pool2').resource_count(Peach)).to eq 5
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
it "executes start nodes only once" do
|
332
|
+
|
333
|
+
d=Diagram.new 'simple'
|
334
|
+
|
335
|
+
d.add_node! Source, {
|
336
|
+
:name => 'source',
|
337
|
+
:activation => :start
|
338
|
+
}
|
339
|
+
|
340
|
+
d.add_node! Pool, {
|
341
|
+
:name => 'deposit',
|
342
|
+
:initial_value => 0
|
343
|
+
}
|
344
|
+
|
345
|
+
d.add_edge! Edge, {
|
346
|
+
:name => 'connector',
|
347
|
+
:from => 'source',
|
348
|
+
:to => 'deposit'
|
349
|
+
}
|
350
|
+
|
351
|
+
d.run!(10)
|
352
|
+
|
353
|
+
|
354
|
+
expect(d.get_node('deposit').resource_count).to eq 1
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'does not run disabled nodes from the beginning' do
|
359
|
+
|
360
|
+
d=Diagram.new 'simple'
|
361
|
+
|
362
|
+
d.add_node! Source, {
|
363
|
+
:name => 'source'
|
364
|
+
}
|
365
|
+
|
366
|
+
d.add_node! Pool, {
|
367
|
+
:name => 'deposit',
|
368
|
+
:initial_value => 0
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
d.add_edge! Edge, {
|
373
|
+
:name => 'connector',
|
374
|
+
:from => 'source',
|
375
|
+
:to => 'deposit'
|
376
|
+
}
|
377
|
+
|
378
|
+
d.get_node('source').attach_condition(lambda { false })
|
379
|
+
|
380
|
+
d.run!(10)
|
381
|
+
|
382
|
+
expect(d.resource_count).to eq 0
|
383
|
+
expect(d.get_node('deposit').resource_count).to eq 0
|
384
|
+
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'must not run disabled nodes at some point' do
|
388
|
+
|
389
|
+
#não entendi pra que serve esse teste
|
390
|
+
|
391
|
+
d=Diagram.new 'simple'
|
392
|
+
|
393
|
+
d.add_node! Source, {
|
394
|
+
:name => 'source'
|
395
|
+
}
|
396
|
+
|
397
|
+
d.add_node! Pool, {
|
398
|
+
:name => 'deposit',
|
399
|
+
:initial_value => 0
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
d.add_edge! Edge, {
|
404
|
+
:name => 'connector',
|
405
|
+
:from => 'source',
|
406
|
+
:to => 'deposit'
|
407
|
+
}
|
408
|
+
|
409
|
+
d.get_node('source').attach_condition(lambda { d.get_node('deposit').resource_count < 3 })
|
410
|
+
|
411
|
+
d.run!(10)
|
412
|
+
|
413
|
+
expect(d.resource_count).to eq 3
|
414
|
+
expect(d.get_node('deposit').resource_count).to eq 3
|
415
|
+
|
416
|
+
end
|
417
|
+
|
418
|
+
it 'runs when both ends (of an edge) are enabled' do
|
419
|
+
|
420
|
+
d=Diagram.new 'simple'
|
421
|
+
|
422
|
+
d.add_node! Source, {
|
423
|
+
:name => 'source'
|
424
|
+
}
|
425
|
+
|
426
|
+
d.add_node! Pool, {
|
427
|
+
:name => 'deposit',
|
428
|
+
:initial_value => 0
|
429
|
+
}
|
430
|
+
|
431
|
+
|
432
|
+
d.add_edge! Edge, {
|
433
|
+
:name => 'connector',
|
434
|
+
:from => 'source',
|
435
|
+
:to => 'deposit'
|
436
|
+
}
|
437
|
+
|
438
|
+
d.get_node('deposit').attach_condition(lambda { d.get_node('deposit').resource_count < 3 })
|
439
|
+
|
440
|
+
d.run!(10)
|
441
|
+
|
442
|
+
# expect(d.resource_count).to eq 3
|
443
|
+
expect(d.get_node('deposit').resource_count).to eq 3
|
444
|
+
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'makes triggers trig!' do
|
448
|
+
d=Diagram.new 'simple'
|
449
|
+
|
450
|
+
d.add_node! Source, {
|
451
|
+
:name => 'source'
|
452
|
+
}
|
453
|
+
|
454
|
+
d.add_node! Pool, {
|
455
|
+
:name => 'deposit',
|
456
|
+
:initial_value => 0
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
d.add_edge! Edge, {
|
461
|
+
:name => 'connector',
|
462
|
+
:from => 'source',
|
463
|
+
:to => 'deposit'
|
464
|
+
}
|
465
|
+
|
466
|
+
d.get_node('deposit').attach_trigger([lambda { d.get_node('deposit').resource_count === 3 }, d.get_node('source')])
|
467
|
+
|
468
|
+
d.run!(10)
|
469
|
+
|
470
|
+
expect(d.resource_count).to eq 11
|
471
|
+
expect(d.get_node('deposit').resource_count).to eq 11
|
472
|
+
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'makes triggers trig! more than once' do
|
476
|
+
d=Diagram.new 'simple'
|
477
|
+
|
478
|
+
d.add_node! Source, {
|
479
|
+
:name => 's1'
|
480
|
+
}
|
481
|
+
|
482
|
+
d.add_node! Pool, {
|
483
|
+
:name => 'd1',
|
484
|
+
:initial_value => 0
|
485
|
+
}
|
486
|
+
|
487
|
+
|
488
|
+
d.add_node! Source, {
|
489
|
+
:name => 's2',
|
490
|
+
:activation => :passive
|
491
|
+
}
|
492
|
+
|
493
|
+
d.add_edge! Edge, {
|
494
|
+
:name => 'c1',
|
495
|
+
:from => 's1',
|
496
|
+
:to => 'd1'
|
497
|
+
}
|
498
|
+
|
499
|
+
d.add_node! Pool, {
|
500
|
+
:name => 'd2',
|
501
|
+
:initial_value => 0
|
502
|
+
}
|
503
|
+
|
504
|
+
|
505
|
+
d.add_edge! Edge, {
|
506
|
+
:name => 'c2',
|
507
|
+
:from => 's2',
|
508
|
+
:to => 'd2'
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
d.get_node('d1').attach_trigger([lambda { d.get_node('d1').resource_count > 3 }, d.get_node('s1')])
|
513
|
+
d.get_node('d1').attach_trigger([lambda { d.get_node('d1').resource_count > 3 }, d.get_node('s2')])
|
514
|
+
#d.extend(Verbose)
|
515
|
+
d.run!(6)
|
516
|
+
|
517
|
+
expect(d.resource_count).to eq 10
|
518
|
+
expect(d.get_node('d1').resource_count).to eq 8
|
519
|
+
expect(d.get_node('d2').resource_count).to eq 2
|
520
|
+
|
521
|
+
end
|
522
|
+
|
523
|
+
it 'makes triggers trig! more than once with instant_resource_count' do
|
524
|
+
d=Diagram.new 'simple'
|
525
|
+
|
526
|
+
d.add_node! Source, {
|
527
|
+
:name => 's1'
|
528
|
+
}
|
529
|
+
|
530
|
+
d.add_node! Pool, {
|
531
|
+
:name => 'd1',
|
532
|
+
:initial_value => 0
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
d.add_node! Source, {
|
537
|
+
:name => 's2',
|
538
|
+
:activation => :passive
|
539
|
+
}
|
540
|
+
|
541
|
+
d.add_edge! Edge, {
|
542
|
+
:name => 'c1',
|
543
|
+
:from => 's1',
|
544
|
+
:to => 'd1'
|
545
|
+
}
|
546
|
+
|
547
|
+
d.add_node! Pool, {
|
548
|
+
:name => 'd2',
|
549
|
+
:initial_value => 0
|
550
|
+
}
|
551
|
+
|
552
|
+
|
553
|
+
d.add_edge! Edge, {
|
554
|
+
:name => 'c2',
|
555
|
+
:from => 's2',
|
556
|
+
:to => 'd2'
|
557
|
+
}
|
558
|
+
|
559
|
+
|
560
|
+
d.get_node('d1').attach_trigger([lambda { d.get_node('d1').instant_resource_count > 3 }, d.get_node('s1')])
|
561
|
+
d.get_node('d1').attach_trigger([lambda { d.get_node('d1').instant_resource_count > 3 }, d.get_node('s2')])
|
562
|
+
#d.extend(Verbose)
|
563
|
+
d.run!(6)
|
564
|
+
|
565
|
+
expect(d.resource_count).to eq 12
|
566
|
+
expect(d.get_node('d1').resource_count).to eq 9
|
567
|
+
expect(d.get_node('d2').resource_count).to eq 3
|
568
|
+
|
569
|
+
end
|
570
|
+
|
571
|
+
context 'integration' do
|
572
|
+
|
573
|
+
it ' makes a train run' do
|
574
|
+
|
575
|
+
d = Diagram.new 'dia'
|
576
|
+
|
577
|
+
d.add_node! Pool, {
|
578
|
+
name: 'p1',
|
579
|
+
mode: :push_any,
|
580
|
+
activation: :automatic,
|
581
|
+
initial_value: 8
|
582
|
+
}
|
583
|
+
|
584
|
+
d.add_node! Pool, {
|
585
|
+
name: 'p2',
|
586
|
+
mode: :push_any,
|
587
|
+
activation: :automatic
|
588
|
+
}
|
589
|
+
|
590
|
+
d.add_node! Pool, {
|
591
|
+
name: 'p3',
|
592
|
+
mode: :push_any,
|
593
|
+
activation: :automatic
|
594
|
+
}
|
595
|
+
|
596
|
+
d.add_node! Pool, {
|
597
|
+
name: 'p4',
|
598
|
+
mode: :push_any,
|
599
|
+
activation: :automatic
|
600
|
+
}
|
601
|
+
|
602
|
+
d.add_edge! Edge,{
|
603
|
+
name: 'e1',
|
604
|
+
from: 'p1',
|
605
|
+
to: 'p2'
|
606
|
+
}
|
607
|
+
d.add_edge! Edge,{
|
608
|
+
name: 'e2',
|
609
|
+
from: 'p2',
|
610
|
+
to: 'p3'
|
611
|
+
}
|
612
|
+
d.add_edge! Edge,{
|
613
|
+
name: 'e3',
|
614
|
+
from: 'p3',
|
615
|
+
to: 'p4'
|
616
|
+
}
|
617
|
+
|
618
|
+
d.run!(30)
|
619
|
+
|
620
|
+
expect(d.get_node('p1').resource_count).to eq 0
|
621
|
+
expect(d.get_node('p2').resource_count).to eq 0
|
622
|
+
expect(d.get_node('p3').resource_count).to eq 0
|
623
|
+
expect(d.get_node('p4').resource_count).to eq 8
|
624
|
+
|
625
|
+
end
|
626
|
+
|
627
|
+
end
|
628
|
+
|
629
|
+
context 'simple converter behaviour' do
|
630
|
+
it 'runs an untyped converter connected to two pools' do
|
631
|
+
|
632
|
+
d=Diagram.new 'simple'
|
633
|
+
|
634
|
+
d.add_node! Pool, {
|
635
|
+
:name => 'from',
|
636
|
+
:initial_value => 5
|
637
|
+
}
|
638
|
+
|
639
|
+
d.add_node! Pool, {
|
640
|
+
:name => 'to',
|
641
|
+
:initial_value => 0
|
642
|
+
}
|
643
|
+
|
644
|
+
d.add_node! Converter,{
|
645
|
+
:name => 'c',
|
646
|
+
:activation => :automatic
|
647
|
+
}
|
648
|
+
|
649
|
+
d.add_edge! Edge, {
|
650
|
+
:name => 'c1',
|
651
|
+
:from => 'from',
|
652
|
+
:to => 'c'
|
653
|
+
}
|
654
|
+
|
655
|
+
d.add_edge! Edge, {
|
656
|
+
:name => 'c2',
|
657
|
+
:from => 'c',
|
658
|
+
:to => 'to'
|
659
|
+
}
|
660
|
+
|
661
|
+
d.run!(4)
|
662
|
+
|
663
|
+
expect(d.get_node('to').resource_count).to eq 4
|
664
|
+
|
665
|
+
end
|
666
|
+
|
667
|
+
|
668
|
+
end
|
669
|
+
|
670
|
+
|
671
|
+
end
|