Skip to content

Commit

Permalink
Cleanup vending machine example for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arian Weber authored and Arian Weber committed Mar 19, 2024
1 parent 3145916 commit 626cecd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions integration_tests/ruby_dsl/020_vending_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
coins = coins.map { |c, v| [c, (v / 10).to_i] }.to_h


MAX_MONEY = 100
START_MONEY = 20
max_money = 100
start_money = 20

transient error :CoinReadFails

Expand All @@ -26,8 +26,8 @@
grab_states = products.keys.map { |product| :"grab_#{product}" }
insert_states = coins.keys.map { |coin| :"insert_#{coin}" }

var pocket_money: (0..MAX_MONEY), init: START_MONEY
var value_in_products: (0..MAX_MONEY), init: 0
var pocket_money: (0..max_money), init: start_money
var value_in_products: (0..max_money), init: 0

states :inserting, *insert_states, \
:pressing, *press_states, \
Expand Down Expand Up @@ -57,7 +57,7 @@
# Grab a product and take note of the value
products.each { |product, value|
transition :waiting => :grab_product do
precon "value_in_products + #{value} < #{MAX_MONEY}"
precon "value_in_products + #{value} < #{max_money}"
guard "LED == green && Dispenser == dispensed_#{product}"
action "value_in_products := value_in_products + #{value}"
end
Expand All @@ -72,7 +72,7 @@

# Grab the change and be done
transition :grab_change => :done do
precon "pocket_money + change <= #{MAX_MONEY}"
precon "pocket_money + change <= #{max_money}"
action "pocket_money := pocket_money + change"
end
end
Expand All @@ -97,14 +97,14 @@
end

graph :Controller do
var budget: (0..MAX_MONEY), init: 0
var budget: (0..max_money), init: 0

dispense_states = products.keys.map { |product| :"dispense_#{product}" }

states :accepting, *dispense_states, :rejected, :done, init: :accepting

transition :accepting => :accepting do
precon "budget + read_value <= #{MAX_MONEY}"
precon "budget + read_value <= #{max_money}"
guard "read_value > 0"
action "budget := budget + read_value"
end
Expand Down Expand Up @@ -159,7 +159,7 @@

graph :CoinDispenser do
states :idle, :dispensed_change, init: :idle
var change: (0..MAX_MONEY), init: 0
var change: (0..max_money), init: 0

# Eject the change money
transition :idle => :dispensed_change do
Expand All @@ -182,7 +182,7 @@

end

hazard "The user looses money" => :"User == done && pocket_money + value_in_products < #{START_MONEY}"
hazard "The machine looses money" => :"User == done && pocket_money + value_in_products > #{START_MONEY}"
# hazard "The user looses money" => :"User == done && pocket_money + value_in_products < #{start_money}"
# hazard "The machine looses money" => :"User == done && pocket_money + value_in_products > #{start_money}"

end

0 comments on commit 626cecd

Please sign in to comment.