From 3c1ee3a78e1498da653927e8443898281b2733d8 Mon Sep 17 00:00:00 2001 From: Kieran Carty Date: Mon, 25 Apr 2022 08:24:00 +0200 Subject: [PATCH] Kieran's Airport Challenge --- lib/airport.rb | 35 +++++++++++++++++++++++++++++++++++ lib/plane.rb | 3 +++ spec/airport_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/plane_spec.rb | 5 +++++ 4 files changed, 73 insertions(+) create mode 100644 lib/airport.rb create mode 100644 lib/plane.rb create mode 100644 spec/airport_spec.rb create mode 100644 spec/plane_spec.rb diff --git a/lib/airport.rb b/lib/airport.rb new file mode 100644 index 0000000000..d7df7bbd36 --- /dev/null +++ b/lib/airport.rb @@ -0,0 +1,35 @@ +require_relative 'plane' + +class Airport + def initialize + @plane_inventory = [] + @capacity = 10 + end + def land(plane) + fail "Airport at capacity" if @plane_inventory.length >= @capacity + @plane_inventory << plane + "#{plane} landed" + end + + def take_off(plane) + fail 'No planes on the ground' if @plane_inventory.empty? + @plane_inventory << plane + "#{plane} plane(s) taken off and no longer in the airport" + end + def plane_inventory + @plane_inventory.count + end + attr_reader :capacity +end + + + +# need another test to see if land_plane and take off correctly edit the plane inv log +# if @plane_inventory += planes <= @capacity +# else "UNSAFE TO LAND - Airport at capcity" +# if (@plane_inventory += planes) > 10 +# @plane_inventory = @capacity +# puts "UNSAFE TO LAND - Airport at capcity" +# end + +# plane = Plane.new \ No newline at end of file diff --git a/lib/plane.rb b/lib/plane.rb new file mode 100644 index 0000000000..51cae115aa --- /dev/null +++ b/lib/plane.rb @@ -0,0 +1,3 @@ +class Plane + +end \ No newline at end of file diff --git a/spec/airport_spec.rb b/spec/airport_spec.rb new file mode 100644 index 0000000000..2bdd3f0d67 --- /dev/null +++ b/spec/airport_spec.rb @@ -0,0 +1,30 @@ +require 'airport' +require 'plane' + +describe Airport do + + it { is_expected.to be_kind_of(Airport)} + it { is_expected.to respond_to(:land).with(1).argument} + it 'can land planes' do + airport = Airport.new + plane = Plane.new + expect(airport.land(plane)).to eq("#{plane} landed") + end + it { is_expected.to respond_to(:take_off).with(1).argument} + it 'can limit the number of planes that can land' do + airport = Airport.new + expect(airport.plane_inventory).to be <= airport.capacity + end + describe '#land' do + it 'raises an landing error when full' do + airport = Airport.new + plane = Plane.new + @plane_inventory = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 , 13, 14, 15, 16, 17, 18, 19, 20, 21] + expect {airport.land(plane)}.to raise_error "Airport at capacity" + end + end + it 'raises an take off error when empty' do + airport = Airport.new + expect {airport.take_off(Plane.new)}.to raise_error "No planes on the ground" + end +end \ No newline at end of file diff --git a/spec/plane_spec.rb b/spec/plane_spec.rb new file mode 100644 index 0000000000..bf71f9aa13 --- /dev/null +++ b/spec/plane_spec.rb @@ -0,0 +1,5 @@ +require 'plane' + +describe Plane do +it { is_expected.to be_kind_of(Plane)} +end \ No newline at end of file