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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Airport Challenge
= ===(_________)

```
Sam Notes - Unfinished
---------
I ran out of time to finish the challenge but am also unsure of how/when to use or properly implement attr_readers & doubles.

I would have written an random number generator with multiple outcomes for different weather options in stormy? then linked this to takeoff and landing.

Instructions
---------
Expand Down
23 changes: 23 additions & 0 deletions docs/airport_challenge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Airport
attr_reader :plane

Choose a reason for hiding this comment

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

Do you need to expose the plane variable outside of this class?


def initialize(capacity)
@capacity = capacity

Choose a reason for hiding this comment

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

How would you implement a default capacity, in case the user didn't specify one? Maybe take a look at including a default argument: https://www.rubyguides.com/2018/06/rubys-method-arguments/

@planes = []
end

def land(plane)

Choose a reason for hiding this comment

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

Good, simple names. I feel like I overcomplicated mine with land_plane and release_plane.

raise 'Airport is full, cannot land plane' if capacity_full?
@planes << (plane)
end

def takeoff(plane)
raise 'cannot take off, weather is stormy' if stormy?

Choose a reason for hiding this comment

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

How can having a plane take off be reflected?

You're currently storing landed planes in @planes - they need to be decremented from this array once they take off, to show they're no longer in the airport.

Choose a reason for hiding this comment

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

In order for Weather's stormy? method to be called here, you could refactor your class with the following snippets (as an example):

def initialize(capacity, weather)
     @capacity = capacity
     @weather = weather
def

With the above, you would initialize a Weather instance with Weather.new, and pass that in as an argument when initialising Airport.new.

Then in your land/take_off methods, you could write:

raise 'cannot take off, weather is stormy' if @weather.stormy?

The last remaining step will be to refactor your Weather class itself - currently, the result will always be the same. Can you think of a way you might randomise the result, so that it's sometimes sunny and sometimes stormy?

end

def capacity_full?
max_capacity = 10
@planes.size >= max_capacity

Choose a reason for hiding this comment

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

Can't say without running it, but should this be @planes.size > max_capacity? I think this would make max_capacity 9

Choose a reason for hiding this comment

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

Additionally, you should use the capacity you passed in in the initialize method, stored in @capacity. Otherwise, it's a duplication of code, and max_capacity will remain static at 10 regardless of the user input.

end

end
5 changes: 5 additions & 0 deletions docs/plane.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Plane
def at_airport?
false
end

Choose a reason for hiding this comment

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

Unused methods should be removed before opening a PR.

end
5 changes: 5 additions & 0 deletions docs/weather.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Weather
def stormy?
true
end
end
35 changes: 35 additions & 0 deletions spec/airport_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require './docs/airport_challenge'
require './docs/weather'
require './docs/plane'

describe Airport do
it 'creates instance of airport' do
airport = Airport.new(10)
expect(airport).to be_kind_of(Airport)
end

# it 'allows plane to land' do
# airport = Airport.new
# expect(airport).to respond_to :land
# end
# not needed as it is fully covered by a future test

Choose a reason for hiding this comment

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

You can remove unneeded tests / commented out code / tests too.


it 'land takes 1 argument' do
airport = Airport.new(10)
expect(airport).to respond_to(:land).with(1).argument
end

it 'allows a plane to takeoff from airport' do
airport = Airport.new(10)
expect(airport).to respond_to(:takeoff).with(1).argument
end

it 'raises error when landing at full airport' do
airport = Airport.new(10)
plane = Plane.new
10.times do
airport.land(plane)
end
expect { airport.land(plane) }.to raise_error 'Airport is full, cannot land plane'
end
end
17 changes: 17 additions & 0 deletions spec/plane_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require './docs/airport_challenge'
require './docs/weather'
require './docs/plane'

describe Plane do
it 'creates instance of plane' do
plane = Plane.new
expect(plane).to be_kind_of(Plane)
end

it 'show that plane is no longer at airport' do
plane = Plane.new
plane.at_airport?
expect(plane.at_airport?).to be false
end

end
23 changes: 23 additions & 0 deletions spec/weather_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require './docs/airport_challenge'
require './docs/weather'
require './docs/plane'

describe Weather do
it 'creates instance of weather' do
weather = Weather.new
expect(weather).to be_kind_of(Weather)
end

it 'weather responds to stormy?' do
weather = Weather.new
expect(weather).to respond_to(:stormy?)
end

it 'is unable to takeoff if weather is stormy' do
weather = Weather.new
airport = Airport.new(10)
weather.stormy?
expect(airport.takeoff(@plane)).to raise_error 'cannot take off, weather is stormy'
#how to raise error if stormy? is true???
end
end