hw1_2
rps.feature:
Code:
Feature: Play RPS
I want to be able to play RPS against one opponent because it's fun.
Scenario Outline: Two player RPS
Given "<player_one>" threw "<throw_one>"
When "<player_two>" throws "<throw_two>"
Then the oputput should be "<output>"
Examples:
|player_one|throw_one|player_two|throw_two|output|
|Armando|P|Dave|S|Dave,S|
|Dave|S|Armando|P|Dave,S|
|Armando|R|Dave|R|Armando,R|
|Armando|r|Dave|p|Dave,p|
rps_steps.rb:
Code:
require_relative 'hw1_2.rb'
Given /^"([^"]*)" threw "([^"]*)"$/ do |player_one, throw_one|
@player_one = [player_one, throw_one]
end
When /^"([^"]*)" throws "([^"]*)"$/ do |player_two, throw_two|
@player_two = [player_two, throw_two]
end
Then /^the oputput should be "([^"]*)"$/ do |winner|
game = [@player_one, @player_two]
expected_output = winner.split(',')
raise "Wrong Output" unless expected_output == rps_game_winner(game)
end
rps_tournament.feature:
Code:
Feature: Play an RPS torunament
I want to be able to play an entire RPS tournament because it's more fun than a single gamefun.
Scenario: RPS tournament [ ["Armando", "P"], ["Kris", "S"] ]
Given A tournament that looks like [ ["Armando", "P"], ["Kris", "S"] ]
When The tournament engine is run
Then the tournament oputput should be ["Kris", "S"]
Scenario: RPS tournament [ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
Given A tournament that looks like [ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
When The tournament engine is run
Then the tournament oputput should be ["Dave", "S"]
Scenario: RPS tournament [ [ [ "Allen", "p" ], [ "Dave", "P" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
Given A tournament that looks like [ [ [ "Allen", "p" ], [ "Dave", "P" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]]
When The tournament engine is run
Then the tournament oputput should be ["Allen", "p"]
Scenario: RPS tournament [[ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]], [ [ [ "Omer", "P" ], [ "David", "S" ] ],[ [ "Max", "R" ] , [ "Jonathan", "P" ] ]], ]
Given A tournament that looks like [[ [ [ "Allen", "P" ], [ "Dave", "S" ] ],[ [ "Richard", "R" ] , [ "Armando", "P" ] ]], [ [ [ "Omer", "P" ], [ "David", "S" ] ],[ [ "Max", "R" ] , [ "Jonathan", "P" ] ]], ]
When The tournament engine is run
Then the tournament oputput should be ["Dave", "S"]
rps_tournament_steps.rb:
Code:
require_relative 'hw1_2.rb'
# Some examples of tournaments
tournament_one = [ ["Armando", "P"], ["Dave", "S"] ]
tournament_two = [
[ [ "Allen", "P" ], [ "Dave", "S" ] ],
[ [ "Richard", "R" ] , [ "Armando", "P" ] ]
]
tournament_three = [
[
[ [ "Allen", "P" ], [ "Dave", "S" ] ],
[ [ "Richard", "R" ] , [ "Armando", "P" ] ]
],
[
[ [ "Omer", "P" ], [ "David", "S" ] ],
[ [ "Max", "R" ] , [ "Jonathan", "P" ] ]
],
]
Given /^A tournament that looks like (.*)$/ do |tournament|
@tournament = tournament
end
When /^The tournament engine is run$/ do
tournament = eval(@tournament)
@output = rps_tournament_winner(tournament).to_s
end
Then /^the tournament oputput should be (.*)$/ do |expected_output|
raise "Wrong Output" unless expected_output == @output
end
hw1_2.rb: