rachinations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 760155c227543c780d0ce31b94b0f3f7ac2f287d
4
- data.tar.gz: ef961b92ed034f84795ab44a32eebbbaadd3ccda
3
+ metadata.gz: 49ee8fa5ba3a2fd67f645d651f16675e2a93d723
4
+ data.tar.gz: be88690c64ece75e4d1af590dec1a06837bd914c
5
5
  SHA512:
6
- metadata.gz: 870ef895b064df8bb9c42304f076f8385405cc63bab61bd7c4c634cfb2baecf0c11e55541c2cb8c3f9a463b876fd210000e0957e206a125eee35870c9708eb35
7
- data.tar.gz: 362d1cb7f3a10c540c6188d425f289bb74db600f6da9f2af5c145c6c486311bbbfb51217d544cc312e14ddac5106225c2d80461d15016729ec00a4b7ddbaf23f
6
+ metadata.gz: 0159177f5cd1b84731efa5057767eb6317aabd9dd6f082d61d2dfc1d0a62989e3c8900e0595adf84d2d5c7e7371ee6e7e3c5e53d73e1aaa369776c542245b342
7
+ data.tar.gz: 243693a7ceff066b8649510c3cc7655ab49a1ac633a82633472726a7e050c7ec5bdba5a0eab08610052ef05ade0516d1a07987f7224ef465e8ea108f5ec82611
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rachinations (0.0.1)
4
+ rachinations (0.0.3)
5
5
  activesupport (= 3.0.0)
6
6
  i18n (= 0.6.11)
7
7
 
@@ -17,20 +17,10 @@ GEM
17
17
  simplecov (>= 0.7)
18
18
  term-ansicolor
19
19
  thor
20
- cucumber (1.3.16)
21
- builder (>= 2.1.2)
22
- diff-lcs (>= 1.1.3)
23
- gherkin (~> 2.12)
24
- multi_json (>= 1.7.5, < 2.0)
25
- multi_test (>= 0.1.1)
26
20
  diff-lcs (1.2.5)
27
21
  docile (1.1.5)
28
22
  ffi (1.9.3-x64-mingw32)
29
23
  ffi (1.9.3-x86-mingw32)
30
- gherkin (2.12.2)
31
- multi_json (~> 1.3)
32
- gherkin (2.12.2-x86-mingw32)
33
- multi_json (~> 1.3)
34
24
  i18n (0.6.11)
35
25
  mime-types (2.3)
36
26
  minitest (5.4.0)
@@ -40,7 +30,6 @@ GEM
40
30
  minitest (>= 5.0)
41
31
  ruby-progressbar
42
32
  multi_json (1.10.1)
43
- multi_test (0.1.1)
44
33
  netrc (0.7.7)
45
34
  rake (10.3.2)
46
35
  rest-client (1.7.2)
@@ -84,10 +73,9 @@ PLATFORMS
84
73
 
85
74
  DEPENDENCIES
86
75
  bundler (~> 1.5)
87
- coveralls
88
- cucumber
89
- minitest
90
- minitest-reporters
76
+ coveralls (= 0.7.0)
77
+ minitest (~> 5.4)
78
+ minitest-reporters (~> 1.0)
91
79
  rachinations!
92
- rake
80
+ rake (~> 10.3)
93
81
  rspec (~> 3.0)
data/README.md CHANGED
@@ -7,7 +7,9 @@ rachinations
7
7
 
8
8
  ### Introduction
9
9
 
10
- This is a port of Dr. J. Dormans' Machinations framework into Ruby.
10
+ This is a port of Dr. J. Dormans' [Machinations framework](http://www.jorisdormans.nl/machinations/) into Ruby.
11
+
12
+ It provides a Ruby-based DSL to enable game designers to create and also test tentative game designs and/or prototypes.
11
13
 
12
14
  ### Contents
13
15
 
@@ -15,5 +17,26 @@ This is a port of Dr. J. Dormans' Machinations framework into Ruby.
15
17
  - Tests
16
18
  - A simple DSL (Domain-specific language) whose objective is to enable anyone to write Machinations diagrams, run them, obtain metrics, compose subdiagrams and so on.
17
19
 
18
- ### Usage
19
- - TODO
20
+ ### DSL Usage
21
+ - Simplest possible usage:
22
+ - Install the `rachinations` [gem](http://rubygems.org/gems/rachinations)
23
+
24
+ ```
25
+ $ gem install rachinations
26
+ ```
27
+ - Require it into your code and start designing diagrams:
28
+
29
+ ```ruby
30
+ require 'rachinations'
31
+
32
+ n=diagram 'my diagram' do
33
+ node 's1',Source
34
+ node 'p1', Pool
35
+ edge 'e1', Edge, 's1','p1'
36
+ end
37
+
38
+ n.run!(5)
39
+
40
+ p n.get_node("p1").resource_count
41
+ #prints 5
42
+ ```
@@ -102,6 +102,17 @@ class Diagram
102
102
 
103
103
  end
104
104
 
105
+
106
+ def resource_count(klass=nil)
107
+ total=0
108
+ @nodes.each do |n|
109
+ total+=n.resource_count(klass)
110
+ end
111
+ total
112
+ end
113
+
114
+ private
115
+
105
116
  def to_s
106
117
  nodes.reduce('') { |carry, n| carry+n.to_s }
107
118
  end
@@ -136,15 +147,6 @@ class Diagram
136
147
  nodes.shuffle.each { |n| n.commit! }
137
148
  end
138
149
 
139
-
140
- def resource_count(klass=nil)
141
- total=0
142
- @nodes.each do |n|
143
- total+=n.resource_count(klass)
144
- end
145
- total
146
- end
147
-
148
150
  def enabled_nodes
149
151
  nodes.select{|n| n.enabled? }
150
152
  end
@@ -0,0 +1,18 @@
1
+ module ProcConvenienceMethods
2
+
3
+ # A few extra methods
4
+ # to make code read more intuitively.
5
+ refine Proc do
6
+
7
+ alias_method :accepts?, :call
8
+ alias_method :accept?, :call
9
+
10
+ alias_method :match?, :call
11
+ alias_method :matches?, :call
12
+
13
+ alias_method :match_resource?, :call
14
+ alias_method :matches_resource?, :call
15
+
16
+ end
17
+
18
+ end
@@ -1,5 +1,8 @@
1
1
  require_relative '../../domain/nodes/node'
2
2
  require_relative '../../domain/nodes/resourceless_node'
3
+ require_relative '../../domain/modules/common/refiners/proc_convenience_methods'
4
+
5
+ using ProcConvenienceMethods
3
6
 
4
7
  class Converter < ResourcefulNode
5
8
 
@@ -52,7 +55,7 @@ class Converter < ResourcefulNode
52
55
  if in_conditions_met?
53
56
  if outgoing_edges.all? { |edge| edge.test_push?(true) }
54
57
  push_all!
55
- pop_stored_resources!
58
+ clear_stored_resources!
56
59
  end # converters are always push_all
57
60
  end # conditions weren't met this turn
58
61
 
@@ -127,8 +130,11 @@ class Converter < ResourcefulNode
127
130
 
128
131
  # This removes from the internal store just enough
129
132
  # resources to accomplish one push_all (only applicable when in pull_any mode)
130
- def pop_stored_resources!
131
- #TODO
133
+ def clear_stored_resources!
134
+ incoming_edges
135
+ .each do |edge|
136
+ edge.label.times{remove_from_contributed_resources!(edge)}
137
+ end
132
138
  end
133
139
 
134
140
 
@@ -257,6 +263,13 @@ class Converter < ResourcefulNode
257
263
  resources_contributed.fetch(edge).put!(resource)
258
264
  end
259
265
 
266
+ # Once a Converter has 'converted', we must alter its state so that
267
+ # contributions across turns don't cause more conversions than they
268
+ # should.
269
+ def remove_from_contributed_resources!(edge)
270
+ resources_contributed.fetch(edge).take!
271
+ end
272
+
260
273
  def init_resources
261
274
  edges.reduce(Hash.new) { |hash, edge| hash.store(edge.object_id, Fifo.new) }
262
275
  end
@@ -3,8 +3,11 @@ require_relative '../../domain/nodes/node'
3
3
  require_relative '../../domain/resources/token'
4
4
  require_relative '../resource_bag'
5
5
  require_relative '../../domain/exceptions/no_elements_matching_condition_error'
6
+ require_relative '../../domain/modules/common/refiners/proc_convenience_methods'
6
7
 
7
8
 
9
+ using ProcConvenienceMethods
10
+
8
11
  class Pool < ResourcefulNode
9
12
 
10
13
  def initialize(hsh={})
@@ -132,7 +135,7 @@ class Pool < ResourcefulNode
132
135
  end
133
136
 
134
137
  def to_s
135
- "Pool '#{@name}': #{@resources.to_s}"
138
+ "Pool '#{@name}': #{resources} "
136
139
  end
137
140
 
138
141
  # TODO this smells. where is this used? can i do without it?
@@ -1,6 +1,10 @@
1
1
  require 'set'
2
2
  require_relative '../../domain/resources/token'
3
3
  require_relative '../../domain/nodes/node'
4
+ require_relative '../../domain/modules/common/refiners/proc_convenience_methods'
5
+
6
+
7
+ using ProcConvenienceMethods
4
8
 
5
9
  class ResourcefulNode < Node
6
10
 
@@ -28,7 +28,7 @@ class Source < ResourcefulNode
28
28
  end
29
29
 
30
30
  def to_s
31
- "Source '#{@name}': #{@resources.to_s}"
31
+ "Source '#{@name}': \n"
32
32
  end
33
33
 
34
34
  def put_resource!;
@@ -19,27 +19,18 @@ class ResourceBag
19
19
  @store.push(obj)
20
20
  end
21
21
 
22
- #retrieve
23
- def get(klass)
24
-
25
- if count(klass) === 0
26
- raise NoElementsOfGivenTypeError, "No elements of class #{klass} found."
27
- end
28
-
29
- obj = store.select { |el| el.is_a?(klass) }.sample
30
-
31
- remove_element!(obj)
32
- obj
33
-
34
- end
35
-
36
- def count(klass)
37
-
38
- inv { klass.is_a?(Class) }
39
-
40
- store.select { |el| el.is_a?(klass) }.length
41
-
42
- end
22
+ # Returns how many resources of given type there are
23
+ # Note that this method includes locked resources in the count.
24
+ #
25
+ # @param [Class] resource type
26
+ # @return []Int] quantity of resources (including locked)
27
+ # def count(klass)
28
+ #
29
+ # inv { klass.is_a?(Class) }
30
+ #
31
+ # store.select { |el| el.is_a?(klass) }.length
32
+ #
33
+ # end
43
34
 
44
35
  def count_where(&blk)
45
36
 
@@ -73,20 +64,7 @@ class ResourceBag
73
64
 
74
65
  end
75
66
 
76
- # created so that I don't have to call count everytime just to see whether there's at least one element matching said condition
77
- def theres_at_least_one_where
78
-
79
- raise ArgumentError, 'Please supply a block containing the condition.' unless block_given?
80
-
81
- store.each do |e|
82
- if e.unlocked? && (yield e)
83
- return true
84
- end
85
- end
86
-
87
- false
88
-
89
- end
67
+ private
90
68
 
91
69
  def to_s
92
70
  out = ''
@@ -96,12 +74,15 @@ class ResourceBag
96
74
  classes.each do |klass|
97
75
 
98
76
  name = if klass.name.nil?
99
- 'Anonymous Klass'
77
+ 'Anonymous Token'
100
78
  else
101
79
  klass.name
102
80
  end
103
81
 
104
- out += "\n"+' '+ name + ' -> '+ count(klass).to_s+"\n\n"
82
+ unlocked = count_where{|r| (r.is_type? klass) && (r.unlocked?) }
83
+ locked = count_where{|r| (r.is_type? klass) && (r.locked?) }
84
+
85
+ out += "\n #{name} -> #{unlocked} (#{locked}) \n\n"
105
86
  end
106
87
 
107
88
  if classes.empty?
@@ -113,8 +94,20 @@ class ResourceBag
113
94
 
114
95
  end
115
96
 
116
- private
97
+ # created so that I don't have to call count everytime just to see whether there's at least one element matching said condition
98
+ def theres_at_least_one_where
117
99
 
100
+ raise ArgumentError, 'Please supply a block containing the condition.' unless block_given?
101
+
102
+ store.each do |e|
103
+ if e.unlocked? && (yield e)
104
+ return true
105
+ end
106
+ end
107
+
108
+ false
109
+
110
+ end
118
111
 
119
112
  def store
120
113
  @store
@@ -1,3 +1,3 @@
1
1
  module Rachinations
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rachinations.rb CHANGED
@@ -3,21 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'rachinations/version'
4
4
 
5
5
 
6
- # A few extra methods
7
- # to make code read more intuitively.
8
- class Proc
9
-
10
- alias_method :accepts?, :call
11
- alias_method :accept?, :call
12
-
13
- alias_method :match?, :call
14
- alias_method :matches?, :call
15
-
16
- alias_method :match_resource?, :call
17
- alias_method :matches_resource?, :call
18
-
19
- end
20
6
 
7
+ require 'rachinations/domain/modules/common/refiners/proc_convenience_methods'
21
8
  require 'rachinations/extras/fifo'
22
9
 
23
10
  require 'rachinations/domain/diagrams/diagram'
data/rachinations.gemspec CHANGED
@@ -22,12 +22,11 @@ design and also test tentative game designs and/or prototypes}
22
22
  spec.required_ruby_version = '~> 2.1'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
- spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rake", "~> 10.3"
26
26
  spec.add_development_dependency "rspec","~> 3.0"
27
- spec.add_development_dependency "minitest"
28
- spec.add_development_dependency "minitest-reporters"
29
- spec.add_development_dependency "cucumber"
30
- spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "minitest", "~> 5.4"
28
+ spec.add_development_dependency "minitest-reporters", "~> 1.0"
29
+ spec.add_development_dependency "coveralls", "0.7.0"
31
30
 
32
31
  spec.add_dependency "activesupport","3.0.0"
33
32
  spec.add_dependency "i18n","0.6.11"
@@ -0,0 +1,95 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'Nodes that can be given conditions' do
4
+
5
+ it 'does not run disabled nodes from the beginning' do
6
+
7
+ d=Diagram.new 'simple'
8
+
9
+ d.add_node! Source, {
10
+ :name => 'source'
11
+ }
12
+
13
+ d.add_node! Pool, {
14
+ :name => 'deposit',
15
+ :initial_value => 0
16
+ }
17
+
18
+
19
+ d.add_edge! Edge, {
20
+ :name => 'connector',
21
+ :from => 'source',
22
+ :to => 'deposit'
23
+ }
24
+
25
+ d.get_node('source').attach_condition(lambda { false })
26
+
27
+ d.run!(10)
28
+
29
+ expect(d.resource_count).to eq 0
30
+ expect(d.get_node('deposit').resource_count).to eq 0
31
+
32
+ end
33
+
34
+ it 'must not run disabled nodes at some point' do
35
+
36
+ #não entendi pra que serve esse teste
37
+
38
+ d=Diagram.new 'simple'
39
+
40
+ d.add_node! Source, {
41
+ :name => 'source'
42
+ }
43
+
44
+ d.add_node! Pool, {
45
+ :name => 'deposit',
46
+ :initial_value => 0
47
+ }
48
+
49
+
50
+ d.add_edge! Edge, {
51
+ :name => 'connector',
52
+ :from => 'source',
53
+ :to => 'deposit'
54
+ }
55
+
56
+ d.get_node('source').attach_condition(lambda { d.get_node('deposit').resource_count < 3 })
57
+
58
+ d.run!(10)
59
+
60
+ expect(d.resource_count).to eq 3
61
+ expect(d.get_node('deposit').resource_count).to eq 3
62
+
63
+ end
64
+
65
+ it 'runs when both ends (of an edge) are enabled' do
66
+
67
+ d= Diagram.new 'simple'
68
+
69
+ d.add_node! Source, {
70
+ :name => 'source'
71
+ }
72
+
73
+ d.add_node! Pool, {
74
+ :name => 'deposit',
75
+ :initial_value => 0
76
+ }
77
+
78
+
79
+ d.add_edge! Edge, {
80
+ :name => 'connector',
81
+ :from => 'source',
82
+ :to => 'deposit'
83
+ }
84
+
85
+ d.get_node('deposit').attach_condition(lambda { d.get_node('deposit').resource_count < 3 })
86
+
87
+ d.run!(10)
88
+
89
+ # expect(d.resource_count).to eq 3
90
+ expect(d.get_node('deposit').resource_count).to eq 3
91
+
92
+ end
93
+
94
+
95
+ end
@@ -2,32 +2,167 @@ require_relative '../spec_helper'
2
2
 
3
3
  describe 'Converter canonical behavior' do
4
4
 
5
- context "there's just one pool on each side" do
5
+ it 'pulls_any' do
6
6
 
7
- before(:each) {
8
- @d = Diagram.new 'foo'
9
- @d.add_node! Pool, name: 'p9', initial_value: 9
10
- @d.add_node! Pool, name: 'p0'
11
- @d.add_node! Converter, name: 'c', mode: :pull_any
12
- @d.add_edge! Edge, name:'e1', from: 'p9', to: 'c'
13
- @d.add_edge! Edge, name:'e2',from: 'c', to: 'p0'
14
- }
15
- it 'is triggered by itself' do
16
- c = @d.get_node 'c'
17
- p0 = @d.get_node('p0')
18
- p9 = @d.get_node('p9')
7
+ d = Diagram.new 'foo'
8
+ d.add_node! Pool, name: 'p9', initial_value: 9
9
+ d.add_node! Pool, name: 'p0'
10
+ d.add_node! Converter, name: 'c', mode: :pull_any, activation: :automatic
11
+ d.add_edge! Edge, name: 'e1', from: 'p9', to: 'c'
12
+ d.add_edge! Edge, name: 'e2', from: 'c', to: 'p0'
19
13
 
20
- 5.times{ c.trigger! }
14
+ c = d.get_node 'c'
15
+ p0 = d.get_node('p0')
16
+ p9 = d.get_node('p9')
21
17
 
22
- # to unlock the resources
23
- @d.get_node('p0').commit!
24
- @d.get_node('p9').commit!
18
+ d.run!(5)
25
19
 
26
- expect(@d.get_node('p0').resource_count).to eq 5
27
- expect(@d.get_node('p9').resource_count).to eq 4
20
+ expect(p0.resource_count).to eq 5
21
+ expect(p9.resource_count).to eq 4
28
22
 
23
+ end
24
+
25
+
26
+ it 'pulls_any to two targets' do
27
+
28
+ d = Diagram.new 'foo'
29
+ d.add_node! Pool, name: 'p9', initial_value: 9
30
+ d.add_node! Pool, name: 'p1'
31
+ d.add_node! Pool, name: 'p2'
32
+ d.add_node! Converter, name: 'c', mode: :pull_any
33
+ d.add_edge! Edge, name: 'e1', from: 'p9', to: 'c'
34
+ d.add_edge! Edge, name: 'e2', from: 'c', to: 'p1'
35
+ d.add_edge! Edge, name: 'e3', from: 'c', to: 'p2'
36
+
37
+ c = d.get_node 'c'
38
+ p1 = d.get_node('p1')
39
+ p2 = d.get_node('p2')
40
+ p9 = d.get_node('p9')
41
+
42
+ 5.times { c.trigger! }
43
+
44
+ # to unlock the resources
45
+ p1.commit!
46
+ p2.commit!
47
+ p9.commit!
48
+
49
+ expect(p1.resource_count).to eq 5
50
+ expect(p2.resource_count).to eq 5
51
+ expect(p9.resource_count).to eq 4
52
+
53
+ end
54
+
55
+ it 'pulls_any from two sources' do
56
+
57
+ d = Diagram.new 'foo'
58
+ d.add_node! Pool, name: 'p1', initial_value: 9
59
+ d.add_node! Pool, name: 'p2', initial_value: 3
60
+ d.add_node! Pool, name: 'p3'
61
+ d.add_node! Pool, name: 'p4'
62
+ d.add_node! Converter, name: 'c', mode: :pull_any
63
+ d.add_edge! Edge, name: 'e1', from: 'p1', to: 'c'
64
+ d.add_edge! Edge, name: 'e2', from: 'p2', to: 'c'
65
+ d.add_edge! Edge, name: 'e3', from: 'c', to: 'p3'
66
+ d.add_edge! Edge, name: 'e4', from: 'c', to: 'p4'
67
+
68
+ c = d.get_node 'c'
69
+ p1 = d.get_node('p1')
70
+ p2 = d.get_node('p2')
71
+ p3 = d.get_node('p3')
72
+ p4 = d.get_node('p4')
73
+
74
+ 5.times { c.trigger! }
75
+
76
+ # to unlock the resources
77
+ p1.commit!
78
+ p2.commit!
79
+ p3.commit!
80
+ p4.commit!
81
+
82
+ expect(p1.resource_count).to eq 4
83
+ expect(p2.resource_count).to eq 0
84
+ expect(p3.resource_count).to eq 3
85
+ expect(p4.resource_count).to eq 3
86
+
87
+ end
88
+
89
+ it "pulls_all from a single source" do
90
+ d = Diagram.new 'foo'
91
+ d.add_node! Pool, name: 'p1', initial_value: 9
92
+ d.add_node! Pool, name: 'p2'
93
+ d.add_node! Converter, name: 'c', mode: :pull_all
94
+ d.add_edge! Edge, name: 'e1', from: 'p1', to: 'c'
95
+ d.add_edge! Edge, name: 'e2', from: 'c', to: 'p2'
96
+
97
+ c = d.get_node 'c'
98
+ p1 = d.get_node('p1')
99
+ p2 = d.get_node('p2')
100
+
101
+ 5.times { c.trigger! }
29
102
 
30
- end
103
+ # to unlock the resources
104
+ p1.commit!
105
+ p2.commit!
31
106
 
107
+ expect(p1.resource_count).to eq 4
108
+ expect(p2.resource_count).to eq 5
32
109
  end
110
+
111
+ it 'pulls_all from multiple sources' do
112
+
113
+ d = Diagram.new 'foo'
114
+ d.add_node! Pool, name: 'p1', initial_value: 9
115
+ d.add_node! Pool, name: 'p2', initial_value: 3
116
+ d.add_node! Pool, name: 'p3', initial_value: 5
117
+ d.add_node! Pool, name: 'p4'
118
+ d.add_node! Pool, name: 'p5'
119
+
120
+ d.add_node! Converter, name: 'c', mode: :pull_all, activation: :automatic
121
+ d.add_edge! Edge, name: 'e1', from: 'p1', to: 'c', label: 2
122
+ d.add_edge! Edge, name: 'e2', from: 'p2', to: 'c'
123
+ d.add_edge! Edge, name: 'e3', from: 'p3', to: 'c'
124
+ d.add_edge! Edge, name: 'e4', from: 'c', to: 'p4'
125
+ d.add_edge! Edge, name: 'e5', from: 'c', to: 'p5'
126
+
127
+ d.run! 5
128
+
129
+ expect(d.get_node('p1').resource_count).to eq 3
130
+ expect(d.get_node('p2').resource_count).to eq 0
131
+ expect(d.get_node('p3').resource_count).to eq 2
132
+ expect(d.get_node('p4').resource_count).to eq 3
133
+ expect(d.get_node('p5').resource_count).to eq 3
134
+ end
135
+
136
+ it 'pulls_any across turns (converter has memory)' do
137
+
138
+ # converter should keep pulling_any as long as it can
139
+ # but only when the conditions are satisfied for _both_
140
+ # incoming edges.
141
+
142
+ d = Diagram.new 'foo'
143
+
144
+ d.add_node! Pool, name: 'p1', initial_value:8
145
+ d.add_node! Source, name: 's' # default automatic
146
+ d.add_node! Pool, name: 'p2' # default zero resources
147
+
148
+ d.add_node! Converter, name: 'c', mode: :pull_any,activation: :automatic
149
+
150
+ d.add_node! Pool, name: 'p3'
151
+
152
+ d.add_edge! Edge, name: 'e1', from: 'p1', to:'c', label: 3
153
+ d.add_edge! Edge, name: 'e2', from: 'p2', to:'c', label: 2
154
+ d.add_edge! Edge, name: 'e3', from: 's', to:'p2'
155
+ d.add_edge! Edge, name: 'e4', from: 'c', to:'p3'
156
+
157
+ d.run! 10
158
+
159
+ expect(d.get_node('p3').resource_count).to eq 2
160
+
161
+ # they get consumed as it is pull any
162
+ expect(d.get_node('p1').resource_count).to eq 0
163
+
164
+
165
+
166
+ end
167
+
33
168
  end
@@ -0,0 +1,128 @@
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
@@ -355,218 +355,7 @@ describe Diagram do
355
355
 
356
356
  end
357
357
 
358
- it 'does not run disabled nodes from the beginning' do
359
358
 
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
359
 
571
360
  context 'integration' do
572
361
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rachinations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Almeida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,58 +56,44 @@ dependencies:
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '5.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-reporters
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: cucumber
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
73
+ - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: '0'
75
+ version: '1.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - ">="
80
+ - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: '1.0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: coveralls
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - ">="
87
+ - - '='
102
88
  - !ruby/object:Gem::Version
103
- version: '0'
89
+ version: 0.7.0
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - ">="
94
+ - - '='
109
95
  - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: 0.7.0
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: activesupport
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +154,7 @@ files:
168
154
  - lib/rachinations/domain/exceptions/unsupported_type_error.rb
169
155
  - lib/rachinations/domain/modules/common/hash_init.rb
170
156
  - lib/rachinations/domain/modules/common/invariant.rb
157
+ - lib/rachinations/domain/modules/common/refiners/proc_convenience_methods.rb
171
158
  - lib/rachinations/domain/modules/diagrams/verbose.rb
172
159
  - lib/rachinations/domain/node_collection.rb
173
160
  - lib/rachinations/domain/nodes/converter.rb
@@ -221,9 +208,10 @@ files:
221
208
  - testing/simulations/sobonito.rb
222
209
  - testing/simulations/sobonitowhile.rb
223
210
  - testing/simulations/whatIwish1.rb
211
+ - testing/spec/canon/conditions_spec.rb
224
212
  - testing/spec/canon/converter_spec.rb
225
213
  - testing/spec/canon/pool_spec.rb
226
- - testing/spec/conditions_spec.rb
214
+ - testing/spec/canon/trigger_spec.rb
227
215
  - testing/spec/converter_spec.rb
228
216
  - testing/spec/diagram_spec.rb
229
217
  - testing/spec/edge_spec.rb
@@ -267,9 +255,10 @@ test_files:
267
255
  - testing/simulations/sobonito.rb
268
256
  - testing/simulations/sobonitowhile.rb
269
257
  - testing/simulations/whatIwish1.rb
258
+ - testing/spec/canon/conditions_spec.rb
270
259
  - testing/spec/canon/converter_spec.rb
271
260
  - testing/spec/canon/pool_spec.rb
272
- - testing/spec/conditions_spec.rb
261
+ - testing/spec/canon/trigger_spec.rb
273
262
  - testing/spec/converter_spec.rb
274
263
  - testing/spec/diagram_spec.rb
275
264
  - testing/spec/edge_spec.rb
@@ -1,10 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe 'Nodes that can be given conditions' do
4
-
5
- it 'does something' do
6
-
7
- skip "will test conditions later"
8
-
9
- end
10
- end