-
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
Luiza Airport Challenge #2502
Open
LGretzk
wants to merge
15
commits into
makersacademy:main
Choose a base branch
from
LGretzk: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
Luiza Airport Challenge #2502
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6b80f0e
Add airport spec, add plane spec
3b4abb8
Complete User Story no 2
b44d66e
Add 'Airport is full' error
23b748a
Add default capacity
d076a25
Refactor, add private method full?
bcd8ca0
Refactor take_off
3d04d31
Complete User story 4
3697420
Add weather class with methods
0955715
Add error message if stormy? true
aa2bbb4
Add weather double and weather logic, correct weather class
ab7ca89
Refactor the code using doubles
c005525
Add no landing in bad weather error
455a680
Update plane class to allow for take-off and landing
c3dbc44
Add allowed to take off method
c3061a3
Add tests to check if plane left_airport? without doubles
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# User story 1 | ||
As an air traffic controller | ||
So I can get passengers to a destination | ||
I want to instruct a plane to land at an airport | ||
|
||
# Nouns | ||
air traffic controller, passengers, destination, plane, airport | ||
|
||
# Verbs | ||
get, instruct, land | ||
|
||
# Functional representation | ||
Objects: | ||
- plane | ||
- airport | ||
|
||
Messages: | ||
- land | ||
|
||
# Diagram | ||
Airport <--land--> Plane | ||
|
||
|
||
################################## | ||
# User story 2 | ||
As an air traffic controller | ||
So I can get passengers on the way to their destination | ||
I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport | ||
|
||
# Nouns | ||
air traffic controller, passengers, destination, plane, airport | ||
|
||
# Verbs | ||
get, instruct, take off, confirm | ||
|
||
# Functional representation | ||
Objects: | ||
- Airport | ||
- Plane | ||
|
||
Messages: | ||
- take_off | ||
- left_airport? | ||
|
||
# Diagrams | ||
Airport <--take_off--> Plane | ||
|
||
Plane <--left_airport?--> true | ||
|
||
|
||
################################## | ||
# User story 3 | ||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent landing when the airport is full | ||
|
||
# Nouns | ||
air traffic controller, safety, airport, full | ||
|
||
# Verbs | ||
ensure, prevent, landing | ||
|
||
# Functional representation | ||
Objects: | ||
- Airport | ||
- Plane | ||
|
||
Messages: | ||
- landing | ||
- full? | ||
|
||
# Diagrams | ||
Airport <--landing--> Plane | ||
|
||
Airport <--full?--> true/false | ||
|
||
|
||
################################## | ||
# User story 4 | ||
As the system designer | ||
So that the software can be used for many different airports | ||
I would like a default airport capacity that can be overridden as appropriate | ||
|
||
# Functional representation | ||
Objects: | ||
- Airport | ||
|
||
Messages: | ||
- set_capacity | ||
|
||
Airport <--set_capacity--> num | ||
|
||
|
||
################################## | ||
# User story 5 | ||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent takeoff when weather is stormy | ||
|
||
# Functional representation | ||
Objects: | ||
- Airport | ||
- Weather | ||
- Plane | ||
|
||
Messages: | ||
- prevent_take_off | ||
|
||
# Diagrams | ||
Airport <--take_off--> Plane | ||
Weather <--stormy?--> ture/false | ||
|
||
|
||
################################## | ||
# User story 6 | ||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent landing when weather is stormy | ||
|
||
# Functional representation | ||
Objects: | ||
- Airport | ||
- Weather | ||
- Plane | ||
|
||
Messages: | ||
- prevent_landing | ||
|
||
# Diagrams | ||
Airport <--land--> Plane | ||
Weather <--stormy?--> true/false | ||
|
||
|
||
################################## | ||
|
||
# Edge cases | ||
- planes can only take off from airports they are in; | ||
# done | ||
- planes that are already flying cannot take off and/or be in an airport; | ||
(when plane lands left_airport? should be false) | ||
# done | ||
- planes that are landed cannot land again and must be in an airport | ||
# done | ||
|
||
################################## |
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,42 @@ | ||
require_relative 'plane' | ||
require_relative 'weather' | ||
|
||
class Airport | ||
|
||
DEFAULT_CAPACITY = 5 | ||
|
||
attr_reader :planes, :capacity | ||
|
||
def initialize(capacity=DEFAULT_CAPACITY) | ||
@planes = [] | ||
@capacity = capacity | ||
end | ||
|
||
def land(plane) | ||
fail 'Airport full' if full? | ||
fail 'Landing not allowed due to adverse weather' if stormy? | ||
fail 'Plane already landed' if @planes.include?(plane) | ||
plane.allowed_land | ||
@planes << plane | ||
plane | ||
end | ||
|
||
def take_off(plane) | ||
fail 'Plane not in the airport' unless @planes.include?(plane) | ||
fail 'Take-off not allowed due to adverse weather' if stormy? | ||
plane.allowed_take_off | ||
@planes.delete(plane) | ||
end | ||
|
||
private | ||
|
||
def full? | ||
@planes.length >= @capacity | ||
end | ||
|
||
def stormy? | ||
weather = Weather.stormy? | ||
weather | ||
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,19 @@ | ||
class Plane | ||
|
||
def initialize | ||
@left_airport = true | ||
end | ||
|
||
def allowed_take_off | ||
@left_airport = true | ||
end | ||
|
||
def left_airport? | ||
@left_airport | ||
end | ||
|
||
def allowed_land | ||
@left_airport = false | ||
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,10 @@ | ||
class Weather | ||
|
||
WEATHER = [:sunny, :rainy, :stormy, :windy] | ||
|
||
def self.stormy? | ||
current_weather = WEATHER.sample | ||
current_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,133 @@ | ||
require './lib/airport' | ||
require './lib/weather' | ||
|
||
describe Airport do | ||
|
||
# Capacity | ||
describe '#capacity' do | ||
|
||
it 'has a default value' do | ||
expect(subject.capacity).to eq Airport::DEFAULT_CAPACITY | ||
end | ||
|
||
it 'can be set to a specific value' do | ||
airport = Airport.new(10) | ||
expect(airport.capacity).to eq 10 | ||
end | ||
|
||
end | ||
|
||
# Lands a plane | ||
describe '#land' do | ||
|
||
it 'airport responds to the method' do | ||
expect(subject).to respond_to :land | ||
end | ||
|
||
it 'accepts one argument' do | ||
expect(subject).to respond_to(:land).with(1).argument | ||
end | ||
|
||
it 'lands a plane' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive(:allowed_land) | ||
expect(subject.land(plane)).to eq plane | ||
end | ||
|
||
it 'rasies an error when airport is full' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive(:allowed_land) | ||
subject.capacity.times {subject.land(Plane.new)} | ||
expect {subject.land(plane)}.to raise_error 'Airport full' | ||
end | ||
|
||
it 'raises an error when the weather is stormy' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(true) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive(:allowed_land) | ||
expect{ subject.land(plane) }.to raise_error 'Landing not allowed due to adverse weather' | ||
end | ||
|
||
it 'raises an error when the plane has already landed' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive(:allowed_land) | ||
subject.land(plane) | ||
expect{ subject.land(plane) }.to raise_error 'Plane already landed' | ||
end | ||
|
||
it 'changes left_airport? to false' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = Plane.new | ||
expect(subject.land(plane)).not_to be_left_airport | ||
end | ||
|
||
end | ||
|
||
# Takes off a plane | ||
describe '#take_off' do | ||
|
||
it 'airport responds to the method' do | ||
expect(subject).to respond_to :take_off | ||
end | ||
|
||
it 'accepts one argument' do | ||
expect(subject).to respond_to(:take_off).with(1).argument | ||
end | ||
|
||
it 'raises an error when the weather is stormy' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive_messages(:allowed_land => nil, :allowed_take_off => nil) | ||
subject.land(plane) | ||
|
||
allow(weather).to receive(:stormy?).and_return(true) | ||
expect{ subject.take_off(plane) }.to raise_error 'Take-off not allowed due to adverse weather' | ||
end | ||
|
||
it 'takes-off the plane when the weather is NOT stormy' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive_messages(:allowed_land => nil, :allowed_take_off => nil) | ||
subject.land(plane) | ||
expect(subject.take_off(plane)).to eq plane | ||
end | ||
|
||
it 'confirms the plane has left_airport?' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = Plane.new | ||
subject.land(plane) | ||
#expect(plane.left_airport?).to eq true | ||
expect(subject.take_off(plane)).to be_left_airport | ||
end | ||
|
||
it 'raises an error when the plane is not in the airport' do | ||
weather = class_double('Weather').as_stubbed_const | ||
allow(weather).to receive(:stormy?).and_return(false) | ||
|
||
plane = double (:plane) | ||
allow(plane).to receive_messages(:allowed_land => nil, :allowed_take_off => nil) | ||
expect{subject.take_off(plane)}.to raise_error 'Plane not in the airport' | ||
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,27 @@ | ||
require 'plane' | ||
|
||
describe Plane do | ||
|
||
it 'responds to allowed_take_off method' do | ||
expect(subject).to respond_to :allowed_take_off | ||
end | ||
|
||
it 'responds to _left_airport? method' do | ||
expect(subject).to respond_to :left_airport? | ||
end | ||
|
||
it 'after allowed_take_off returns true for left_airport?' do | ||
subject.allowed_take_off | ||
expect(subject).to be_left_airport | ||
end | ||
|
||
it 'responds to allowed_land method' do | ||
expect(subject).to respond_to :allowed_land | ||
end | ||
|
||
it 'after allowed_land returns false for left_airport' do | ||
subject.allowed_land | ||
expect(subject).not_to be_left_airport | ||
end | ||
|
||
end |
Oops, something went wrong.
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.
Adding doubles to the top of the Airport spec would dry code a bit