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

Liam R Airport Challenge Submission #181

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
81 changes: 81 additions & 0 deletions AirportChallenge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Airport Challenge
=================

```
______
__\____\___
= = ==(____DFA____)
\_____\__________________,-~~~~~~~`-.._
/ 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.
* Keep it SIMPLE - it's not nearly as complicated as it first may look.
* You must [submit your challenge](https://airtable.com/shrUGm2T8TYCFAmjN) by the deadline, wherever you get to.
* Use your own test framework and evidence your test-driven development by committing on passing tests.
* Please write your own README detailing how to install your project, how to run the tests, how you approached the problem and provide screenshots of interacting with your program.
* If you refer to the solution of another coach or student, please put a link to that in your README.
* Please create separate files for every class, module, and spec.

Steps
-------

1. Fork this repo, and clone to your local machine
2. `npm install` to install project dependencies
3. Convert stories into a representative domain model and test-drive your work.
4. Run your tests using `npm test` or `node specRunner.js`
5. OPTIONAL: [Lint](https://eslint.org/docs/user-guide/getting-started) your source code using `npx eslint src`.

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:

#### Acceptance Criteria
```
As an air traffic controller
So I can get passengers to a destination
I want to instruct the airport to land a plane

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 landing when the airport is full

As an air traffic controller
So I can get passengers on the way to their destination
I want to instruct the airport to let a plane take off and confirm that it is no longer in the airport

As an air traffic controller
To avoid confusion
I want to prevent asking the airport to let planes take-off which are not at the airport, or land a plane that's already landed
```

#### Extended Acceptance Criteria
```
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

As an air traffic controller
To count planes easily
Planes that have landed must be at an airport
```

Your task is to test drive the creation of a set of classes/objects 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 stub random behaviour 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.
192 changes: 192 additions & 0 deletions DomainModels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Airport Challenge

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domain modelling and planning was clear and well done


### User Story 1

```
As an air traffic controller
So I can get passengers to a destination
I want to instruct the airport to land a plane
```

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ----------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |

#### Tests
1. When `landPlane()` is called `airportPlaneList` increases by 1
2. `landPlane()` puts the plane with the correct id in `airportPlaneList`


### User Story 2

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

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------- | -----------------------| --------|
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | | |

#### Tests
1. There is an `airportCapacity @number` that can be called - default capacity
2. When `modifyAirportCapacity` is called, `airportCapacity @number` changes to expected number.
3. `modifyAirportCapacity` can only change airport capacity to an integer


### User Story 3

```
As an air traffic controller
To ensure safety
I want to prevent landing when the airport is full
```

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ---------------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | isAirportFull() | @Boolean |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |

#### Tests
1. `isAirportFull` returns true if `airportPlaneList` amount is equal to `airportCapacity @number`
2. `isAirportFull` returns false if `airportPlaneList` is less than `airportCapacity @number`
3. If `isAirportFull` is true, then `landPlane(@Plane)` will not modify `airportPlaneList @Array`
4. If `isAirportFull` is true and `landPlane(@Plane)` is called, then an error is thrown. (I anticipate this will require refactoring of test 3)

### User Story 4

```
As an air traffic controller
So I can get passengers on the way to their destination
I want to instruct the airport to let a plane take off and confirm that it is no longer in the airport
```

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ---------------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | | takeOff(@Plane) | @Void |
| | | planeInAirport(@Plane) | @Boolean |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | isAirportFull() | @Boolean |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |

#### Tests
1. `takeOff(@Plane)` should remove one plane from `airportPLaneList`
2. `takeOff(@Plane)` should remove a given plane (check id) from `airportPLaneList` - decided to omit
3. `planeInAirport` should return true if that plane is in `airportPLaneList`
4. `planeInAirport` should return false if that plane is not in `airportPlaneList`

### User Story 5

```
As an air traffic controller
To avoid confusion
I want to prevent asking the airport to let planes take-off which are not at the airport, or land a plane that's already landed
```

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ---------------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | | takeOff(@Plane) | @Void |
| | | planeInAirport(@Plane) | @Boolean |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | isAirportFull() | @Boolean |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |

#### Tests

`planeInAirport` functionality was tested in User Story 4 so this modifies `takeOff(@plane)` and `landPlane(@Plane)` to check `planeInAirport`.

1. If `takeOff(@Plane)` is called but `planeInAirport(@Plane)` returns false, then an error is thrown
2. If `landPlane(@Plane)` is called but `planeInAirport(@Plane)` returns true, then an error is thrown

### Extended Criteria - User Story 6 & 7

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

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ---------------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | | takeOff(@Plane) | @Void |
| | | planeInAirport(@Plane) | @Boolean |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | isAirportFull() | @Boolean |
| | weatherCondition | isStormy() | @Boolean |
| | | setWeather(@String) | @Void |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |
| Weather | weatherStatus | weatherReport() | @String |

#### Tests

Thought process: `setWeather` will be used to ensure consistent behaviour for testing - random number generator will be implemented to `Weather` class for randomised weather conditions and used in index.js

1. Check `setWeather` alters `weatherCondition`.
2. Check `isStormy` returns true when `setWeather` has the parameters of 'stormy'.
3.. Plane does not take off if airport `isStormy` is true.
4. Plane can take off if `isStormy` is false.
5. Plane does not land if `isStormy` is true.
6. Plane can land if `isStormy` is false.



### Extended Criteria - User Story 8

```
As an air traffic controller
To count planes easily
Planes that have landed must be at an airport
```

#### Domain Model
| Objects | Properties | Messages | Output |
| ----------- | ------------------------------ | ---------------------- | -------- |
| Airport | airportPlaneList @Array[@Id] | landPlane(@Plane) | @Void |
| | | takeOff(@Plane) | @Void |
| | | planeInAirport(@Plane) | @Boolean |
| | | planeCount() | @number |
| | airportCapacity @number | modifyAirportCapacity()| @Void |
| | | isAirportFull() | @Boolean |
| | weatherCondition | isStormy() | @Boolean |
| | | setWeather(@String) | @Void |
| | | | |
| Plane | id @String | getId() | @String |
| | | | |
| Weather | weatherStatus | weatherReport() | @String |

#### Tests

Thought process: Trying to land a plane without defining an airport or to an airport that does not exist will return an error. Functionality of landing and taking off planes has been tested above - so planes in an airport will be stored in [given airport].airportPlaneList. Therefore can then test and create function that counts the number of planes in a given airport for the air traffic controller.

1. `planeCount()` will return the correct number of planes in an airport.
84 changes: 17 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Airport Challenge
Airport Challenge (Outline can be found in AirportChallenge.md)
=================

```
Expand All @@ -13,69 +13,19 @@ Airport Challenge

```

Instructions
---------

* Feel free to use google, your notes, books, etc. but work on your own.
* Keep it SIMPLE - it's not nearly as complicated as it first may look.
* You must [submit your challenge](https://airtable.com/shrUGm2T8TYCFAmjN) by the deadline, wherever you get to.
* Use your own test framework and evidence your test-driven development by committing on passing tests.
* Please write your own README detailing how to install your project, how to run the tests, how you approached the problem and provide screenshots of interacting with your program.
* If you refer to the solution of another coach or student, please put a link to that in your README.
* Please create separate files for every class, module, and spec.

Steps
-------

1. Fork this repo, and clone to your local machine
2. `npm install` to install project dependencies
3. Convert stories into a representative domain model and test-drive your work.
4. Run your tests using `npm test` or `node specRunner.js`
5. OPTIONAL: [Lint](https://eslint.org/docs/user-guide/getting-started) your source code using `npx eslint src`.

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:

#### Acceptance Criteria
```
As an air traffic controller
So I can get passengers to a destination
I want to instruct the airport to land a plane

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 landing when the airport is full

As an air traffic controller
So I can get passengers on the way to their destination
I want to instruct the airport to let a plane take off and confirm that it is no longer in the airport

As an air traffic controller
To avoid confusion
I want to prevent asking the airport to let planes take-off which are not at the airport, or land a plane that's already landed
```

#### Extended Acceptance Criteria
```
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

As an air traffic controller
To count planes easily
Planes that have landed must be at an airport
```

Your task is to test drive the creation of a set of classes/objects 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 stub random behaviour 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.
### Instructions
- Use `npm test` or `node specRunner.js` to execute tests.
- There is also `index.js` which can be run to see an example of randomised weather which will allow a plane to land if it is sunny or alert to a landing error if it is stormy.

### How I approached the project
- I converted each of the user stories into domain models, and planned out the tests I would write to enable TDD.
- I created a new spec file for each method then wrote each of the user stories tests to fail and created production code to create passing tests.
- I also created an index.js to run an instance of randomised weather for the functionality outlined in the extended criteria.

### Reflections
Given more time I would like to:
- Clean up code - some of the airport.js code is too verbose and has too many parameters. Lint code.
- Refactor code so airport, weather and plane properties can be private.
- Greater defense against edge cases (e.g. different weather inputs).
- Write a larger index.js run more of the functionalities of the programme.
- Improved the error functionality so that the programme does not stop unless try&catch statements are implemented in index.js
Loading