forked from makersacademy/airport_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7d59d4
commit a735363
Showing
10 changed files
with
121 additions
and
151 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
}; |
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 |
---|---|---|
@@ -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() | ||
}; | ||
}; |
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,9 @@ | ||
class Weather { | ||
constructor() { | ||
this._CHANCE_OF_STORMY = 0.5; | ||
}; | ||
|
||
isStormy() { | ||
return (Math.random() > this._CHANCE_OF_STORMY); | ||
} | ||
}; |
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