Skip to content

Commit

Permalink
Updated ReadMe and notes added
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhodine-orleans-lindsay committed Jan 31, 2020
1 parent a7d59d4 commit a735363
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 151 deletions.
Binary file added JavaScriptAirport/JS Event Listener.pages
Binary file not shown.
Binary file not shown.
53 changes: 31 additions & 22 deletions JavaScriptAirport/spec/FeatureSpec.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
'use strict';
describe('Feature Test', function (){
describe('Feature Test', function() {
var plane;
var airport;

beforeEach(function(){
beforeEach(function() {
plane = new Plane();
airport = new Airport();
});
it('allows planes to land at the airport', function(){
plane.land(airport);
expect(airport.planes()).toContain(plane)
});
it('planes can takeoff', function(){
plane.land(airport);
plane.takeoff(airport);
expect(airport.planes()).not.toContain(plane);
});
describe('normal weather conditions', function() {
beforeEach(function(){
spyOn(Math, 'random').and.returnValue(0);
});

it('stops planes from taking off when weather is stormy', function(){
plane.land(airport);
spyOn(airport, 'isStormy').and.returnValue(true);
expect(function(){
it('allows planes to land at the airport', function() {
plane.land(airport);
expect(airport.planes()).toContain(plane)
});
it('planes can takeoff', function() {
plane.land(airport);
plane.takeoff(airport);
}).toThrowError('Takeoff prohibited due to storm conditions');
expect(airport.planes()).toContain(plane);
expect(airport.planes()).not.toContain(plane);
});
});

it('stops planes from landing when weather is stormy', function(){
spyOn(airport, 'isStormy').and.returnValue(true);
expect(function(){
describe('stormy conditions', function() {
it('stops planes from taking off when weather is stormy', function() {
spyOn(Math, 'random').and.returnValue(0);
plane.land(airport);
}).toThrowError('Landing prohibited due to storm conditions');
expect(airport.planes()).not.toContain(plane);
spyOn(airport._weather, 'isStormy').and.returnValue(true);
expect(function(){
plane.takeoff(airport);
}).toThrowError('Takeoff prohibited due to storm conditions');
expect(airport.planes()).toContain(plane);
});

it('stops planes from landing when weather is stormy', function() {
spyOn(Math, 'random').and.returnValue(1);
expect(function() {
plane.land(airport);
}).toThrowError('Landing prohibited due to storm conditions');
expect(airport.planes()).not.toContain(plane);
});
});
});
75 changes: 39 additions & 36 deletions JavaScriptAirport/spec/airportSpec.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
'use strict'
describe('Airport', function(){
describe('Airport', function() {
var airport;
var plane;
beforeEach(function(){
airport = new Airport();
var weather;

beforeEach(function() {
plane = jasmine.createSpy('plane',['land']);
weather = jasmine.createSpyObj('weather',['isStormy']);
airport = new Airport(weather);
});
it('has no planes by default', function(){

it('has no planes by default', function() {
expect(airport.planes()).toEqual([]);
});
it('can clear planes for landing', function(){
airport.clearForLanding(plane);
expect(airport.planes()).toEqual([plane]);
});

it('can clear planes for takeoff', function(){
airport.clearForLanding(plane);
airport.clearForTakeoff(plane);
expect(airport.planes()).toEqual([]);
describe('normal conditions', function() {
beforeEach(function() {
weather.isStormy.and.returnValue(false);
});
it('can clear planes for landing', function() {
airport.clearForLanding(plane);
expect(airport.planes()).toEqual([plane]);
});
it('can clear planes for takeoff', function() {
airport.clearForLanding(plane);
airport.clearForTakeoff(plane);
expect(airport.planes()).toEqual([]);
});
});

describe('capacity', function(){
it('responds to capacity', function(){

describe('capacity', function() {
it('responds to capacity', function() {
expect(airport.capacity).not.toBeUndefined();
});

it('sets default capacity', function(){
it('sets default capacity', function() {
expect(airport.capacity).toEqual(airport.DEFAULT_CAPACITY);
});

it('raises an error if full', function(){
it('raises an error if full', function() {
airport.capacity = 1;
airport.clearForLanding(plane);
expect(function(){
expect(function() {
airport.clearForLanding(plane);
}).toThrowError("Airport Full!");
});

it('raises an error if empty', function(){
expect(function(){
it('raises an error if empty', function() {
expect(function() {
airport.clearForTakeoff(plane);
}).toThrowError("Airport Empty!");
});
});

it('checks for storm conditions', function(){
expect(airport.isStormy()).toBeFalsy();
});

describe('under stormy conditions',function(){
it('does not clear planes for takeoff when stormy', function(){
spyOn(airport,'isStormy').and.returnValue(true);
expect(function(){
describe('under stormy conditions',function() {
beforeEach(function() {
weather.isStormy.and.returnValue(true);
});
it('does not clear planes for takeoff when stormy', function() {
expect(function() {
airport.clearForTakeoff(plane);
}).toThrowError('Takeoff prohibited due to storm conditions');
});

it('does not clear planes for landing when stormy', function(){
spyOn(airport,'isStormy').and.returnValue(true);
expect(function(){
airport.clearForLanding(plane);
}).toThrowError('Landing prohibited due to storm conditions');
it('does not clear planes for landing when stormy', function() {
expect(function() {
airport.clearForLanding(plane);
}).toThrowError('Landing prohibited due to storm conditions');
});
});
});
10 changes: 5 additions & 5 deletions JavaScriptAirport/spec/planeSpec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict'
describe('Plane', function(){
describe('Plane', function() {
var plane;
var airport
beforeEach(function(){
beforeEach(function() {
plane = new Plane();
airport = jasmine.createSpyObj('airport',['clearForLanding','clearForTakeoff']);
});
it('can land at an airport', function(){
it('can land at an airport', function() {
plane.land(airport);
expect(airport.clearForLanding).toHaveBeenCalledWith(plane);
});
it('can takeoff from the airport', function(){
it('can takeoff from the airport', function() {
plane.land(airport);
plane.takeoff(airport);
expect(airport.clearForTakeoff).toHaveBeenCalledWith();
expect(airport.clearForTakeoff).toHaveBeenCalled();
});
});
9 changes: 5 additions & 4 deletions JavaScriptAirport/spec/weatherSpec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict'

describe('Weather', function(){
describe('Weather', function() {
var weather;
beforeEach(function(){

beforeEach(function() {
weather = new Weather();
});
it('is stormy sometimes', function(){
it('is stormy sometimes', function() {
spyOn(Math,'random').and.returnValue(1);
expect(weather.isStormy()).toBeTruthy();
});
it('is not stormy other times', function(){
it('is not stormy other times', function() {
spyOn(Math,'random').and.returnValue(0);
expect(weather.isStormy()).toBeFalsy();
});
Expand Down
25 changes: 13 additions & 12 deletions JavaScriptAirport/src/airport.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
'use strict'
class Airport{
constructor(){
class Airport {
constructor(weather) {
this.DEFAULT_CAPACITY = 20;
this._weather = typeof weather !== 'undefined' ? weather : new Weather();
this._runway = [];
this.capacity = this.DEFAULT_CAPACITY;
};

planes(){
planes() {
return this._runway;
};

clearForLanding(plane) {
if(this.isStormy()){
if (this._weather.isStormy()) {
throw new Error('Landing prohibited due to storm conditions');
};
if(this._runway.length == this.capacity){
throw new Error("Airport Full!");
};
if (this._runway.length == this.capacity) {
throw new Error("Airport Full!");
};
this._runway.push(plane);
};

clearForTakeoff(plane){
if(this.isStormy()){
clearForTakeoff(plane) {
if (this._weather.isStormy()) {
throw new Error('Takeoff prohibited due to storm conditions');
};
if(this._runway.length == 0){
if (this._runway.length == 0) {
throw new Error("Airport Empty!");
};

this._runway.pop(plane);
}
};
isStormy(){
return false;
}
};
};
18 changes: 9 additions & 9 deletions JavaScriptAirport/src/plane.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'
class Plane{
constructor(){
class Plane {
constructor() {
this._location;
};

land(airport){
airport.clearForLanding(this)
this._location = airport
};
land(airport) {
airport.clearForLanding(this)
this._location = airport
};

takeoff(airport){
this._location.clearForTakeoff()
};
takeoff(airport) {
this._location.clearForTakeoff()
};
};
9 changes: 9 additions & 0 deletions JavaScriptAirport/src/weather.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Weather {
constructor() {
this._CHANCE_OF_STORMY = 0.5;
};

isStormy() {
return (Math.random() > this._CHANCE_OF_STORMY);
}
};
73 changes: 10 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
Airport Challenge
=================

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

```
Instructions
---------
* Challenge time: rest of the day and weekend, until Monday 9am
* 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 9am Monday morning
Steps
-------
1. Fork this repo, and clone to your local machine
2. Run the command `gem install bundle` (if you don't have bundle 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
Expand Down Expand Up @@ -61,44 +29,23 @@ 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/master/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 weekend.
**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.** There are various checks that happen automatically when you send a pull request. **Fix these issues if you can**. Green is good.
* Finally, please submit a pull request before Monday at 9am 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 9am.
***Stories Completed(JavaScript)***
***Stories Completed(JavaScript challenge in JavaScriptAirport folder)***
User story 1 - User story 1 complete. I initially tried to create the function airport.land(plane) which seemed to be working until the point where I had to push the plane into the array, so I refactored my tests to follow the walkthrough more closely and have the land function in the Plane class.

User story 2 and 3 - User story 2 and 3 complete . I implemented the same method for takeoff as I did for landing in User story 1 but in the plane class included 'this_location' which was assigned to 'airport' I also added some more tests for an error to be raised when the airport was full and when it was empty.

User story 4 - capacity - had already begun this in user story 3 but refactored code and test to include DEFAULT_CAPACITY to get rid of the magic number.

User story 5 - User story 5 completed. To pass the test, I created a 'isStormy' function that returned false by default and created a guard clause within the 'clearForTakeoff' function that would through the error when isStormy was true. I also refactored my capacity test to have 'capacity' = 'DEFAULT_CAPACITY'.
User story 5 - User story 5 complete. To pass the test, I created a 'isStormy' function that returned false by default and created a guard clause within the 'clearForTakeoff' function that would through the error when isStormy was true. I also refactored my capacity test to have 'capacity' = 'DEFAULT_CAPACITY'.

User story 6 - User story 6 complete. I created a test similar to that in user story 5 but landing rather than takeoff and added a guard clause to the 'clearForLanding' function to make it pass.

Final refactoring -
I refactored my code and tests with help from the walkthrough to give the weather responsibilities to a weather class .


User story 6 - User story 6 completed. I created a test similar to that in user story 5 but landing rather than takeoff and added a guard clause to the 'clearForLanding' function to make it pass.
***Part 2: Learning a New Language***
I have included notes I made (and am still in the process of updating) during the week while learning JavaScript(they are also located in the JavaScriptAirport folder). In addition to practicing with the FizzBuzz and thermostat challenges, I also completed the JavaScript exercises on the W3 Schools website which helped me understand a lot of the syntax, and I am still working my way through Code Academy exercises.



Expand Down

0 comments on commit a735363

Please sign in to comment.