From 1e460ee56bfc1af9ccf81103274f4cfb262c1fd4 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:03:56 -0700 Subject: [PATCH 01/30] Got item_spec tests passing --- lib/item.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index e198fd3..2f60678 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,7 +1,7 @@ -class Items +class Item attr_reader :name def initialize(name) - @name = "Chalkware Piggy Bank" + @name = name end end \ No newline at end of file From 16bee99fb2971df1b66b8160981a43b7fe4c99c6 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:05:58 -0700 Subject: [PATCH 02/30] Correct auction to pass tests --- lib/auction.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/auction.rb b/lib/auction.rb index 4d53f20..f66f844 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -6,10 +6,12 @@ def initialize end def add_item(item) - @items.unshift(item) + @items << item end def item_names - raise NotImplementedError + @items.map do |item| + item.name + end end end \ No newline at end of file From e64a3ffac910a1e17e433f6fa990b92045001551 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:09:51 -0700 Subject: [PATCH 03/30] Correct attendee to pass tests --- lib/attendee.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/attendee.rb b/lib/attendee.rb index 690e5c9..9e556c2 100644 --- a/lib/attendee.rb +++ b/lib/attendee.rb @@ -3,6 +3,6 @@ class Attendee def initialize(info) @name = info[:name] - @budget = info[:budget] + @budget = info[:budget].split("$")[1].to_i end end \ No newline at end of file From 18d6f57b1549d8b45268ed2b22b6e25e3e653a9e Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:15:37 -0700 Subject: [PATCH 04/30] Add tests for item bids --- spec/item_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 4073cc4..add5b36 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -1,9 +1,13 @@ require './lib/item' +require './lib/attendee' RSpec.describe Item do before(:each) do @item1 = Item.new('Chalkware Piggy Bank') @item2 = Item.new('Bamboo Picture Frame') + + @attendee1 = Attendee.new({name: 'Megan', budget: '$50'}) + @attendee2 = Attendee.new({name: 'Bob', budget: '$75'}) end it 'exists' do @@ -14,4 +18,22 @@ expect(@item1.name).to eq("Chalkware Piggy Bank") expect(@item2.name).to eq("Bamboo Picture Frame") end + + it 'has a list of bids defaulted to an empty hash' do + expect(@item1.bids).to eq({}) + end + + it 'can be bid on' do + expect(@item1.bids).to eq({}) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + + expect(@item1.bids).to eq({ + @attendee2 => 20, + @attendee1 => 22 + }) + end + + end \ No newline at end of file From f6ce45db1b7f56f496afbf737268833a6309fc7a Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:17:25 -0700 Subject: [PATCH 05/30] Add test for current_high_bid --- spec/item_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index add5b36..3e50b4a 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -19,6 +19,8 @@ expect(@item2.name).to eq("Bamboo Picture Frame") end + # Iteration 2 + it 'has a list of bids defaulted to an empty hash' do expect(@item1.bids).to eq({}) end @@ -35,5 +37,7 @@ }) end - + it 'can determine the current highest bid' do + expect(@item1.current_high_bid).to eq(22) + end end \ No newline at end of file From 85ca5b2d2e57764c775496cc1f830b2160eacda1 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:18:56 -0700 Subject: [PATCH 06/30] Update before(:each) block --- spec/auction_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 31d12e0..1bd09c2 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -5,6 +5,13 @@ before(:each) do @item1 = Item.new('Chalkware Piggy Bank') @item2 = Item.new('Bamboo Picture Frame') + @item3 = Item.new('Homemade Chocolate Chip Cookies') + @item4 = Item.new('2 Days Dogsitting') + @item5 = Item.new('Forever Stamps') + + @attendee1 = Attendee.new({name: 'Megan', budget: '$50'}) + @attendee2 = Attendee.new({name: 'Bob', budget: '$75'}) + @attendee3 = Attendee.new({name: 'Mike', budget: '$100'}) @auction = Auction.new end From 6d3fe879224fe14ccf1e5d9c335285566cd1e988 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:25:31 -0700 Subject: [PATCH 07/30] Add test for unpopular_items --- spec/auction_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 1bd09c2..81795bb 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -36,4 +36,30 @@ expect(@auction.item_names).to eq(["Chalkware Piggy Bank", "Bamboo Picture Frame"]) end + + # Iteration 2 + + describe "iteration 2" do + before(:each) do + @auction.add_item(@item1) + @auction.add_item(@item2) + @auction.add_item(@item3) + @auction.add_item(@item4) + @auction.add_item(@item5) + end + + describe "#unpopular_items" do + it 'can return a list of unpopular items (no bids)' do + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item4.add_bid(@attendee3, 50) + + expect(@auction.unpopular_items).to eq([@item2, @item3, @item5]) + + @item3.add_bid(@attendee2, 15) + + expect(@auction.unpopular_items).to eq([@item2, @item5]) + end + end + end end \ No newline at end of file From 0c2ed6305f9d0cc98cae88bbf902052e23b9c2b9 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:27:51 -0700 Subject: [PATCH 08/30] Add test for potential revenue --- spec/auction_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 81795bb..6fc510d 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -61,5 +61,16 @@ expect(@auction.unpopular_items).to eq([@item2, @item5]) end end + + describe "#potential_revenue" do + it 'can calculate the auctions potential revenue' do + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) # Will only count highest bid + @item4.add_bid(@attendee3, 50) + @item3.add_bid(@attendee2, 15) + + expect(@auction.potential_revenue).to eq(87) + end + end end end \ No newline at end of file From c2a600495c22c1befa2fa929d58c19214ef75f73 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:30:57 -0700 Subject: [PATCH 09/30] Add add_bid method and bids instance variable --- lib/item.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/item.rb b/lib/item.rb index 2f60678..01aa164 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,7 +1,12 @@ class Item - attr_reader :name + attr_reader :name, :bids def initialize(name) @name = name + @bids = {} + end + + def add_bid(attendee, bid) + bids[attendee] = bid end end \ No newline at end of file From 72833f2cbea85ee590b75dd2a23338b08de4d9cf Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:32:50 -0700 Subject: [PATCH 10/30] Add missing method calls in current_high_bid test --- spec/item_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 3e50b4a..85222ca 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -38,6 +38,9 @@ end it 'can determine the current highest bid' do + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + expect(@item1.current_high_bid).to eq(22) end end \ No newline at end of file From d5e0f5960cb2cdfc1804fe9e86903dd6194e3045 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:33:49 -0700 Subject: [PATCH 11/30] Add current_high_bid method --- lib/item.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/item.rb b/lib/item.rb index 01aa164..e93dab0 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -9,4 +9,11 @@ def initialize(name) def add_bid(attendee, bid) bids[attendee] = bid end + + def current_high_bid + highest = @bids.max_by do |attendee, bid| + bid + end + highest[1] + end end \ No newline at end of file From 194874ba14dc0c4c78910c5d93b9e91f18a1e30b Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:36:16 -0700 Subject: [PATCH 12/30] Add missing require statement --- spec/auction_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 6fc510d..61da3e8 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -1,4 +1,5 @@ require './lib/item' +require './lib/attendee' require './lib/auction' RSpec.describe Auction do From 41f381e8bc8828748557dbeb6092ddc0a81ad35e Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:37:50 -0700 Subject: [PATCH 13/30] Add unpopular items method --- lib/auction.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index f66f844..cfbd6ec 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -14,4 +14,11 @@ def item_names item.name end end + + def unpopular_items + unpopular = @items.select do |item| + item.bids.empty? + end + unpopular + end end \ No newline at end of file From d3c7529005cae5858f1b1d46b9852a1181600300 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:46:08 -0700 Subject: [PATCH 14/30] Add potential_revenue method --- lib/auction.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index cfbd6ec..c6bc391 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -21,4 +21,14 @@ def unpopular_items end unpopular end + + def potential_revenue + revenue = 0 + @items.each do |item| + if !unpopular_items.include?(item) + revenue += item.current_high_bid + end + end + revenue + end end \ No newline at end of file From 9afff6ac3905e5cec4ab0f7cd4e98241b1c8bf9b Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 09:59:24 -0700 Subject: [PATCH 15/30] Add tests for close_bidding --- spec/item_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 85222ca..642fb6b 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -8,6 +8,7 @@ @attendee1 = Attendee.new({name: 'Megan', budget: '$50'}) @attendee2 = Attendee.new({name: 'Bob', budget: '$75'}) + @attendee3 = Attendee.new({name: 'Mike', budget: '$100'}) end it 'exists' do @@ -43,4 +44,26 @@ expect(@item1.current_high_bid).to eq(22) end + + describe "#close_bidding" do + before(:each) do + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + end + + it 'has a closed attribute defaulted to false' do + expect(@item1.closed).to be false + end + + it 'can close bidding' do + expect(@item1.close_bidding).to eq("Closed!") + expect(@item1.closed).to be true + end + + it 'can no longer accept new bids after closed' do + @item1.close_bidding + + expect(@item1.add_bid(@attendee3, 24)).to eq("Bidding Closed!") + end + end end \ No newline at end of file From 07e2b4b59eb1791c7f79660eef95589ebeac696d Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:02:05 -0700 Subject: [PATCH 16/30] Add close_bidding method and closed attribute --- lib/item.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/item.rb b/lib/item.rb index e93dab0..40494cb 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,9 +1,10 @@ class Item - attr_reader :name, :bids + attr_reader :name, :bids, :closed def initialize(name) @name = name @bids = {} + @closed = false end def add_bid(attendee, bid) @@ -16,4 +17,10 @@ def current_high_bid end highest[1] end + + def close_bidding + @closed = true + + "Closed!" + end end \ No newline at end of file From 20186551b2628b22df966dca6cd8d78e1050484e Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:03:46 -0700 Subject: [PATCH 17/30] Adjust add_bid method to only take bids when bidding is not closed --- lib/item.rb | 6 +++++- spec/item_spec.rb | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/item.rb b/lib/item.rb index 40494cb..faa62c3 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -8,7 +8,11 @@ def initialize(name) end def add_bid(attendee, bid) - bids[attendee] = bid + if @closed == false + bids[attendee] = bid + else + return "Bidding Closed!" + end end def current_high_bid diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 642fb6b..a4d6a47 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -45,6 +45,7 @@ expect(@item1.current_high_bid).to eq(22) end + # Iteration 3 describe "#close_bidding" do before(:each) do @item1.add_bid(@attendee2, 20) From e3b33353510cfa33a39ce61be91e4e85c96f192b Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:09:39 -0700 Subject: [PATCH 18/30] Add test for bidders --- spec/auction_spec.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 61da3e8..5ba2ead 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -40,7 +40,7 @@ # Iteration 2 - describe "iteration 2" do + describe "#unpopular/revenue" do before(:each) do @auction.add_item(@item1) @auction.add_item(@item2) @@ -74,4 +74,29 @@ end end end + + # Iteration 3 + describe "#bidders/bidder_info" do + before(:each) do + @auction.add_item(@item1) + @auction.add_item(@item2) + @auction.add_item(@item3) + @auction.add_item(@item4) + @auction.add_item(@item5) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item4.add_bid(@attendee3, 50) + @item3.add_bid(@attendee2, 15) + @item2.add_bid(@attendee1, 28) + end + + describe "#bidders" do + it 'can return an Array of bidders names' do + expect(@auction.bidders).to eq(["Megan", "Bob", "Mike"]) + end + end + + + end end \ No newline at end of file From 61baf4b95da0e8d8cfcef8b2db9112f280b4e3e4 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:16:39 -0700 Subject: [PATCH 19/30] Add test for bidder_info --- spec/auction_spec.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 5ba2ead..8c7f2e4 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -97,6 +97,23 @@ end end - + describe "#bidder_info" do + it 'can return a hash of bidders info' do + expect(@auction.bidder_info).to eq({ + @attendee1 => { + budget: 50, + items: [@item1, @item2] + }, + @attendee2 => { + budget: 75, + items: [@item1, @item3] + }, + @attendee3 => { + budget: 100, + items: [@item4] + } + }) + end + end end end \ No newline at end of file From 23a68fdbf596329808b6fc2f05f7869d4d4ba273 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:25:35 -0700 Subject: [PATCH 20/30] Add bidders method --- lib/auction.rb | 14 ++++++++++++++ spec/auction_spec.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/auction.rb b/lib/auction.rb index c6bc391..2b68453 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -31,4 +31,18 @@ def potential_revenue end revenue end + + def bidders + bidders = [] + @items.each do |item| + item_bidders = item.bids.keys + + item_bidders.each do |bidder| + if !bidders.include?(bidder.name) + bidders << bidder.name + end + end + end + bidders + end end \ No newline at end of file diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 8c7f2e4..e9303c4 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -93,7 +93,7 @@ describe "#bidders" do it 'can return an Array of bidders names' do - expect(@auction.bidders).to eq(["Megan", "Bob", "Mike"]) + expect(@auction.bidders).to eq(["Bob", "Megan", "Mike"]) end end From 35dca475939a4844ad65ca010d198acbad7f44bf Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:29:46 -0700 Subject: [PATCH 21/30] Add test for helper method list_bidder_objects --- spec/auction_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index e9303c4..14a8e6f 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -95,6 +95,12 @@ it 'can return an Array of bidders names' do expect(@auction.bidders).to eq(["Bob", "Megan", "Mike"]) end + + describe "#list_bidder_objects" do + it 'can return a list of attendee objects that bid' do + expect(@auction.list_bidder_objects).to eq(@attendee2, @attendee1, @attendee3) + end + end end describe "#bidder_info" do From e013c4eb4b4ed964b2437b9680978e99147489af Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:36:34 -0700 Subject: [PATCH 22/30] Add list_bidder_objects helper method and adjust bidders to use this helper method --- lib/auction.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/auction.rb b/lib/auction.rb index 2b68453..61bfa26 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -33,16 +33,27 @@ def potential_revenue end def bidders - bidders = [] + bidders = list_bidder_objects + + return bidder_names = bidders.map do |bidder| + bidder.name + end + end + + + # Helper Method that returns an array of the attendee objects that bid + def list_bidder_objects + bidder_objects = [] + @items.each do |item| item_bidders = item.bids.keys item_bidders.each do |bidder| - if !bidders.include?(bidder.name) - bidders << bidder.name + if !bidder_objects.include?(bidder) + bidder_objects << bidder end end end - bidders + bidder_objects end end \ No newline at end of file From 6c7a509c30c9e52af27e4458909beee68bf100a5 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 10:43:49 -0700 Subject: [PATCH 23/30] Add bidder_info method --- lib/auction.rb | 18 ++++++++++++++++++ spec/auction_spec.rb | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/auction.rb b/lib/auction.rb index 61bfa26..a882061 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -40,6 +40,24 @@ def bidders end end + def bidder_info + bidder_info = {} + bidder_objects = list_bidder_objects + + bidder_objects.each do |bidder| + @items.each do |item| + if item.bids.keys.include?(bidder) + if !bidder_info.keys.include?(bidder) + bidder_info[bidder] = {budget: bidder.budget, + items: [item]} + else + bidder_info[bidder][:items] << item + end + end + end + end + bidder_info + end # Helper Method that returns an array of the attendee objects that bid def list_bidder_objects diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 14a8e6f..1190a2e 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -98,7 +98,7 @@ describe "#list_bidder_objects" do it 'can return a list of attendee objects that bid' do - expect(@auction.list_bidder_objects).to eq(@attendee2, @attendee1, @attendee3) + expect(@auction.list_bidder_objects).to eq([@attendee2, @attendee1, @attendee3]) end end end From 6f6012e26c253c781218380d0b46f2ed4d946c8c Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:18:07 -0700 Subject: [PATCH 24/30] Add tests for close_auction --- spec/auction_spec.rb | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 1190a2e..65738a6 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -122,4 +122,71 @@ end end end + + # Iteration 4 + + # describe "#date" do + # it 'can return the date of the auction' do + # test_date = double("any date") + + # allow(test_date).to receive(:date).and_return("24/02/2020") + # expect(@auction.date).to eq("24/02/2020") + # end + # end + + describe "#close_auction" do + before(:each) do + @auction.add_item(@item1) + @auction.add_item(@item2) + @auction.add_item(@item3) + @auction.add_item(@item4) + @auction.add_item(@item5) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item4.add_bid(@attendee3, 50) + @item3.add_bid(@attendee2, 15) + @item2.add_bid(@attendee1, 28) + end + + it 'can close bidding on all items' do + @auction.close_auction + + expect(@item1.closed).to eq true + expect(@item2.closed).to eq true + expect(@item3.closed).to eq true + expect(@item4.closed).to eq true + expect(@item5.closed).to eq true + end + + it 'can return a hash of sold items' do + expect(@auction.close_auction).to eq({ + @item1 => @attendee1, + @item2 => @attendee1, + @item3 => @attendee2, + @item4 => @attendee3, + @item5 => 'Not Sold' + }) + end + + it 'can only sell items if an attendee can afford the bid' do + @item5.add_bid(@attendee1, 15) + + expect(@auction.close_auction).to eq({ + @item1 => @attendee1, + @item2 => @attendee1, + @item3 => @attendee2, + @item4 => @attendee3, + @item5 => 'Not Sold' + }) + end + + # helper method to determine if an attendee can afford the bid + describe "#can_afford" do + expect(@auction.can_afford(@item2, 28)).to be true + + @item5.add_bid(@attendee1, 15) + expect(@auction.can_afford(@item5, 15)).to be false + end + end end \ No newline at end of file From c06ad34a6f85688bd5e7402c03878766acdfc85c Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:21:02 -0700 Subject: [PATCH 25/30] Add forgotten it line --- spec/auction_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 65738a6..d917eaf 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -183,10 +183,12 @@ # helper method to determine if an attendee can afford the bid describe "#can_afford" do - expect(@auction.can_afford(@item2, 28)).to be true + it 'can determine if an attendee can afford a bid' do + expect(@auction.can_afford(@item2, 28)).to be true - @item5.add_bid(@attendee1, 15) - expect(@auction.can_afford(@item5, 15)).to be false + @item5.add_bid(@attendee1, 15) + expect(@auction.can_afford(@item5, 15)).to be false + end end end end \ No newline at end of file From e271ba82ff7dc85bb8d781cb2c132a83a07c249d Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:40:43 -0700 Subject: [PATCH 26/30] Add spend method test to handle changes in budget --- spec/attendee_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/attendee_spec.rb b/spec/attendee_spec.rb index 563506f..9e9e321 100644 --- a/spec/attendee_spec.rb +++ b/spec/attendee_spec.rb @@ -13,4 +13,9 @@ expect(@attendee.name).to eq('Megan') expect(@attendee.budget).to eq(50) end + + it 'can spend budget' do + @attendee.spend(22) + expect(@attendee.budget).to eq(28) + end end \ No newline at end of file From 932ad1a04d799369067c8dc0cbfd520071d5a8b1 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:54:21 -0700 Subject: [PATCH 27/30] Add spend method to handle budget changes --- lib/attendee.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/attendee.rb b/lib/attendee.rb index 9e556c2..4fbaf8b 100644 --- a/lib/attendee.rb +++ b/lib/attendee.rb @@ -5,4 +5,8 @@ def initialize(info) @name = info[:name] @budget = info[:budget].split("$")[1].to_i end + + def spend(cost) + @budget -= cost + end end \ No newline at end of file From bd23456b0a4063a3b330c58e0550993f0431df3b Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:54:50 -0700 Subject: [PATCH 28/30] adjust can_afford --- spec/auction_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index d917eaf..b95dd66 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -184,10 +184,11 @@ # helper method to determine if an attendee can afford the bid describe "#can_afford" do it 'can determine if an attendee can afford a bid' do - expect(@auction.can_afford(@item2, 28)).to be true + expect(@auction.can_afford(@attendee1, 22)).to be true + expect(@auction.can_afford(@attendee1, 28)).to be true @item5.add_bid(@attendee1, 15) - expect(@auction.can_afford(@item5, 15)).to be false + expect(@auction.can_afford(@attendee1, 15)).to be false end end end From 25795ae975a193c6db322feaac87bb89eac235a4 Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:55:20 -0700 Subject: [PATCH 29/30] Add can_afford helper method --- lib/auction.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index a882061..4e65499 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -1,3 +1,5 @@ +require 'date' + class Auction attr_reader :items @@ -59,6 +61,12 @@ def bidder_info bidder_info end + # def date + # Date.today.to_s + # end + + + # Helper Method that returns an array of the attendee objects that bid def list_bidder_objects bidder_objects = [] @@ -74,4 +82,14 @@ def list_bidder_objects end bidder_objects end + + def can_afford(bidder, bid) + if bidder.budget >= bid + bidder.spend(bid) + true + else + false + end + end + end \ No newline at end of file From d8fa74f71862560167406933403f5cfeea26be4e Mon Sep 17 00:00:00 2001 From: elysableu Date: Tue, 12 Nov 2024 11:55:52 -0700 Subject: [PATCH 30/30] Add close_auction method using can_afford helper method --- lib/auction.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/auction.rb b/lib/auction.rb index 4e65499..ad1ae3a 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -65,7 +65,25 @@ def bidder_info # Date.today.to_s # end - + def close_auction + sales = {} + @items.each do |item| + item.close_bidding # Close bidding on all items + + if item.bids.empty? + sales[item] = 'Not Sold' + else + item.bids.select do |bidder, bid| + if bid == item.current_high_bid && can_afford(bidder, bid) + sales[item] = bidder + else + sales[item] = 'Not Sold' + end + end + end + end + sales + end # Helper Method that returns an array of the attendee objects that bid def list_bidder_objects