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

Final Exam Part 2 Tests added and Small Function Changes #14

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3cc8f85
Nothing done yet, but have cloned the repo and am starting on the fin…
CoraBailey Mar 19, 2023
7fd6aaa
Have cloned the repo and am starting on the final project, removed th…
CoraBailey Mar 19, 2023
f748658
Got test for initialization with name and volume to pass
CoraBailey Mar 19, 2023
6fc5851
Completed test check for initially empty vessel
CoraBailey Mar 19, 2023
18c803f
Completed test to fill vessel with items
CoraBailey Mar 19, 2023
88d1c36
Added ability to add multiple items instead of only one, and can be o…
CoraBailey Mar 19, 2023
75a4faa
added tests for Item class to check whether new items have a name and…
CoraBailey Mar 19, 2023
7d02975
consolidated name and volume tests so there is only one test checking…
CoraBailey Mar 19, 2023
0be10b7
Finished basic tests for water_dispenser, checking it starts with no …
CoraBailey Mar 19, 2023
3d4873a
Checking that water_reservoir is empty on initialization
CoraBailey Mar 19, 2023
a1afd29
Test for fill function to fill water reservoir completely complete
CoraBailey Mar 19, 2023
bd39a3d
Completed fill/drain tests for water_reservoir
CoraBailey Mar 19, 2023
51acc9f
Completed tests for checking that it starts off, can be turned on, an…
CoraBailey Mar 19, 2023
70b86b9
Completed basic tests for freezer, including ability to add items to …
CoraBailey Mar 19, 2023
432e8a7
Completed chiller tests by modeling them after freezer_spec, they hav…
CoraBailey Mar 19, 2023
737a7b8
Completed tests to check total_capacity function returns query for co…
CoraBailey Mar 20, 2023
395d9d0
Completed tests to check freezer and chiller start off empty and are …
CoraBailey Mar 20, 2023
8c9de18
Completed tests for checking chiller and freezer turn on with refrige…
CoraBailey Mar 20, 2023
8805352
Completed the test opposite turning on freezer and chiller with fridg…
CoraBailey Mar 20, 2023
8ff1f51
Completed tests for to_s checking status is returned properly as a st…
CoraBailey Mar 20, 2023
5566861
Changed water_reservoir implementation so that it cannot go into the …
CoraBailey Mar 20, 2023
3064470
Completed test to ensure that the WaterReservoir may not go into the …
CoraBailey Mar 20, 2023
8c7e8ad
Completed function to fill reservoir based on the given volume within…
CoraBailey Mar 20, 2023
183d140
Added test to check that through the fill method, the reservoir canno…
CoraBailey Mar 20, 2023
227d235
Completed test, and added change to initialization for water_reservoi…
CoraBailey Mar 20, 2023
bb2b3ca
Fixed some problems with freeze and chill tests that I didn't notice
CoraBailey Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.5.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.0)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)

PLATFORMS
ruby

DEPENDENCIES
rspec

BUNDLED WITH
2.1.4
6 changes: 5 additions & 1 deletion lib/chiller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Chiller

ROOM_TEMPERATURE = 70

attr_reader :capacity, :temperature
attr_reader :capacity, :temperature, :power

def initialize(capacity = 100)
@capacity = capacity
Expand All @@ -11,6 +11,10 @@ def initialize(capacity = 100)
@contents = []
end

def empty?
@contents.empty?
end

def turn_on
@power = :on
end
Expand Down
6 changes: 5 additions & 1 deletion lib/freezer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Freezer

ROOM_TEMPERATURE = 70

attr_reader :capacity, :temperature
attr_reader :capacity, :temperature, :power

def initialize(capacity = 100)
@capacity = capacity
Expand All @@ -11,6 +11,10 @@ def initialize(capacity = 100)
@contents = []
end

def empty?
@contents.empty?
end

def turn_on
@power = :on
end
Expand Down
4 changes: 2 additions & 2 deletions lib/refrigerator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Refrigerator

attr_reader :chiller, :freezer, :control_panel, :water_dispenser, :water_reservoir
attr_reader :chiller, :freezer, :control_panel, :water_dispenser, :water_reservoir, :power

def initialize(chiller, freezer, water_dispenser, water_reservoir)
@chiller = chiller
Expand Down Expand Up @@ -52,7 +52,7 @@ def to_s
Power: #{@power}
Storage: #{remaining_capacity} of #{total_capacity} available
Temps: Chiller is #{chiller.temperature}, Freezer is #{freezer.temperature}
Water: Reservoir has #{water_reservoir.current_water_volume} remaining.
Water: Reservoir has #{water_reservoir.volume} remaining.
STATUS
end

Expand Down
11 changes: 10 additions & 1 deletion lib/vessel.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
class Vessel
attr_reader :volume
attr_reader :name, :volume

def initialize(name, volume)
@name = name
@volume = volume
@contents = []
end

def empty?
@contents.empty?
end

def fill(*item)
@contents << item
end

end
4 changes: 4 additions & 0 deletions lib/water_dispenser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def initialize(reservoir)
@reservoir = reservoir
end

def fill(vessel)
reservoir.fill(vessel.volume)
end

def dispense(vessel)
reservoir.drain(vessel.volume)
end
Expand Down
24 changes: 18 additions & 6 deletions lib/water_reservoir.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
class WaterReservoir

attr_reader :capacity
attr_accessor :current_water_volume
attr_accessor :volume

def initialize(capacity = 10, initial_water_volume = 0)
@capacity = capacity
@current_water_volume = initial_water_volume
if initial_water_volume > capacity
@volume = capacity
else
@volume = initial_water_volume
end
end

def empty?
current_water_volume == 0
@volume == 0
end

def fill
current_water_volume = capacity
def fill(volume)
if capacity < (@volume + volume)
@volume = capacity
else
@volume += volume
end
end

def drain(volume)
self.current_water_volume -= volume
if volume <= @volume
@volume -= volume.to_i
else
@volume = 0
end
end

end
29 changes: 29 additions & 0 deletions spec/chiller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,33 @@

describe 'A chiller' do

chiller = Chiller.new
it 'should start off' do
expect(chiller.power).to be :off
end

it 'should be turned on' do
chiller.turn_on
expect(chiller.power).to be :on
end

it 'should start empty' do
expect(chiller).to be_empty
end

it 'should be able to have items added to it' do
item = Item.new("pizza", 5)
chiller.add(item)
expect(chiller).to_not be_empty
end

it 'should be able to calculate the remaining capacity' do
expect(chiller.remaining_capacity).to eq(95)
end

it 'should be able to set the current temperature level' do
chiller.set_level(3)
expect(chiller.temperature).to eq(55)
end

end
30 changes: 30 additions & 0 deletions spec/freezer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,34 @@

describe 'A freezer' do

freezer = Freezer.new

it 'should start off' do
expect(freezer.power).to be :off
end

it 'should be turned on' do
freezer.turn_on
expect(freezer.power).to be :on
end

it 'should start empty' do
expect(freezer).to be_empty
end

it 'should be able to have items added to it' do
item = Item.new("pizza", 5)
freezer.add(item)
expect(freezer).to_not be_empty
end

it 'should be able to calculate the remaining capacity' do
expect(freezer.remaining_capacity).to eq(95)
end

it 'should be able to set the current temperature level' do
freezer.set_level(3)
expect(freezer.temperature).to eq(40)
end

end
6 changes: 6 additions & 0 deletions spec/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

describe 'An item of food or a beverage' do

it 'has a name and a volume' do
pizza = Item.new('pizza', 5)
expect(pizza.name).to eq('pizza')
expect(pizza.volume).to eq(5)
end

end
56 changes: 56 additions & 0 deletions spec/refrigerator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
require_relative '../lib/refrigerator'
require_relative '../lib/chiller'
require_relative '../lib/freezer'
require_relative '../lib/water_dispenser'
require_relative '../lib/water_reservoir'

describe 'A refrigerator' do

pizza = Item.new("pizza", 5)
dreamsicle = Item.new('Dreamsicle', 1)
chiller = Chiller.new
freezer = Freezer.new
water_reservoir = WaterReservoir.new
water_dispenser = WaterDispenser.new(water_reservoir)

refrigerator = Refrigerator.new(chiller, freezer, water_dispenser, water_reservoir)

it 'should return the correct status before changes to status when to_s is called' do
expect(refrigerator.to_s).to eq("Power: off\nStorage: 200 of 200 available\nTemps: Chiller is 70, Freezer is 70\nWater: Reservoir has 0 remaining.\n")
end

it 'has a chiller that starts empty' do
expect(refrigerator.chiller).to be_empty
end

it 'has a freezer that starts empty' do
expect(refrigerator.freezer).to be_empty
end

it 'adds item to chiller by chill function' do
refrigerator.chill(pizza)
expect(refrigerator.chiller).to_not be_empty
end

it 'adds item to freezer by freeze function' do
refrigerator.freeze(pizza)
expect(refrigerator.freezer).to_not be_empty
end

it 'total capacity includes both the freezers and the chillers capacity' do
expect(refrigerator.total_capacity).to eq(200)
end

it 'should power on both freezer and chiller when turned on' do
refrigerator.plug_in
expect(refrigerator.power).to be :on
expect(refrigerator.chiller.power).to be :on
expect(refrigerator.freezer.power).to be :on
end

it 'should power off both freezer and chiller when turned off' do
refrigerator.unplug
expect(refrigerator.power).to be :off
expect(refrigerator.chiller.power).to be :off
expect(refrigerator.freezer.power).to be :off
end

it 'should return the correct status after changes to status when to_s is called' do
expect(refrigerator.to_s).to eq("Power: off\nStorage: 190 of 200 available\nTemps: Chiller is 70, Freezer is 70\nWater: Reservoir has 0 remaining.\n")
end
end
5 changes: 2 additions & 3 deletions spec/vessel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
describe 'A vessel for holding liquid' do

it 'has a name and volume' do
vessel = Vessel.new
vessel = Vessel.new('FAKE', 100)
expect(vessel.name).to eq('FAKE')
expect(vessel.volume).to eq(100)
end

it 'is initially empty' do
skip
vessel = Vessel.new('FAKE', 100)
expect(vessel).to be_empty
end

it 'is no longer empty when we fill it' do
skip
vessel = Vessel.new('FAKE', 100)
vessel.fill
expect(vessel).to_not be_empty
end

end
18 changes: 18 additions & 0 deletions spec/water_dispenser_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
require_relative '../lib/water_dispenser'
require_relative '../lib/water_reservoir'

describe 'A water dispenser' do
water_reservoir = WaterReservoir.new
water_dispenser = WaterDispenser.new(water_reservoir)
vessel = Vessel.new("nalgene", 2)

it 'has a reservoir that starts with no water' do
expect(water_dispenser.reservoir.volume).to eq(0)
end

it 'has a reservoir that can be filled with water' do
water_dispenser.fill(vessel)
expect(water_dispenser.reservoir.volume).to be >= 0
end

it 'can drain its reservoir' do
water_dispenser.dispense(water_reservoir)
expect(water_dispenser.reservoir.volume).to eq(0)
end

end
38 changes: 38 additions & 0 deletions spec/water_reservoir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,42 @@

describe 'A water reservoir' do

water_reservoir = WaterReservoir.new

it 'should initialize with a volume at most the same value as capacity' do
wr = WaterReservoir.new(10, 20)
expect(wr.volume).to eq(10)
expect(wr.volume).to_not eq(20)
end

it 'should be empty when initialized' do
expect(water_reservoir).to be_empty
end

it 'can be fully filled' do
water_reservoir.fill(10)
expect(water_reservoir.volume).to eq(10)
end

it 'cannot be filled beyond full' do
water_reservoir.drain(water_reservoir.volume)
water_reservoir.fill(200)
expect(water_reservoir.volume).to_not eq(200)
expect(water_reservoir.volume).to eq(10)
end

it 'can be drained' do
water_reservoir.drain(water_reservoir.volume)
expect(water_reservoir.volume).to eq(0)
end

it 'can be drained but will never be negative' do
water_reservoir.fill(10)
water_reservoir.drain(5)
expect(water_reservoir.volume).to eq(5)
water_reservoir.drain(10)
expect(water_reservoir.volume).to_not eq(-5)
expect(water_reservoir.volume).to eq(0)
end

end