From 4d06b729feeec5148ce9faeaa8121f59e866e598 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:13:43 -0500 Subject: [PATCH 01/25] fix errors --- 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 1e67b43872588bfbdd97e6a6f227959f0d1d9675 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:13:48 -0500 Subject: [PATCH 02/25] fix errors --- lib/attendee.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/attendee.rb b/lib/attendee.rb index 690e5c9..fbeeef3 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].delete('$').to_i end end \ No newline at end of file From 5e98bd119b388d8c7029b6640f3dc444fd4ab37f Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:14:02 -0500 Subject: [PATCH 03/25] fix error; add #item_names --- lib/auction.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/auction.rb b/lib/auction.rb index 4d53f20..7859506 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -6,10 +6,16 @@ def initialize end def add_item(item) - @items.unshift(item) + @items << item end def item_names - raise NotImplementedError + names = [] + + @items.each do |item| + names << item.name + end + + names end end \ No newline at end of file From a7de91a82c0aab20b38468f256a8da247cbc7ad4 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:17:35 -0500 Subject: [PATCH 04/25] add assertions for new attribute --- spec/item_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 4073cc4..a42dfae 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -13,5 +13,7 @@ it 'has attributes' do expect(@item1.name).to eq("Chalkware Piggy Bank") expect(@item2.name).to eq("Bamboo Picture Frame") + expect(@item1.bids).to eq({}) + expect(@item2.bids).to eq({}) end end \ No newline at end of file From 77c8ba609fec689cf8359b5da83844873fa59eca Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:17:44 -0500 Subject: [PATCH 05/25] add new attribute #bids --- lib/item.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/item.rb b/lib/item.rb index 2f60678..f97c072 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,7 +1,8 @@ class Item - attr_reader :name + attr_reader :name, :bids def initialize(name) @name = name + @bids = {} end end \ No newline at end of file From a1cf04cb66d1fba2a47cb82411d29e60dff197f4 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:28:04 -0500 Subject: [PATCH 06/25] add test for #add_bid --- spec/item_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index a42dfae..f71ee44 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -4,6 +4,8 @@ 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 @@ -16,4 +18,15 @@ expect(@item1.bids).to eq({}) expect(@item2.bids).to eq({}) end + + describe '#add_bid' do + it 'adds a bid to an item from a specific person' 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 end \ No newline at end of file From 77b9242b7fb03ff219b7cd303e47a6139abf3fc5 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:28:15 -0500 Subject: [PATCH 07/25] write #add_bid --- lib/item.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/item.rb b/lib/item.rb index f97c072..fba0a5f 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -5,4 +5,8 @@ def initialize(name) @name = name @bids = {} end + + def add_bid(attendee, bid) + @bids[attendee] = bid + end end \ No newline at end of file From e2ef799f73f2aa762f62cbdff800a7af13d97eac Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:32:20 -0500 Subject: [PATCH 08/25] writes test for #current_high_bid --- spec/item_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index f71ee44..21f86f7 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -29,4 +29,13 @@ expect(@item1.bids).to eq({@attendee2=>20, @attendee1=>22}) end end + + describe '#current_high_bid' do + it 'returns the current highest bid for the item' do + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + + expect(@item1.current_high_bid).to eq(22) + end + end end \ No newline at end of file From 90f69091fff8b29ade4e98c3a75445f67d3fa4d8 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:32:35 -0500 Subject: [PATCH 09/25] write #current_high_bid method --- lib/item.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/item.rb b/lib/item.rb index fba0a5f..2174279 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -9,4 +9,10 @@ def initialize(name) def add_bid(attendee, bid) @bids[attendee] = bid end + + def current_high_bid + @bids.max_by do |attendee, bid| + bid + end[1] + end end \ No newline at end of file From a9514db1335cfd3a7ed3a429085c1f8be7f67487 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:40:08 -0500 Subject: [PATCH 10/25] add setup and write test for #unpopular_items --- spec/auction_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 31d12e0..0500e8e 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -5,7 +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') @auction = Auction.new + @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 @@ -29,4 +35,21 @@ expect(@auction.item_names).to eq(["Chalkware Piggy Bank", "Bamboo Picture Frame"]) end + + describe '#unpopular_items' do + it 'returns all items that have no bids' do + @auction.add_item(@item1) + @auction.add_item(@item2) + @auction.add_item(@item3) + @auction.add_item(@item4) + @auction.add_item(@item5) + expect(@auction.unpopular_items).to eq([@item1, @item2, @item3, @item4, @item5]) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item4.add_bid(@attendee3, 50) + + expect(@auction.unpopular_items).to eq([@item2, @item3, @item5]) + end + end end \ No newline at end of file From 8bdcb81f1fa63f490203bd554f42a4e6c29fd71e Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:40:22 -0500 Subject: [PATCH 11/25] write #unpopular_items method --- lib/auction.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/auction.rb b/lib/auction.rb index 7859506..51b37fd 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -11,11 +11,19 @@ def add_item(item) def item_names names = [] - @items.each do |item| names << item.name end - names end + + def unpopular_items + unpopular_items = [] + @items.each do |item| + if item.bids.empty? + unpopular_items << item + end + end + unpopular_items + end end \ No newline at end of file From 268a0c5dc423fe6f8a861537984a925f846b5f7b Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:46:00 -0500 Subject: [PATCH 12/25] write test for #potential_revenue method --- spec/auction_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 0500e8e..c4b995f 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -52,4 +52,19 @@ expect(@auction.unpopular_items).to eq([@item2, @item3, @item5]) end end + + describe '#potential_revenue' do + it 'returns the sum of each items highest bid' do + @auction.add_item(@item1) + @auction.add_item(@item3) + @auction.add_item(@item4) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item3.add_bid(@attendee2, 15) + @item4.add_bid(@attendee3, 50) + + expect(@auction.potential_revenue).to eq(87) + end + end end \ No newline at end of file From 2a5d1e119fea131888b2a1f1e4a9888ae891bc2f Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:46:14 -0500 Subject: [PATCH 13/25] write #potential_revenue method --- lib/auction.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index 51b37fd..b3c172b 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -26,4 +26,14 @@ def unpopular_items end unpopular_items end + + def potential_revenue + potential_revenue = 0 + @items.each do |item| + if item.current_high_bid != nil + potential_revenue += item.current_high_bid + end + end + potential_revenue + end end \ No newline at end of file From e6e85c6a2df33632ef53aefa1eff2d3f81d6f591 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:56:16 -0500 Subject: [PATCH 14/25] write test for #bidders method --- spec/auction_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index c4b995f..a98fc28 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -67,4 +67,19 @@ expect(@auction.potential_revenue).to eq(87) end end + + describe '#bidders' do + it 'returns an array of all the current bidders names' do + @auction.add_item(@item1) + @auction.add_item(@item3) + @auction.add_item(@item4) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item3.add_bid(@attendee2, 15) + @item4.add_bid(@attendee3, 50) + + expect(@auction.bidders).to contain_exactly('Megan', 'Bob', 'Mike') + end + end end \ No newline at end of file From 5dcd133da05416a428074149a5271b92be1e388e Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 11:56:25 -0500 Subject: [PATCH 15/25] write #bidders method --- lib/auction.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index b3c172b..d07043f 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -36,4 +36,18 @@ def potential_revenue end potential_revenue end + + def bidders + names = [] + @items.each do |item| + all_bidders_for_item = item.bids.keys + + all_bidders_for_item.each do |bidder| + if !names.include?(bidder.name) + names << bidder.name + end + end + end + names + end end \ No newline at end of file From 4731dc2e774f2fa34b7d7139873ee75c252ff37f Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:07:30 -0500 Subject: [PATCH 16/25] add test for #close_bidding --- spec/item_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/item_spec.rb b/spec/item_spec.rb index 21f86f7..a866ce3 100644 --- a/spec/item_spec.rb +++ b/spec/item_spec.rb @@ -17,6 +17,8 @@ expect(@item2.name).to eq("Bamboo Picture Frame") expect(@item1.bids).to eq({}) expect(@item2.bids).to eq({}) + expect(@item1.closed?).to be false + expect(@item2.closed?).to be false end describe '#add_bid' do @@ -38,4 +40,19 @@ expect(@item1.current_high_bid).to eq(22) end end + + describe '#close_bidding' do + it 'prevents future bids from being added once run' do + expect(@item1.closed?).to be false + + @item1.add_bid(@attendee2, 20) + expect(@item1.bids).to eq({@attendee2=>20}) + + @item1.close_bidding + expect(@item1.closed?).to be true + + @item1.add_bid(@attendee1, 22) + expect(@item1.bids).to eq({@attendee2=>20}) + end + end end \ No newline at end of file From e2eb80d80e1f74636fb46881022d868ee60be31b Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:07:49 -0500 Subject: [PATCH 17/25] write #close_bidding method; add logic to #add_bid --- lib/item.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/item.rb b/lib/item.rb index 2174279..74fa97a 100644 --- a/lib/item.rb +++ b/lib/item.rb @@ -1,13 +1,20 @@ class Item - attr_reader :name, :bids + attr_reader :name, :bids, :closed def initialize(name) @name = name @bids = {} + @closed = false + end + + def closed? + @closed end def add_bid(attendee, bid) - @bids[attendee] = bid + if @closed == false + @bids[attendee] = bid + end end def current_high_bid @@ -15,4 +22,8 @@ def current_high_bid bid end[1] end + + def close_bidding + @closed = true + end end \ No newline at end of file From cac140cf60695a687c2bbf631880cec4a5271842 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:32:43 -0500 Subject: [PATCH 18/25] write test for helper method #bidder_objects --- spec/auction_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index a98fc28..5252c58 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -82,4 +82,19 @@ expect(@auction.bidders).to contain_exactly('Megan', 'Bob', 'Mike') end end + + describe '#bidder_objects' do + it 'returns an array of all attendee objects that have a bid placed' do + @auction.add_item(@item1) + @auction.add_item(@item3) + @auction.add_item(@item4) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item3.add_bid(@attendee2, 15) + @item4.add_bid(@attendee3, 50) + + expect(@auction.bidder_objects).to contain_exactly(@attendee1, @attendee2, @attendee3) + end + end end \ No newline at end of file From 59fb2965870be4ff6a69494e0029dd16676c841d Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:33:02 -0500 Subject: [PATCH 19/25] write #bidder_objects helper method --- lib/auction.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index d07043f..ca36477 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -50,4 +50,18 @@ def bidders end names end + + def bidder_objects + bidder_objects = [] + @items.each do |item| + all_bidders_for_item = item.bids.keys + + all_bidders_for_item.each do |bidder| + if !bidder_objects.include?(bidder) + bidder_objects << bidder + end + end + end + bidder_objects + end end \ No newline at end of file From 77bf0bffbf9e53c1fc3ee766f57b0998a44da6c6 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:39:50 -0500 Subject: [PATCH 20/25] write test for #bidder_info --- spec/auction_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 5252c58..2f062ba 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -97,4 +97,35 @@ expect(@auction.bidder_objects).to contain_exactly(@attendee1, @attendee2, @attendee3) end end + + describe '#bidder_info' do + it 'returns a nested hash of bidder information' do + @auction.add_item(@item1) + @auction.add_item(@item3) + @auction.add_item(@item4) + + @item1.add_bid(@attendee2, 20) + @item1.add_bid(@attendee1, 22) + @item3.add_bid(@attendee2, 15) + @item4.add_bid(@attendee3, 50) + + bidder_info = @auction.bidder_info + + expect(bidder_info).to be_a(Hash) + bidder_info.each do |attendee, info| + expect(attendee).to be_a(Attendee) + expect(info).to be_a(Hash) + + expect(info.keys).to contain_exactly(:budget, :items) + expect(info[:budget]).to eq(attendee.budget) + expect(info[:items]).to be_an(Array) + + info[:items].each do |item| + bidders = item.keys + expect(item).to be_an(Item) + expect(bidders.includes?(attendee)).to be true + end + end + end + end end \ No newline at end of file From 8bd8170705a2064351c96e76f0f4dc97b2b77a3f Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 12:58:19 -0500 Subject: [PATCH 21/25] fix syntax error; swap useless logic to make test more robust --- 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 2f062ba..d6f95e6 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -121,9 +121,10 @@ expect(info[:items]).to be_an(Array) info[:items].each do |item| - bidders = item.keys expect(item).to be_an(Item) - expect(bidders.includes?(attendee)).to be true + bids = item.bids + bidders = bids.keys + expect(bidders.include?(attendee)).to be true end end end From 9091b2b838e8939672e432dfa6d074360d927665 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 13:00:07 -0500 Subject: [PATCH 22/25] write #bidder_info method --- lib/auction.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index ca36477..18f84c9 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -64,4 +64,30 @@ def bidder_objects end bidder_objects end + + # i left my notes here so you could see my process for creating this method. + # i wrote the notes as a guide, then the test, then came back and wrote the code + def bidder_info + #start with an empty hash + bidder_info = {} + + #get a list of all bidder objects + all_bidders = bidder_objects + + #enumerate though all_bidders + all_bidders.each do |bidder| + #get their budget + budget = bidder.budget + #get a list of items they have bid on + items = [] + @items.each do |item| + if item.bids.keys.include?(bidder) + items << item + end + end + #create and add key, value pair to initial hash + bidder_info[bidder] = {:budget => budget, :items => items} + end + bidder_info + end end \ No newline at end of file From 01223af406656c96ae0399a6b2b0e2db63cbd526 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 13:46:36 -0500 Subject: [PATCH 23/25] write stub for Date.today and add assertion for date attribute --- spec/auction_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index d6f95e6..93291f7 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -8,6 +8,7 @@ @item3 = Item.new('Homemade Chocolate Chip Cookies') @item4 = Item.new('2 Days Dogsitting') @item5 = Item.new('Forever Stamps') + allow(Date).to receive(:today).and_return(Date.new(2020, 02, 24)) @auction = Auction.new @attendee1 = Attendee.new({name: 'Megan', budget: '$50'}) @attendee2 = Attendee.new({name: 'Bob', budget: '$75'}) @@ -20,6 +21,7 @@ it 'has attributes' do expect(@auction.items).to eq([]) + expect(@auction.date).to eq('24/02/2024') end it 'add_item' do From 6b3613f9f0031887201b505ca50af79c5d9ddd5b Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 13:48:28 -0500 Subject: [PATCH 24/25] fix typo --- spec/auction_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/auction_spec.rb b/spec/auction_spec.rb index 93291f7..b76b97e 100644 --- a/spec/auction_spec.rb +++ b/spec/auction_spec.rb @@ -1,5 +1,6 @@ require './lib/item' require './lib/auction' +require 'date' RSpec.describe Auction do before(:each) do @@ -21,7 +22,7 @@ it 'has attributes' do expect(@auction.items).to eq([]) - expect(@auction.date).to eq('24/02/2024') + expect(@auction.date).to eq('24/02/2020') end it 'add_item' do From 3a5103e1662042c2ed63f3f0a8fd91d7233108c5 Mon Sep 17 00:00:00 2001 From: Dustin Peukert Date: Tue, 12 Nov 2024 13:48:47 -0500 Subject: [PATCH 25/25] add date attribute and write #date method --- lib/auction.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/auction.rb b/lib/auction.rb index 18f84c9..05b85e5 100644 --- a/lib/auction.rb +++ b/lib/auction.rb @@ -1,8 +1,15 @@ +require 'date' + class Auction attr_reader :items def initialize @items = [] + @date = Date.today + end + + def date + @date.strftime('%d/%m/%Y') end def add_item(item)