-
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 (Erlantz) #2503
base: main
Are you sure you want to change the base?
Changes from all commits
4566c14
3c00ba2
476bd47
ab314f0
44d05a3
3159d2e
ad14342
5d1cc1d
5589283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
# Your name | ||
# Erlantz Ramos | ||
|
||
|
||
Please write your full name here to make it easier to find your pull request. | ||
|
||
# User stories | ||
|
||
Please list which user stories you've implemented (delete the ones that don't apply). | ||
|
||
- [ ] User story 1: "I want to instruct a plane to land at an airport" | ||
- [ ] User story 2: "I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport" | ||
- [ ] User story 3: "I want to prevent landing when the airport is full" | ||
- [ ] User story 4: "I would like a default airport capacity that can be overridden as appropriate" | ||
- [ ] User story 5: "I want to prevent takeoff when weather is stormy" | ||
- [ ] User story 6: "I want to prevent landing when weather is stormy" | ||
- [x] User story 1: "I want to instruct a plane to land at an airport" | ||
- [x] User story 2: "I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport" | ||
- [x] User story 3: "I want to prevent landing when the airport is full" | ||
- [x] User story 4: "I would like a default airport capacity that can be overridden as appropriate" | ||
- [x] User story 5: "I want to prevent takeoff when weather is stormy" | ||
- [x] User story 6: "I want to prevent landing when weather is stormy" | ||
|
||
# README checklist | ||
|
||
Does your README contains instructions for | ||
|
||
- [ ] how to install, | ||
- [ ] how to run, | ||
- [ ] and how to test your code? | ||
- [x] how to install, | ||
- [x] how to run, | ||
- [x] and how to test your code? | ||
|
||
[Here is a pill](https://github.com/makersacademy/course/blob/main/pills/readmes.md) that can help you write a great README! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,25 @@ | ||
Airport Challenge | ||
================= | ||
# Airport Challenge | ||
|
||
``` | ||
______ | ||
_\____\___ | ||
= = ==(____MA____) | ||
\_____\___________________,-~~~~~~~`-.._ | ||
/ o o o o o o o o o o o o o o o o |\_ | ||
`~-.__ __..----..__ ) | ||
`---~~\___________/------------````` | ||
= ===(_________) | ||
Code to simulate an Airport, according to six user stories: | ||
|
||
``` | ||
- User story 1: "I want to instruct a plane to land at an airport" | ||
- User story 2: "I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport" | ||
- User story 3: "I want to prevent landing when the airport is full" | ||
- User story 4: "I would like a default airport capacity that can be overridden as appropriate" | ||
- User story 5: "I want to prevent takeoff when weather is stormy" | ||
- User story 6: "I want to prevent landing when weather is stormy" | ||
|
||
Instructions | ||
--------- | ||
|
||
* Feel free to use google, your notes, books, etc. but work on your own | ||
* If you refer to the solution of another coach or student, please put a link to that in your README | ||
* If you have a partial solution, **still check in a partial solution** | ||
* You must submit a pull request to this repo with your code by 10am Monday morning | ||
## Getting started | ||
|
||
Steps | ||
------- | ||
Install Ruby and RSpec | ||
|
||
1. Fork this repo, and clone to your local machine | ||
2. Run the command `gem install bundler` (if you don't have bundler already) | ||
3. When the installation completes, run `bundle` | ||
4. Complete the following task: | ||
|
||
Task | ||
----- | ||
## Usage | ||
|
||
We have a request from a client to write the software to control the flow of planes at an airport. The planes can land and take off provided that the weather is sunny. Occasionally it may be stormy, in which case no planes can land or take off. Here are the user stories that we worked out in collaboration with the client: | ||
Run both 'airport.rb' and 'plane.rb' | ||
|
||
``` | ||
As an air traffic controller | ||
So I can get passengers to a destination | ||
I want to instruct a plane to land at an airport | ||
|
||
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 | ||
## Running tests | ||
|
||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent landing when the airport is full | ||
|
||
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 | ||
|
||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent takeoff when weather is stormy | ||
|
||
As an air traffic controller | ||
To ensure safety | ||
I want to prevent landing when weather is stormy | ||
``` | ||
|
||
Your task is to test drive the creation of a set of classes/modules to satisfy all the above user stories. You will need to use a random number generator to set the weather (it is normally sunny but on rare occasions it may be stormy). In your tests, you'll need to use a stub to override random weather to ensure consistent test behaviour. | ||
|
||
Your code should defend against [edge cases](http://programmers.stackexchange.com/questions/125587/what-are-the-difference-between-an-edge-case-a-corner-case-a-base-case-and-a-b) such as inconsistent states of the system ensuring that planes can only take off from airports they are in; planes that are already flying cannot take off and/or be in an airport; planes that are landed cannot land again and must be in an airport, etc. | ||
|
||
For overriding random weather behaviour, please read the documentation to learn how to use test doubles: https://www.relishapp.com/rspec/rspec-mocks/docs . There’s an example of using a test double to test a die that’s relevant to testing random weather in the test. | ||
|
||
Please create separate files for every class, module and test suite. | ||
|
||
In code review we'll be hoping to see: | ||
|
||
* All tests passing | ||
* High [Test coverage](https://github.com/makersacademy/course/blob/main/pills/test_coverage.md) (>95% is good) | ||
* The code is elegant: every class has a clear responsibility, methods are short etc. | ||
|
||
Reviewers will potentially be using this [code review rubric](docs/review.md). Referring to this rubric in advance will make the challenge somewhat easier. You should be the judge of how much challenge you want this at this moment. | ||
|
||
**BONUS** | ||
|
||
* Write an RSpec **feature** test that lands and takes off a number of planes | ||
|
||
Note that is a practice 'tech test' of the kinds that employers use to screen developer applicants. More detailed submission requirements/guidelines are in [CONTRIBUTING.md](CONTRIBUTING.md) | ||
|
||
Finally, don’t overcomplicate things. This task isn’t as hard as it may seem at first. | ||
|
||
* **Submit a pull request early.** | ||
|
||
* Finally, please submit a pull request before Monday at 10am with your solution or partial solution. However much or little amount of code you wrote please please please submit a pull request before Monday at 10am. | ||
Run rspec on main folder |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class Airport | ||
|
||
DEFAULT_CAPACITY = 1 | ||
|
||
def initialize(capacity = DEFAULT_CAPACITY) | ||
@planes = [] | ||
@capacity = capacity | ||
end | ||
|
||
attr_accessor :capacity | ||
attr_reader :planes | ||
|
||
def land(plane) | ||
fail 'Airport full' if full? | ||
fail 'Plane cannot land on stormy weather' if weather == "stormy" | ||
planes << plane | ||
end | ||
|
||
def take_off(plane) | ||
fail 'Plane cannot take off on stormy weather' if weather == "stormy" | ||
fail 'Plane not in this airport' unless plane_in_airport?(plane) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good. I should have written something similar. |
||
planes.delete(plane) | ||
"#{plane} no longer in #{self} airport" | ||
end | ||
|
||
def weather | ||
return "stormy" if rand(20) == 1 | ||
"sunny" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote weather as a new class. Yours is more succinct but since the weather is effectively a different entity to airport and plane, I think it should be it's own class. |
||
|
||
private | ||
|
||
def plane_in_airport?(plane) | ||
planes.include?(plane) | ||
end | ||
|
||
def full? | ||
planes.count >= capacity | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Plane | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'airport' | ||
require 'plane' | ||
|
||
describe Airport do | ||
|
||
it 'class Airport works' do | ||
expect(subject).to be_a_kind_of(Airport) | ||
end | ||
|
||
it 'plane can land in an airport' do | ||
expect(subject).to respond_to(:land).with(1).argument | ||
end | ||
|
||
it 'plane can take off from an airport' do | ||
expect(subject).to respond_to(:take_off).with(1).argument | ||
end | ||
|
||
describe "#take_off" do | ||
|
||
it 'take_off method confirms plane is not longer in the airport' do | ||
plane = Plane.new | ||
allow(subject).to receive(:weather) { "sunny" } | ||
subject.land(plane) | ||
expect(subject.take_off(plane)).to eq ("#{plane} no longer in #{subject} airport") | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very clear - I like matching to the message. |
||
|
||
it 'take_off method removes a plane from the airport (testing capacity of 6 planes)' do | ||
capacity_test = 6 | ||
plane = Plane.new | ||
airport = Airport.new(capacity_test) | ||
allow(airport).to receive(:weather) { "sunny" } | ||
airport.land(plane) | ||
(capacity_test - 1).times { airport.land(Plane.new) } | ||
airport.take_off(plane) | ||
expect { airport.land(Plane.new) }.not_to raise_error | ||
end | ||
|
||
it 'plane cannot take off when stormy weather' do | ||
allow(subject).to receive(:weather) { "sunny" } | ||
plane = Plane.new | ||
subject.land(plane) | ||
allow(subject).to receive(:weather) { "stormy" } | ||
expect { subject.take_off(plane) }.to raise_error 'Plane cannot take off on stormy weather' | ||
end | ||
|
||
it 'take_off method to take out specific plane from airport' do | ||
plane = Plane.new | ||
airport = Airport.new(3) | ||
allow(airport).to receive(:weather) { "sunny" } | ||
airport.land(plane) | ||
airport.land(Plane.new) | ||
airport.take_off(plane) | ||
expect(airport.planes).not_to include(plane) | ||
end | ||
|
||
it 'take_off raise error if plane is not in the airport' do | ||
allow(subject).to receive(:weather) { "sunny" } | ||
subject.land(Plane.new) | ||
expect { subject.take_off(Plane.new) }.to raise_error ('Plane not in this airport') | ||
end | ||
|
||
end | ||
|
||
describe "#land" do | ||
|
||
it 'raise an error if airport is full and try to land a plane (testing capacity of 6 planes)' do | ||
capacity_test = 6 | ||
airport = Airport.new(capacity_test) | ||
allow(airport).to receive(:weather) { "sunny" } | ||
capacity_test.times { airport.land(Plane.new) } | ||
expect { airport.land(Plane.new) }.to raise_error 'Airport full' | ||
end | ||
|
||
it 'plane cannot land when stormy weather' do | ||
allow(subject).to receive(:weather) { "stormy" } | ||
expect { subject.land(Plane.new) }.to raise_error 'Plane cannot land on stormy weather' | ||
end | ||
|
||
end | ||
|
||
it 'capacity of airport can be overriden' do | ||
subject.capacity = 20 | ||
expect(subject.capacity).to eq(20) | ||
end | ||
|
||
it 'weather returns sunny or stormy' do | ||
expect(subject.weather).to eq("sunny").or eq("stormy") | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'plane' | ||
|
||
describe Plane do | ||
|
||
it 'class Plane works' do | ||
expect(subject).to be_a_kind_of(Plane) | ||
end | ||
|
||
end |
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.
Is this a constant? Could you just set your initialized capacity to 1?