Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.5) | ||
rspec (3.2.0) | ||
rspec-core (~> 3.2.0) | ||
rspec-expectations (~> 3.2.0) | ||
rspec-mocks (~> 3.2.0) | ||
rspec-core (3.2.0) | ||
rspec-support (~> 3.2.0) | ||
rspec-expectations (3.2.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.2.0) | ||
rspec-mocks (3.2.0) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.2.0) | ||
rspec-support (3.2.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rock, paper, scissors, lizard, spock | ||
================ | ||
|
||
Exercise in showing the application lifecycle in the land of start-ups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require_relative '../models/computer_player' | ||
require_relative '../models/game' | ||
|
||
describe ComputerPlayer do | ||
subject { ComputerPlayer.new } | ||
|
||
context '#initialize' do | ||
it { expect(subject.win_count).to eq(0) } | ||
end | ||
|
||
context '#name' do | ||
it { expect(subject.name).to eq('Computer') } | ||
end | ||
|
||
context '#pick' do | ||
before { subject.pick } | ||
|
||
it 'sets selection' do | ||
expect(subject.selection).not_to be_nil | ||
end | ||
|
||
it 'gets random value from Game::CHOICES' do | ||
expect(Game::CHOICES).to include(subject.selection.to_sym) | ||
end | ||
end | ||
|
||
context '#selection_detail' do | ||
before{ subject.pick } | ||
|
||
it { expect(subject.selection_detail).to eq(Game::CHOICES[subject.selection.to_sym]) } | ||
end | ||
|
||
context '#selection_name' do | ||
before { subject.pick } | ||
|
||
it { expect(subject.selection_name).to eq(Game::CHOICES[subject.selection.to_sym][:name]) } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require_relative '../models/game' | ||
|
||
describe Game do | ||
subject { Game.new('Kirk') } | ||
|
||
context '#initialize' do | ||
it { expect(subject.player1.name).to eq('Kirk') } | ||
it { expect(subject.player2.class.name).to eq('ComputerPlayer')} | ||
end | ||
|
||
context '#result' do | ||
it 'returns tie if both players picked same choice' do | ||
subject.player1.selection = 'r' | ||
allow(subject.player2).to receive(:selection) { 'r' } | ||
expect(subject.result).to eq('It was a tie! No winner') | ||
end | ||
|
||
it 'returns player1 name if he/she beats player2 choice' do | ||
subject.player2.pick | ||
subject.player1.selection = get_choice_that_beats(subject.player2.selection) | ||
expect(subject.result).to eq("WINNER is: #{subject.player1.name} - #{subject.player1.selection_name} #{winner_choice_action(subject.player1.selection, subject.player2.selection)} #{subject.player2.selection_name}") | ||
end | ||
|
||
it 'returns player2 name if he/she beats player1 choice' do | ||
subject.player2.pick | ||
subject.player1.selection = get_choice_that_loses(subject.player2.selection) | ||
expect(subject.result).to eq("WINNER is: #{subject.player2.name} - #{subject.player2.selection_name} #{winner_choice_action(subject.player2.selection, subject.player1.selection)} #{subject.player1.selection_name}") | ||
end | ||
end | ||
|
||
context '#champion' do | ||
it 'returns tie if matching win counts' do | ||
subject.player1.win_count = 1 | ||
subject.player2.win_count = 1 | ||
expect(subject.champion).to eq('TIE!!!') | ||
end | ||
|
||
it 'returns player1 name if he/she has more wins' do | ||
subject.player1.win_count = 1 | ||
subject.player2.win_count = 0 | ||
expect(subject.champion).to eq(subject.player1.name) | ||
end | ||
|
||
it 'returns player2 name if he/she has more wins' do | ||
subject.player1.win_count = 0 | ||
subject.player2.win_count = 1 | ||
expect(subject.champion).to eq(subject.player2.name) | ||
end | ||
end | ||
end | ||
|
||
def get_choice_that_beats(choice) | ||
Game::CHOICES.select{ |k,v| v[:beats].include?(choice.to_sym) }.first[0].to_s | ||
end | ||
|
||
def get_choice_that_loses(choice) | ||
Game::CHOICES[choice.to_sym][:beats].first[0].to_s | ||
end | ||
|
||
def winner_choice_action(choice, losing_action) | ||
Game::CHOICES[choice.to_sym][:beats][losing_action.to_sym] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require_relative '../models/player' | ||
require_relative '../models/game' | ||
|
||
describe Player do | ||
subject { Player.new('Kirk') } | ||
|
||
context '#initialize' do | ||
it { expect(subject.win_count).to eq(0) } | ||
end | ||
|
||
context '#name' do | ||
it { expect(subject.name).to eq('Kirk') } | ||
end | ||
|
||
context '#valid?' do | ||
it 'true for valid selection' do | ||
subject.selection = 'r' | ||
expect(subject).to be_valid | ||
end | ||
|
||
it 'false for invalid selection' do | ||
subject.selection = 'f' | ||
expect(subject).not_to be_valid | ||
end | ||
end | ||
|
||
context '#selection_detail' do | ||
before{ subject.selection = 'r' } | ||
|
||
it { expect(subject.selection_detail).to eq(Game::CHOICES[subject.selection.to_sym]) } | ||
end | ||
|
||
context '#selection_name' do | ||
before { subject.selection = 'r' } | ||
|
||
it { expect(subject.selection_name).to eq(Game::CHOICES[subject.selection.to_sym][:name]) } | ||
end | ||
|
||
context '#beat?' do | ||
before { subject.selection = 'r' } | ||
|
||
it 'true if selection does not beat opponent' do | ||
expect(subject).to be_beat('l') | ||
end | ||
|
||
it 'false if selection does beat opponent' do | ||
expect(subject).not_to be_beat('p') | ||
end | ||
end | ||
|
||
end |