-
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
Baljit's branch for airport_challenge #2495
Open
baljitrakhra
wants to merge
12
commits into
makersacademy:main
Choose a base branch
from
baljitrakhra: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.
+169
−43
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2a7ec9a
user story to land a plane completed
baljitrakhra 30800cd
user story regarding ATC to be able to instruct plane to take off and…
baljitrakhra c88c421
user story regarding default capacity for the airport created
baljitrakhra 0ae5203
if airport is full then no landing allowed
baljitrakhra 59133f4
user story to prevent takeoff when weather is stormy added
baljitrakhra eb392ae
user story to stop landing during stomy weather added
baljitrakhra 457aadf
edge cases handeling added
baljitrakhra 7ed1e4d
Test coverage increased to 98.80% and rubocop checks completed
baljitrakhra f97282e
tested for multiple take-off's and landing's
baljitrakhra 3d225ff
Updated README.md
baljitrakhra 2fb8eb9
converted require to require_relative plus added status changer for i…
baljitrakhra 725c48d
Merge branch 'main' of https://github.com/baljitrakhra/airport_challenge
baljitrakhra 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,33 @@ | ||
require_relative '../lib/weather.rb' | ||
require_relative '../lib/plane.rb' | ||
|
||
class Airport | ||
attr_reader :planes, :capacity | ||
DEFAULT_CAPACITY = 10 | ||
|
||
def initialize(capacity = DEFAULT_CAPACITY, weather: Weather.new) | ||
@planes = [] | ||
@capacity = capacity | ||
@weather = weather | ||
end | ||
|
||
def land(plane) | ||
fail "Plane is not in the air" if plane.in_flight? | ||
fail 'Due to stormy weather no landing allowed' if stormy? | ||
fail 'Airport is full no landing allowed' if @planes.count >= DEFAULT_CAPACITY | ||
plane.in_flight = false | ||
@planes << plane | ||
end | ||
|
||
def takeoff(plane) | ||
fail 'Due to stormy weather no landing allowed' if stormy? | ||
fail 'Plane is not at the airport' if plane.in_flight? | ||
plane.in_flight = true | ||
@planes.delete(plane) | ||
'plane has taken off' | ||
end | ||
|
||
def stormy? | ||
@weather.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,11 @@ | ||
class Plane | ||
attr_accessor :in_flight | ||
|
||
def initialize(in_flight = false) | ||
@in_flight = in_flight | ||
end | ||
|
||
def in_flight? | ||
@in_flight | ||
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,13 @@ | ||
class Weather | ||
def stormy | ||
random_outlook == :stormy | ||
end | ||
|
||
private | ||
|
||
OUTLOOKS = [:stormy, :fine, :fine, :fine] | ||
|
||
def random_outlook | ||
OUTLOOKS.sample | ||
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,66 @@ | ||
require_relative '../lib/airport.rb' | ||
|
||
describe Airport do | ||
let(:plane) { Plane.new } | ||
let(:airport) { Airport.new } | ||
let(:weather) { Weather.new } | ||
|
||
|
||
describe '# landing' do | ||
|
||
it 'has a Default capcity' do | ||
expect(airport.capacity).to eq(Airport::DEFAULT_CAPACITY) | ||
end | ||
|
||
it '--to be prevented when airport is full' do | ||
allow(airport).to receive(:stormy?).and_return false | ||
Airport::DEFAULT_CAPACITY.times { airport.land Plane.new } | ||
expect { airport.land Plane.new }.to raise_error 'Airport is full no landing allowed' | ||
end | ||
|
||
it 'is prevented due to stormy weather' do | ||
allow(airport).to receive(:stormy?).and_return true | ||
expect { airport.land plane }.to raise_error "Due to stormy weather no landing allowed" | ||
end | ||
|
||
it 'raise an error when plane is not in the air before landing' do | ||
allow(airport).to receive(:stormy?).and_return false | ||
plane = Plane.new(true) | ||
expect { airport.land plane }.to raise_error "Plane is not in the air" | ||
end | ||
it 'lands multiple planes' do # bonus points | ||
allow(airport).to receive(:stormy?).and_return false | ||
5.times { airport.land Plane.new } | ||
expect { airport.land Plane.new }.not_to raise_error | ||
end | ||
end | ||
baljitrakhra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe '#take-offs' do | ||
it { is_expected.to respond_to(:takeoff).with(1).argument } | ||
|
||
it 'informs that the plane has taken off' do | ||
allow(airport).to receive(:stormy?).and_return false | ||
airport.planes << plane | ||
expect(airport.takeoff plane).to eq 'plane has taken off' | ||
end | ||
it 'gets weather status' do | ||
allow(airport).to receive(:stormy?).and_return false | ||
expect(weather.stormy).to be(true).or be(false) | ||
end | ||
it 'is prevented due to stormy weather' do | ||
allow(airport).to receive(:stormy?).and_return true | ||
expect { airport.takeoff plane }.to raise_error "Due to stormy weather no landing allowed" | ||
end | ||
|
||
it 'raise an error when plane is not in the airport before taking off' do | ||
allow(airport).to receive(:stormy?).and_return false | ||
plane.in_flight = true | ||
expect { airport.takeoff plane }.to raise_error "Plane is not at the airport" | ||
end | ||
it 'multiple planes' do # bonus points | ||
allow(airport).to receive(:stormy?).and_return false | ||
5.times { airport.land Plane.new } | ||
expect { airport.takeoff plane }.not_to raise_error | ||
end | ||
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,4 @@ | ||
require_relative '../lib/plane.rb' | ||
|
||
describe Plane do | ||
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,19 @@ | ||
require_relative '../lib/weather.rb' | ||
|
||
describe Weather do | ||
let(:weather) { Weather.new } | ||
|
||
it { is_expected.to respond_to(:stormy) } | ||
|
||
describe '#tells the weather condition' do | ||
it "is sunny" do | ||
allow(weather).to receive(:random_outlook).and_return(:fine) | ||
expect(weather.stormy).to eq false | ||
end | ||
|
||
it "is stormy" do | ||
allow(weather).to receive(:random_outlook).and_return(:stormy) | ||
expect(weather.stormy).to eq true | ||
end | ||
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.
small typo, capacity