Skip to content
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 completed pull request #2509

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d6466dd
Add personal readme to document process
lukestorey95 Apr 23, 2022
ef104d4
Described Airport class
lukestorey95 Apr 23, 2022
ad82945
Describe #land to take argument
lukestorey95 Apr 23, 2022
1dd3e30
Describe Plane class
lukestorey95 Apr 23, 2022
c2b0bab
Describe land and expect it to land plane
lukestorey95 Apr 23, 2022
478c49e
Complete user story 1
lukestorey95 Apr 23, 2022
952d126
Update README to use my version
lukestorey95 Apr 23, 2022
a55ea37
Add user story 2
lukestorey95 Apr 23, 2022
9764bf6
Describe Airport::TakeOff
lukestorey95 Apr 23, 2022
2df6d0c
Expect Airport to not contain plane after it has taken off
lukestorey95 Apr 23, 2022
dc9d903
Complete user story 2
lukestorey95 Apr 23, 2022
8a1a800
Add user story 3
lukestorey95 Apr 23, 2022
a1fa0a5
Complete user story 3
lukestorey95 Apr 23, 2022
51119d0
Add user story 4
lukestorey95 Apr 23, 2022
f949f53
Update story 3 feature test
lukestorey95 Apr 23, 2022
e6d17f5
Add capacity and refactor to use it
lukestorey95 Apr 23, 2022
ce5328b
Refactor to use private methods
lukestorey95 Apr 23, 2022
a936d4b
Complete user story 4
lukestorey95 Apr 23, 2022
a0bdfba
Add edge case plane can't take off if not at airport
lukestorey95 Apr 23, 2022
acabf30
Track and change landed state of plane
lukestorey95 Apr 23, 2022
a23e9fb
Refactor tests to read more clearly
lukestorey95 Apr 23, 2022
bbf1a15
Refactor plane spec to test behaviour not state
lukestorey95 Apr 23, 2022
f9de7e6
Refactor plane to use private methods
lukestorey95 Apr 23, 2022
297ebe6
Refactor airport to use private methods
lukestorey95 Apr 23, 2022
224587c
Refactor airport_spec to test behaviour not state
lukestorey95 Apr 23, 2022
44c8712
Add edge case tests for plane state
lukestorey95 Apr 24, 2022
83494fd
Add user stories 5 & 6
lukestorey95 Apr 24, 2022
9e03049
Add weather class and stormy? method
lukestorey95 Apr 24, 2022
953b41e
Refactor weather to use private method
lukestorey95 Apr 24, 2022
701252a
Add rubocop
lukestorey95 Apr 24, 2022
0a7476b
Complete user story 5
lukestorey95 Apr 24, 2022
dba29af
Complete user story 5
lukestorey95 Apr 24, 2022
786e62d
Complete user story 6
lukestorey95 Apr 24, 2022
da6ee2e
Refactor to be more literal and adhere to SRP
lukestorey95 Apr 24, 2022
6875e98
Add instructions for installation and use
lukestorey95 Apr 24, 2022
61f1f76
Update completed checklist for README
lukestorey95 Apr 24, 2022
ee3061c
Update program description for
lukestorey95 Apr 24, 2022
7655702
Add badges
lukestorey95 Apr 24, 2022
d187153
Update badge
lukestorey95 Apr 24, 2022
7ed7d39
Update badge
lukestorey95 Apr 24, 2022
965a7d7
Update badges
lukestorey95 Apr 24, 2022
4b41790
Update badge
lukestorey95 Apr 24, 2022
b87fabf
Add test results
lukestorey95 Apr 24, 2022
fa9a4da
Add tests results
lukestorey95 Apr 24, 2022
3280386
Refactor spec for legibility
lukestorey95 Apr 24, 2022
d41f6e7
Add README to describe and document program
lukestorey95 Apr 23, 2022
42e4bdd
Complete user story 1
lukestorey95 Apr 23, 2022
7992566
Update README with user stories and feature tests
lukestorey95 Apr 23, 2022
48ed5d3
Complete user story 2
lukestorey95 Apr 23, 2022
ee3149f
Complete user story 3
lukestorey95 Apr 23, 2022
3c55b0e
Complete user story 4
lukestorey95 Apr 23, 2022
ff731ab
Add edge cases
lukestorey95 Apr 23, 2022
408efd2
Complete user story 5
lukestorey95 Apr 24, 2022
a483abf
Complete user story 6
lukestorey95 Apr 24, 2022
73b2418
Refactor to be more literal and adhere to SRP
lukestorey95 Apr 24, 2022
25031d0
Update README with setup, installation and usage
lukestorey95 Apr 24, 2022
e7a76d7
Refactor spec for legibility
lukestorey95 Apr 24, 2022
c258013
Merge remote-tracking branch 'refs/remotes/origin/main'
lukestorey95 Apr 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Your name

Please write your full name here to make it easier to find your pull request.
Luke Storey

# User stories
# 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!
[Here is a pill](https://github.com/makersacademy/course/blob/main/pills/readmes.md) that can help you write a great README!
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ group :test do
gem 'rspec'
gem 'simplecov', require: false
gem 'simplecov-console', require: false
gem 'simplecov-shields-badge', require: false
end

group :development, :test do
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ GEM
simplecov
terminal-table
simplecov-html (0.12.3)
simplecov-shields-badge (0.1.0)
simplecov (~> 0.15)
simplecov_json_formatter (0.1.3)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
Expand All @@ -58,6 +60,7 @@ DEPENDENCIES
rubocop (= 1.20)
simplecov
simplecov-console
simplecov-shields-badge

RUBY VERSION
ruby 3.0.2p107
Expand Down
214 changes: 156 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,187 @@
Airport Challenge
=================
# Airport Challenge

[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
[![Coverage](./badge.svg)](https://github.com/lukestorey95/airport_challenge)

This program allows the user to simulate a working airport. Planes are able to land and take off from an airport so long as the weather isn't stormy.

<br>

## Installation

```
$ git clone https://github.com/lukestorey95/airport_challenge.git

$ cd airport_challenge

$ bundle
```
______
_\____\___
= = ==(____MA____)
\_____\___________________,-~~~~~~~`-.._
/ o o o o o o o o o o o o o o o o |\_
`~-.__ __..----..__ )
`---~~\___________/------------`````
= ===(_________)

<br>

## Quickstart

```
irb

> Dir['./lib/*.rb'].each {|file| require file }

> airport = Airport.new
> plane = Plane.new

> airport.land(plane)

> airport.take_off(plane)
```

> For more usage please see user stories below

<br>

## Running Tests

```
$ rspec
```

<details>
<summary>Click to see test results</summary>

![Test results](./test_results.png)

</details>

<br>

## My Process

1. Break down user story into objects and behaviour
2. Feature test and note down errors/expected errors
3. Write failing test that replicates errors
4. Write the minimum code to make test pass
5. Refactor and ensure tests still pass
6. Repeat step 2 and ensure behaviour works as intended

<br>

## User Stories

> I want to instruct a **_plane_** to **_land_** at an **_airport_**

```
airport = Airport.new
plane = Plane.new
airport.land(plane)
```

---

> I want to instruct a **_plane_** to **_take off_** from an **_airport_** and **_confirm_** that it is no longer in the **_airport_**

Instructions
---------
```
airport = Airport.new
plane = Plane.new
airport.land(plane)
airport.take_off(plane)
airport.planes
```

* 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
---

Steps
-------
> I want to **_prevent landing_** when the **_airport_** is **_full_**

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:
```
airport = Airport.new
plane = Plane.new
airport.land(plane)
airport.land(plane)
```

Task
-----
---

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:
> I would like a **_default airport capacity_** that can **_be overridden_** as appropriate

```
As an air traffic controller
So I can get passengers to a destination
I want to instruct a plane to land at an airport
airport = Airport.new(3)
plane = Plane.new
airport.capacity.times { airport.land(plane) }
airport.land(plane)
```

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
---

As an air traffic controller
To ensure safety
I want to prevent landing when the airport is full
> I want to **_prevent takeoff_** when **_weather_** is stormy

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
```
airport = Airport.new
plane = Plane.new
weather = Weather.new
airport.land(plane)
airport.take_off(plane)
#=> should raise error if weather is stormy
```

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
> I want to **_prevent landing_** when **_weather_** is stormy

```
airport = Airport.new
plane = Plane.new
weather = Weather.new
airport.land(plane)
#=> should raise error if 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.
<br>

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.
## Edge Cases

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.
> I want to **_prevent_** a **_plane_** from **_taking off_**, if it is not in the correct **_airport_**

Please create separate files for every class, module and test suite.
```
airport = Airport.new
plane = Plane.new
airport.take_off(plane)
#=> should raise error
```

In code review we'll be hoping to see:
> I want to **_prevent_** a **_landed plane_** from **_landing_** again

* 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.
```
airport = Airport.new
plane = Plane.new
airport.land(plane)
airport.land(plane)
#=> should raise error
```

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.
> I want to **_prevent_** a **_flying plane_** from **_taking off_** again

**BONUS**
```
airport = Airport.new
plane = Plane.new
airport.land(plane)
airport.take_off(plane)
airport.take_off(plane)
#=> should raise error
```

<br>

## Feature Test

* Write an RSpec **feature** test that lands and takes off a number of planes
> I want to **_land_** and then **_take off_** several **_planes_** at once

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)
```
airport = Airport.new(3)
planes = Array.new(3) { Plane.new }

planes.each { |plane| airport.land(plane) }

Finally, don’t overcomplicate things. This task isn’t as hard as it may seem at first.
# airport should contain the planes and the planes should be landed

* **Submit a pull request early.**
planes.each { |plane| airport.take_off(plane) }

* 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.
# airport should not contain the planes and the planes should be flying
```
89 changes: 89 additions & 0 deletions README_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Airport Challenge
=================

```
______
_\____\___
= = ==(____MA____)
\_____\___________________,-~~~~~~~`-.._
/ o o o o o o o o o o o o o o o o |\_
`~-.__ __..----..__ )
`---~~\___________/------------`````
= ===(_________)

```

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

Steps
-------

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
-----

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:

```
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

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.
Loading