Skip to content
Browse files

Cleaned up basic book steps

  • Loading branch information...
1 parent af087bf commit 864ed7a1eca579b01c2eb688cf378d1d185bf1f0 @Vaguery committed May 23, 2012
View
59 features/acceptance_tests.feature
@@ -1,59 +0,0 @@
-Feature: Acceptance tests
- In order to verify the emulator's accuracy
- As a Cargo-bot runner
- I want to check the outcome against known Cargo-bot results
-
- Scenario: Tutorial 1
- Given the bot is created with script "claw R claw" and 2 stacks
- And stack 1 contains [:yellow]
- And the goal is '[[], [:yellow]]'
- When I activate the cargobot
- Then the stacks should be [[], [:yellow]]
- And the number of moves should be 3
- And the number of crashes should be 0
- And the number of topples should be 0
-
- Scenario: Tutorial 2
- Given the bot is created with script "claw R R R claw" and 4 stacks
- And stack 1 contains [:yellow]
- And the goal is '[[], [], [], [:yellow]]'
- When I activate the cargobot
- Then the stacks should be [[], [], [], [:yellow]]
- And the number of moves should be 5
- And the number of crashes should be 0
- And the number of topples should be 0
-
-
- Scenario: Tutorial 3
- Given the bot is created with script "claw R claw L call1" and 2 stacks
- And stack 1 contains [:y, :y, :y, :y]
- And the goal is '[[], [:y, :y, :y, :y]]'
- When I activate the cargobot
- Then the stacks should be [[], [:y, :y, :y, :y]]
- And the number of moves should be 15
- And the number of crashes should be 0
- And the number of topples should be 0
-
-
- Scenario: Tutorial 4
- Given the bot is created with script "call2 call2 call2 call2 R call1 prog_2 claw R claw L" and 6 stacks
- And stack 1 contains [:b, :r, :g, :y]
- And the goal is '[[], [], [], [], [], [:y, :g, :r, :b]]'
- When I activate the cargobot
- Then the stacks should be [[], [], [], [], [], [:y, :g, :r, :b]]
- And the number of moves should be 83
- And the number of crashes should be 0
- And the number of topples should be 0
-
-
- Scenario: "Double Sort"
- Given the bot is created with script "L claw_b R claw_none R claw_none call2 prog_2 R claw_y L L call1" and 4 stacks
- And stack 2 contains [:b, :b, :y, :y]
- And stack 3 contains [:y, :b, :y, :b]
- And the claw is in position 2
- And the goal is '[[:b,:b,:b,:b],[],[],[:y,:y,:y,:y]]'
- When I activate the cargobot
- Then the stacks should be [[:b, :b, :b, :b], [], [], [:y, :y, :y, :y]]
- And the number of moves should be 66
- And the number of crashes should be 0
- And the number of topples should be 0
View
26 features/branching.feature
@@ -1,26 +0,0 @@
-Feature: Branching and recursive execution of programs
- In order to re-use code
- As a cargo-bot programmer
- I want the script to be partitioned into several subroutines
-
- Scenario: Execution should return to where it started when a subroutine was called
- Given the bot is created with script "R call2 claw call3 L prog_2 claw R prog_3 L" and 3 stacks
- And the claw is in position 1
- And the top box on stack 2 is blue
- And the top box on stack 3 is red
- When I activate the cargobot
- Then the number of moves should be 6
- And the claw should be in position 1
- And the claw should be empty
- And stack 2 should be empty
- And stack 3 should be [:red, :blue]
-
-
- Scenario: Recursion can create infinite loops, but they will terminate based on steps
- Given the bot is created with script "R call1" and 3 stacks
- And the step limit is 200
- And the claw is in position 1
- When I activate the cargobot
- Then the number of steps should be 200
- And the claw should be in position 3
-
View
45 features/claw_movement.feature
@@ -1,45 +0,0 @@
-Feature: Claw movement
- In order to evaluate a given Cargo-bot script
- As a simulator
- I want the claw to move as it does in the original game
-
- Scenario: Claw should move left and right between stacks
- Given the bot is created with script "L R R R" and 10 stacks
- And the claw is in position 2
- When I activate the cargobot
- Then the number of moves should be 4
- And the claw should be in position 4
-
- Scenario: When the claw tries to move left of position 1, it should crash
- Given the bot is created with script "L R L L" and 10 stacks
- And the claw is in position 1
- When I activate the cargobot
- Then the claw should be in position 1
- And the number of crashes should be 2
-
- Scenario: When the claw tries to move right of the rightmost stack, it should crash
- Given the bot is created with script "R R L R" and 3 stacks
- And the claw is in position 3
- When I activate the cargobot
- Then the claw should be in position 3
- And the number of crashes should be 2
-
- Scenario: When the empty claw activates over a block, it should pick it up
- Given the bot is created with script "claw R" and 2 stacks
- And the claw is in position 1
- And the top box on stack 1 is blue
- When I activate the cargobot
- Then the claw should be in position 2
- And the claw should contain a blue box
- And the number of boxes in stack 1 should be 0
-
- Scenario: When the claw containing a block activates, it should put it down on that stack
- Given the bot is created with script "claw R claw" and 2 stacks
- And the claw is in position 1
- And the top box on stack 1 is blue
- And the top box on stack 2 is red
- When I activate the cargobot
- Then the claw should be in position 2
- And the claw should be empty
- And the number of boxes in stack 1 should be 0
- And stack 2 should be [:red, :blue]
View
30 features/conditional_tokens.feature
@@ -1,30 +0,0 @@
-Feature: Conditional tokens
- In order to permit conditional execution
- As a Cargo-bot programmer
- I want tokens to be conditioned by what the claw is holding when they're executed
-
- Scenario: Color annotations act as filters on tokens
- Given the bot is created with script "claw R_red R_blue R_blue claw L L call1" and 3 stacks
- And stack 1 contains [:blue, :red, :blue, :red, :blue]
- And the goal is '[[], [:red, :red], [:blue, :blue, :blue]]'
- When I activate the cargobot
- Then the stacks should be [[], [:red, :red], [:blue, :blue, :blue]]
- And the number of moves should be 24
-
-
- Scenario: Generic 'any' annotations filter on whether a block is held
- Given the bot is created with script "claw R_any R_red claw L L call1" and 3 stacks
- And stack 1 contains [:blue, :red, :green, :red, :yellow]
- And the goal is '[[], [:yellow, :green, :blue], [:red, :red]]'
- When I activate the cargobot
- Then the stacks should be [[], [:yellow, :green, :blue], [:red, :red]]
- And the number of moves should be 23
-
-
- Scenario: Generic 'none' annotations filter on whether a block is held
- Given the bot is created with script "R claw_none L_any claw_any call1" and 3 stacks
- And stack 2 contains [:blue, :red, :green, :red, :yellow]
- And the goal is '[[:yellow, :red, :green, :red, :blue], [], []]'
- When I activate the cargobot
- Then the stacks should be [[:yellow, :red, :green, :red, :blue], [], []]
- And the number of moves should be 20
View
4 features/chapter_1/claw.feature → features/emulator/claw.feature
@@ -1,4 +1,4 @@
-Feature: Chapter1 claw
+Feature: Cargo-bot emulator claw
Background: a bot exists
Given I have a new cargobot
@@ -16,7 +16,7 @@ Scenario: Empty claw picks up crates
And the claw is over pallet 1
When I activate the cargobot
Then the claw should be over pallet 2
- And the claw should hold a red box
+ And the claw should hold a red crate
And the pallets should be [[blue],[]]
Scenario: Claw with crate sets it down
View
4 features/chapter_1/conditional.feature → features/emulator/conditional.feature
@@ -1,4 +1,4 @@
-Feature: Chapter 1 conditionals
+Feature: Cargo-bot emulator conditionals
Background: a bot exists
Given I have a new cargobot
@@ -27,4 +27,4 @@ Scenario: 'none' filters
And the pallets are [[],[red],[],[blue,red]]
When I activate the cargobot
Then the pallets should be [[red], [], [], [blue,red]]
- And the claw will not be crashed
+ And the claw should not be crashed
View
10 features/chapter_1/crashing.feature → features/emulator/crashing.feature
@@ -1,4 +1,4 @@
-Feature: Chapter 1 crashing
+Feature: Cargo-bot emulator crashing
Background: a bot exists
Given I have a new cargobot
@@ -8,15 +8,15 @@ Scenario: Crash when hitting left wall
And the pallets are [[], [], []]
And the claw is in position 1
When I activate the cargobot
- Then the claw should be in position 1
+ Then the claw should be over pallet 1
And the step count should be 1
- And the claw will be crashed
+ And the claw should be crashed
Scenario: Crash when hitting right wall
Given subroutine 1 is "R R R R"
And the pallets are [[], [], []]
And the claw is in position 1
When I activate the cargobot
- Then the claw should be in position 3
+ Then the claw should be over pallet 3
And the step count should be 3
- And the claw will be crashed
+ And the claw should be crashed
View
24 features/emulator/loading.feature
@@ -0,0 +1,24 @@
+Feature: Cargo-bot emulator loading scripts
+
+Background: a bot exists
+ Given I have a new cargobot
+
+Scenario: Start with subroutine 1
+ Given the script is "L R R R"
+ When I load the script into the bot
+ Then subroutine 1 should be "L R R R"
+ And subroutine 2 should be empty
+
+Scenario: Add tokens as indicated by prog_N
+ Given the script is "R prog_2 L prog_1 R prog_4 L"
+ When I load the script into the bot
+ Then subroutine 1 should be "R R"
+ And subroutine 2 should be "L"
+ And subroutine 3 should be empty
+ And subroutine 4 should be "L"
+
+Scenario: Return to subroutine as indicated
+ Given the script is "R prog_2 L L L L prog_1 R R"
+ When I load the script into the bot
+ Then subroutine 1 should be "R R R"
+ And subroutine 2 should be "L L L L"
View
2 features/chapter_1/solving.feature → features/emulator/solving.feature
@@ -1,4 +1,4 @@
-Feature: Chapter 1 solving
+Feature: Cargo-bot emulator solving
Background: a bot exists
Given I have a new cargobot
View
2 features/chapter_1/subroutines.feature → features/emulator/subroutines.feature
@@ -1,4 +1,4 @@
-Feature: Chapter 1 subroutines
+Feature: Cargo-bot emulator subroutines
Background: a bot exists
Given I have a new cargobot
View
6 features/chapter_1/toppling.feature → features/emulator/toppling.feature
@@ -1,4 +1,4 @@
-Feature: Chapter 1 crashing
+Feature: Cargo-bot emulator toppling
Background: a bot exists
Given I have a new cargobot
@@ -8,6 +8,6 @@ Scenario: Stacks topple when brushed
And the pallets are [[],[red,red,red,red,red,red,red],[]]
And the claw is in position 1
When I activate the cargobot
- Then the claw should be in position 2
+ Then the claw should be over pallet 2
And the step count should be 1
- And a stack of crates will be toppled
+ And a stack of crates should be toppled
View
22 features/chapter_1/tutorial.feature → features/emulator/tutorial.feature
@@ -1,4 +1,4 @@
-Feature: Chapter1 claw
+Feature: Cargo-bot emulator tutorial examples
Background: a bot exists
Given I have a new cargobot
@@ -9,27 +9,27 @@ Scenario: Tutorial 1
And the goal is [[], [yellow]]
When I activate the cargobot
Then the pallets should be [[], [yellow]]
- And the number of steps should be 3
- And the number of crashes should be 0
- And the number of topples should be 0
+ And the step count should be 3
+ And the claw should not be crashed
+ And no stacks should be toppled
Scenario: Tutorial 2
Given subroutine 1 is "claw R R R claw"
And the pallets are [[yellow],[],[],[]]
And the goal is [[],[],[],[yellow]]
When I activate the cargobot
Then the pallets should be [[],[],[],[yellow]]
- And the number of steps should be 5
- And the number of crashes should be 0
- And the number of topples should be 0
-
+ And the step count should be 5
+ And the claw should not be crashed
+ And no stacks should be toppled
+
Scenario: Tutorial 4
Given subroutine 1 is "call2 call2 call2 call2 R call1"
And subroutine 2 is "claw R claw L"
And the pallets are [[blue,red,green,yellow],[],[],[],[],[]]
And the goal is [[],[],[],[],[],[yellow,green,red,blue]]
When I activate the cargobot
Then the pallets should be [[],[],[],[],[],[yellow,green,red,blue]]
- And the number of steps should be 107
- And the number of crashes should be 0
- And the number of topples should be 0
+ And the step count should be 107
+ And the claw should not be crashed
+ And no stacks should be toppled
View
26 features/loading_script.feature
@@ -1,26 +0,0 @@
-Feature: Loading script
- In order to evaluate a Cargo-bot script
- As a simulator
- I want to be able to load tokens into the emulator registers
-
- Scenario: Script tokens are added to the end of the 1st subroutine by default
- Given the bot is created with script "L L R claw"
- Then the bot's program should have 1 subroutine
- And subroutine 1 should have 4 tokens
-
- Scenario: Where script tokens are added is controlled by the 'prog_X' token
- Given the bot is created with script "R prog_2 L prog_1 R prog_4 L"
- Then the bot's program should have 4 subroutines
- And subroutine 1 should have 2 tokens
- And subroutine 2 should have 1 token
- And subroutine 3 should have 0 tokens
- And subroutine 4 should have 1 token
-
- Scenario: All tokens added to a subroutine are appended, even after a break
- Given the bot is created with script "R prog_2 L L L L prog_1 R R"
- Then the bot's program should have 2 subroutines
- And subroutine 1 should have tokens [:R, :R, :R]
- And subroutine 2 should have tokens [:L, :L, :L, :L]
-
-
-
View
0 features/cleanup_distance.feature → features/metrics/cleanup_distance.feature
File renamed without changes.
View
0 features/rebuild_distance.feature → features/metrics/rebuild_distance.feature
File renamed without changes.
View
0 features/teardown_distance.feature → features/metrics/teardown_distance.feature
File renamed without changes.
View
49 ...ures/step_definitions/book_chap1_steps.rb → features/step_definitions/emulator_steps.rb
@@ -17,6 +17,11 @@
@bot.stacks = eval(symbolized_stacks)
end
+Given /^the claw is in position (\d+)$/ do |pallet|
+ @bot.claw_position = pallet.to_i
+end
+
+
Given /^the goal is (\[.+\])$/ do |stacks|
symbolized_stacks = stacks.gsub(/(\w+)/,':\1')
@bot.goal = eval(symbolized_stacks)
@@ -31,15 +36,36 @@
@bot.step_limit = limit.to_i
end
+Given /^the script is "([^"]*)"$/ do |script|
+ @script = script
+end
+
+
+
+
+When /^I load the script into the bot$/ do
+ @bot.load_program(@script)
+end
+
+When /^I activate the cargobot$/ do
+ @bot.activate
+end
+
+
+
Then /^the claw should be over pallet (\d+)$/ do |which|
@bot.claw_position.should == which.to_i
end
-Then /^the claw should hold a (\w+) box$/ do |color|
+Then /^the claw should hold a (\w+) crate$/ do |color|
@bot.claw_holding.should == color.intern
end
+Then /^the claw should be empty$/ do
+ @bot.claw_holding.should be_nil
+end
+
Then /^the pallets should be (\[.+\])$/ do |stacks|
symbolized_stacks = stacks.gsub(/(\w+)/,':\1')
@bot.stacks.should == eval(symbolized_stacks)
@@ -49,14 +75,29 @@
@bot.steps.should == steps.to_i
end
-Then /^the claw will be crashed$/ do
+Then /^the claw should be crashed$/ do
@bot.crashes.should_not == 0
end
-Then /^the claw will not be crashed$/ do
+Then /^the claw should not be crashed$/ do
@bot.crashes.should == 0
end
-Then /^a stack of crates will be toppled$/ do
+Then /^a stack of crates should be toppled$/ do
@bot.topples.should >= 1
end
+
+Then /^no stacks should be toppled$/ do
+ @bot.topples.should == 0
+end
+
+
+Then /^subroutine (\d+) should be "([^"]*)"$/ do |which, subroutine|
+ parsed_subroutine = subroutine.split.collect {|token| token.intern}
+ @bot.program[which.to_i-1].should == parsed_subroutine
+end
+
+Then /^subroutine (\d+) should be empty$/ do |which|
+ [nil,[]].should include @bot.program[which.to_i-1]
+end
+
View
156 features/step_definitions/simple_steps.rb
@@ -1,156 +0,0 @@
-module LongProgram
- def long_program
- @long_program ||= "R " * 500
- end
-end
-
-World(LongProgram)
-
-
-Given /^the bot is created with script "([^"]*)"$/ do |arg1|
- @bot = CargoBot.new(arg1)
-end
-
-
-Given /^the bot is created with script a very long program and (\d+) stacks$/ do |arg1|
- @bot = CargoBot.new(long_program, stacks:arg1.to_i.times.collect {[]})
-end
-
-
-
-Given /^the claw is in position (\d+)$/ do |arg1|
- @bot.claw_position = arg1.to_i
-end
-
-
-Given /^the subscript "([^"]*)" is loaded into Prog(\d+)$/ do |arg1, arg2|
- arg1.scan(/w+/) do |word|
- @bot.script[arg2.to_i - 1] = word.intern
- end
-end
-
-
-Given /^the bot has (\d+) stacks$/ do |arg1|
- @bot.stacks = arg1.to_i.times.collect {Array.new}
-end
-
-
-Given /^the bot is created with script "([^"]*)" and (\d+) stacks?$/ do |arg1, arg2|
- @bot = CargoBot.new(arg1,stacks:arg2.to_i.times.collect {[]})
-end
-
-
-Given /^the top box on stack (\d+) is (\w+)$/ do |arg1, arg2|
- @bot.stacks[arg1.to_i-1].push arg2.intern
-end
-
-
-Given /^the step limit is (\d+)$/ do |arg1|
- @bot.step_limit = arg1.to_i
-end
-
-
-Given /^the goal is '(\[.+\])'$/ do |arg1|
- @bot.goal = eval(arg1)
-end
-
-
-Given /^the bot has a fragile claw$/ do
- @bot.fragile = true
-end
-
-
-Given /^the stacks topple the claw bumps them at their height limit$/ do
- @bot.unstable = true
-end
-
-
-Given /^the bot has a height limit of (\d+)$/ do |arg1|
- @bot.height_limit = arg1.to_i
-end
-
-
-Given /^stack (\d+) contains (\[.+\])$/ do |arg1,arg2|
- @bot.stacks[arg1.to_i-1] = eval(arg2)
-end
-
-
-When /^I activate the cargobot$/ do
- @bot.activate
-end
-
-
-Then /^the bot's program should have (\d+) subroutines?$/ do |arg1|
- @bot.program.length.should == arg1.to_i
-end
-
-
-Then /^the number of moves should be (\d+)$/ do |arg1|
- @bot.moves.should == arg1.to_i
-end
-
-
-Then /^the number of steps should be (\d+)$/ do |arg1|
- @bot.steps.should == arg1.to_i
-end
-
-
-
-Then /^subroutine (\d+) should have (\d+) tokens?$/ do |arg1, arg2|
- @bot.program[arg1.to_i-1].length.should == arg2.to_i
-end
-
-
-Then /^subroutine (\d+) should have tokens (\[.+\])$/ do |arg1, arg2|
- @bot.program[arg1.to_i - 1].inspect.should == arg2
-end
-
-
-Then /^stack (\d+) should be (\[.+\])$/ do |arg1, arg2|
- @bot.stacks[arg1.to_i - 1].inspect.should == arg2
-end
-
-
-Then /^the claw should be in position (\d+)$/ do |arg1|
- @bot.claw_position.should == arg1.to_i
-end
-
-
-Then /^the number of crashes should be (\d+)$/ do |arg1|
- @bot.crashes.should == arg1.to_i
-end
-
-
-Then /^the claw should contain a (\w+) box$/ do |arg1|
- @bot.claw_holding.should == arg1.intern
-end
-
-
-Then /^the number of boxes in stack (\d+) should be (\d+)$/ do |arg1, arg2|
- @bot.stacks[arg1.to_i-1].length.should == arg2.to_i
-end
-
-
-Then /^the claw should be empty$/ do
- @bot.claw_holding.should be_nil
-end
-
-
-Then /^stack (\d+) should be empty$/ do |arg1|
- @bot.stacks[arg1.to_i-1].should be_empty
-end
-
-
-Then /^the stack trace should contain (\d+) items$/ do |arg1|
- @bot.stack_trace.length.should == arg1.to_i
-end
-
-
-Then /^the number of topples should be (\d+)$/ do |arg1|
- @bot.topples.should == arg1.to_i
-end
-
-
-Then /^the stacks should be (\[.+\])$/ do |arg1|
- @bot.stacks.should == eval(arg1)
-end
View
49 features/termination_conditions.feature
@@ -1,49 +0,0 @@
-Feature: Termination conditions
- In order to evaluate a Cargo-bot script
- As a simulator
- I want evaluation to stop as soon as the target is found, or at some shutoff point
-
-
- Scenario: Execution should stop if it reaches the end of subroutine 1
- Given the bot is created with script "R R R"
- When I activate the cargobot
- Then the number of steps should be 3
-
-
- Scenario: Execution should stop immediately when the target state is found
- Given the bot is created with script "claw R claw R R R R" and 6 stacks
- And the claw is in position 1
- And the top box on stack 1 is blue
- And the goal is '[[], [:blue], [], [], [], []]'
- When I activate the cargobot
- Then the number of moves should be 3
- And the claw should be in position 2
-
-
- Scenario: Execution should stop immediately when the step limit is reached
- Given the bot is created with script a very long program and 3 stacks
- And the goal is '[[:yellow]]'
- And the step limit is 200
- And the claw is in position 1
- When I activate the cargobot
- Then the number of steps should be 200
- And the claw should be in position 3
-
-
- Scenario: Execution should stop if the bot is 'fragile' and it crashes
- Given the bot is created with script "L L L" and 1 stack
- And the bot has a fragile claw
- When I activate the cargobot
- Then the number of crashes should be 1
- And the number of steps should be 1
-
-
- Scenario: Execution should stop if the bot is 'unstable' and a stack topples
- Given the bot is created with script "claw R claw call1" and 2 stacks
- And the bot has a height limit of 4
- And the stacks topple the claw bumps them at their height limit
- And stack 1 contains [:red, :red]
- And stack 2 contains [:blue, :blue, :blue, :blue, :blue, :blue]
- When I activate the cargobot
- Then the number of topples should be 1
- And the number of steps should be 2

0 comments on commit 864ed7a

Please sign in to comment.
Something went wrong with that request. Please try again.