-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Airport Challenge Stevie Spiegl #2510
Open
S-Spiegl
wants to merge
8
commits into
makersacademy:main
Choose a base branch
from
S-Spiegl:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1b3295
first commit
S-Spiegl 176ef14
ready to submit pull request, still some work to be done
S-Spiegl 78c50cc
Update README.md
S-Spiegl 2eae496
Update README.md
S-Spiegl 6c1d079
Update README.md
S-Spiegl aed12ef
committing before switching computers
cd37149
committing before switching computers
55db262
committing before switching computers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,31 @@ | ||
require_relative 'plane' | ||
|
||
class Airport | ||
|
||
CAPACITY = 5 | ||
WEATHER = {0 => "stormy", 1 => "fine", 2 => "fine", 3 => "fine"} | ||
|
||
|
||
def initialize(capacity = CAPACITY, weather = WEATHER[rand(4)]) | ||
@planes = [] | ||
@capacity = capacity | ||
@weather = weather | ||
end | ||
|
||
def release_plane(plane) | ||
fail 'weather too stormy for take-off' unless @weather != "stormy" | ||
@planes.pop | ||
end | ||
|
||
def land_plane(plane) | ||
|
||
fail 'airport full' if @planes.length == @capacity | ||
fail 'weather too stormy for landing' unless @weather != "stormy" | ||
@planes << plane | ||
end | ||
|
||
attr_accessor :planes | ||
attr_accessor :capacity | ||
attr_accessor :weather | ||
|
||
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,5 @@ | ||
class Plane | ||
def working? | ||
true | ||
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,5 @@ | ||
class WeatherGenerator | ||
def generate_weather | ||
weather = {0 => "sunny", 1 => "stormy"} | ||
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,58 @@ | ||
require 'airport' | ||
|
||
describe Airport do | ||
|
||
it 'responds to planes' do | ||
expect(subject).to respond_to(:planes) | ||
end | ||
|
||
it 'responds to release_plane' do | ||
expect(subject).to respond_to(:release_plane) | ||
end | ||
|
||
describe '#release_plane' do | ||
it 'releases a plane' do | ||
plane = Plane.new | ||
subject.land_plane(plane) | ||
expect(subject.release_plane(plane)).to eq plane | ||
end | ||
end | ||
|
||
it 'responds to land_plane with one argument' do | ||
expect(subject).to respond_to(:land_plane).with(1).argument | ||
end | ||
|
||
describe '#land_plane' do | ||
it 'prevents landing when airport is full' do | ||
5.times {subject.land_plane Plane.new} | ||
expect { subject.land_plane Plane.new }.to raise_error 'airport full' | ||
end | ||
end | ||
|
||
|
||
it 'has a default capacity that can be overridden' do | ||
expect(subject.capacity).to eq 5 | ||
end | ||
|
||
it 'lands something' do | ||
plane = Plane.new | ||
expect(subject.land_plane(plane)).to eq plane | ||
end | ||
|
||
it 'returns landed planes' do | ||
plane = Plane.new | ||
subject.land_plane(plane) | ||
expect(subject.planes).to eq plane | ||
end | ||
|
||
it 'prevents landing if weather is stormy' do | ||
subject.weather = "stormy" | ||
expect { subject.land_plane(Plane.new) }.to raise_error 'weather too stormy for landing' | ||
end | ||
|
||
it 'prevents takeoff if weather is stormy' do | ||
subject.weather = "stormy" | ||
expect { subject.release_plane(Plane.new) }.to raise_error 'weather too stormy for take-off' | ||
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,6 @@ | ||
require 'plane' | ||
describe Plane do | ||
it 'responds to working' do | ||
expect(subject).to respond_to(:working?) | ||
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,7 @@ | ||
require 'weather_generator' | ||
|
||
describe WeatherGenerator do | ||
it 'responds to generate_weather' do | ||
expect(subject).to respond_to(:generate_weather) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the ruby convention is to use attr_reader over attr_accessor, and that they go before the methods in the class