rachinations 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -16
  3. data/Gemfile.lock +2 -0
  4. data/lib/rachinations/domain/diagrams/diagram.rb +46 -14
  5. data/lib/rachinations/domain/edges/edge.rb +34 -20
  6. data/lib/rachinations/domain/modules/common/hash_init.rb +2 -1
  7. data/lib/rachinations/domain/modules/common/invariant.rb +2 -2
  8. data/lib/rachinations/domain/modules/common/refiners/number_modifiers.rb +22 -0
  9. data/lib/rachinations/domain/nodes/converter.rb +5 -5
  10. data/lib/rachinations/domain/nodes/gate.rb +77 -0
  11. data/lib/rachinations/domain/nodes/node.rb +69 -36
  12. data/lib/rachinations/domain/nodes/pool.rb +121 -74
  13. data/lib/rachinations/domain/nodes/resourceful_node.rb +0 -1
  14. data/lib/rachinations/domain/nodes/sink.rb +3 -0
  15. data/lib/rachinations/domain/nodes/source.rb +3 -2
  16. data/lib/rachinations/domain/resource_bag.rb +3 -4
  17. data/lib/rachinations/dsl/bad_dsl.rb +2 -0
  18. data/lib/rachinations/dsl/bootstrap.rb +59 -0
  19. data/lib/rachinations/dsl/diagram_shorthand_methods.rb +107 -0
  20. data/lib/rachinations/dsl/helpers/parser.rb +170 -0
  21. data/lib/rachinations/extras/constant_hash.rb +25 -0
  22. data/lib/rachinations/extras/fifo.rb +25 -19
  23. data/lib/rachinations/helpers/edge_helper.rb +40 -0
  24. data/lib/rachinations/utils/string_helper.rb +7 -0
  25. data/lib/rachinations/version.rb +1 -1
  26. data/lib/rachinations.rb +13 -5
  27. data/rachinations.gemspec +3 -2
  28. data/testing/simulations/modelo1.rb +1 -1
  29. data/testing/simulations/sequencial.rb +1 -1
  30. data/testing/simulations/sobonito.rb +1 -1
  31. data/testing/simulations/sobonitowhile.rb +1 -1
  32. data/testing/simulations/whatIwish1.rb +2 -2
  33. data/testing/spec/canon/conditions_spec.rb +3 -4
  34. data/testing/spec/converter_spec.rb +3 -4
  35. data/testing/spec/diagram_spec.rb +293 -238
  36. data/testing/spec/edge_spec.rb +28 -14
  37. data/testing/spec/gate_spec.rb +34 -0
  38. data/testing/spec/pool_spec.rb +8 -10
  39. data/testing/spec/release1/dsl_spec.rb +204 -0
  40. data/testing/spec/spec_helper.rb +1 -0
  41. data/testing/spec/xexeo_spec.rb +39 -40
  42. metadata +30 -8
  43. data/lib/rachinations/domain/edges/random_edge.rb +0 -4
  44. data/lib/rachinations/dsl/dsl.rb +0 -63
  45. data/testing/spec/canon/trigger_spec.rb +0 -128
@@ -1,63 +0,0 @@
1
- require_relative '../domain/diagrams/diagram'
2
- require_relative '../domain/diagrams/verbose_diagram'
3
- require_relative '../domain/diagrams/non_deterministic_diagram'
4
- require_relative '../domain/modules/diagrams/verbose'
5
-
6
- module DSL
7
-
8
- class ::Diagram
9
-
10
- # convenience method
11
- def node(name,klass,hsh={})
12
-
13
- hsh[:name] = name
14
-
15
- add_node! klass, hsh
16
- end
17
-
18
- # convenience method
19
- def edge(name,klass,from,to,hsh={})
20
-
21
- hsh[:name] = name
22
- hsh[:from] = from
23
- hsh[:to] = to
24
-
25
- add_edge! klass,hsh
26
- end
27
-
28
- end
29
-
30
-
31
- def diagram(name,verbose=:silent,&blk)
32
-
33
- if verbose === :verbose
34
- dia= VerboseDiagram.new name
35
- else
36
- dia = Diagram.new name
37
- end
38
-
39
- dia.instance_eval &blk
40
-
41
- dia
42
-
43
- end
44
-
45
- def non_deterministic_diagram(name,verbose=:silent,&blk)
46
-
47
- dia=NonDeterministicDiagram.new name
48
- if verbose === :verbose
49
- dia.extend(Verbose)
50
- end
51
-
52
- dia.instance_eval &blk
53
-
54
- dia
55
-
56
- end
57
-
58
- #add these methods to existing class Diagram here
59
- #because it doesn't need to know about it
60
-
61
-
62
-
63
- end
@@ -1,128 +0,0 @@
1
- require_relative '../spec_helper'
2
-
3
- describe 'triggers' do
4
-
5
- it 'makes triggers trig!' do
6
- d=Diagram.new 'simple'
7
-
8
- d.add_node! Source, {
9
- :name => 'source'
10
- }
11
-
12
- d.add_node! Pool, {
13
- :name => 'deposit',
14
- :initial_value => 0
15
- }
16
-
17
-
18
- d.add_edge! Edge, {
19
- :name => 'connector',
20
- :from => 'source',
21
- :to => 'deposit'
22
- }
23
-
24
- d.get_node('deposit').attach_trigger([lambda { d.get_node('deposit').resource_count === 3 }, d.get_node('source')])
25
-
26
- d.run!(10)
27
-
28
- expect(d.resource_count).to eq 11
29
- expect(d.get_node('deposit').resource_count).to eq 11
30
-
31
- end
32
-
33
- it 'makes triggers trig! more than once' do
34
- d=Diagram.new 'simple'
35
-
36
- d.add_node! Source, {
37
- :name => 's1'
38
- }
39
-
40
- d.add_node! Pool, {
41
- :name => 'd1',
42
- :initial_value => 0
43
- }
44
-
45
-
46
- d.add_node! Source, {
47
- :name => 's2',
48
- :activation => :passive
49
- }
50
-
51
- d.add_edge! Edge, {
52
- :name => 'c1',
53
- :from => 's1',
54
- :to => 'd1'
55
- }
56
-
57
- d.add_node! Pool, {
58
- :name => 'd2',
59
- :initial_value => 0
60
- }
61
-
62
-
63
- d.add_edge! Edge, {
64
- :name => 'c2',
65
- :from => 's2',
66
- :to => 'd2'
67
- }
68
-
69
-
70
- d.get_node('d1').attach_trigger([lambda { d.get_node('d1').resource_count > 3 }, d.get_node('s1')])
71
- d.get_node('d1').attach_trigger([lambda { d.get_node('d1').resource_count > 3 }, d.get_node('s2')])
72
- #d.extend(Verbose)
73
- d.run!(6)
74
-
75
- expect(d.resource_count).to eq 10
76
- expect(d.get_node('d1').resource_count).to eq 8
77
- expect(d.get_node('d2').resource_count).to eq 2
78
-
79
- end
80
-
81
- it 'makes triggers trig! more than once with instant_resource_count' do
82
- d=Diagram.new 'simple'
83
-
84
- d.add_node! Source, {
85
- :name => 's1'
86
- }
87
-
88
- d.add_node! Pool, {
89
- :name => 'd1',
90
- :initial_value => 0
91
- }
92
-
93
-
94
- d.add_node! Source, {
95
- :name => 's2',
96
- :activation => :passive
97
- }
98
-
99
- d.add_edge! Edge, {
100
- :name => 'c1',
101
- :from => 's1',
102
- :to => 'd1'
103
- }
104
-
105
- d.add_node! Pool, {
106
- :name => 'd2',
107
- :initial_value => 0
108
- }
109
-
110
-
111
- d.add_edge! Edge, {
112
- :name => 'c2',
113
- :from => 's2',
114
- :to => 'd2'
115
- }
116
-
117
-
118
- d.get_node('d1').attach_trigger([lambda { d.get_node('d1').instant_resource_count > 3 }, d.get_node('s1')])
119
- d.get_node('d1').attach_trigger([lambda { d.get_node('d1').instant_resource_count > 3 }, d.get_node('s2')])
120
- #d.extend(Verbose)
121
- d.run!(6)
122
-
123
- expect(d.resource_count).to eq 12
124
- expect(d.get_node('d1').resource_count).to eq 9
125
- expect(d.get_node('d2').resource_count).to eq 3
126
-
127
- end
128
- end