From 981e75d8cf2d9465e2d767cf80f46adcb18d3ae0 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 15:54:26 -0600 Subject: [PATCH 01/62] Initial commit --- lib/card.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/card.rb b/lib/card.rb index e69de29bb..9bedaf872 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -0,0 +1,19 @@ + +class Card + +end + +def question + +end + +def answer + +end + +def category + +end + +card_1 = Card.new(question, answer, category) + From 0b20b6a6a6337a62f8b75429f9edc487a79f669f Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 15:55:14 -0600 Subject: [PATCH 02/62] Initial commit --- lib/turn.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/turn.rb diff --git a/lib/turn.rb b/lib/turn.rb new file mode 100644 index 000000000..64fabe080 --- /dev/null +++ b/lib/turn.rb @@ -0,0 +1,19 @@ +class Turn + +end + +def guess + +end + +def correct? + +end + +def feedback + +end + +turn_1 = Turn.new(guess, card) + +#class objects can become the parameter for the next class instance \ No newline at end of file From 05bd52e5fa32c75ce9838d3c05edfcac61e4f807 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 15:57:35 -0600 Subject: [PATCH 03/62] Initial commit --- lib/deck.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/deck.rb diff --git a/lib/deck.rb b/lib/deck.rb new file mode 100644 index 000000000..e69de29bb From b7474bbfc77a2d90c9f367b4b165528d6b001cec Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 15:57:54 -0600 Subject: [PATCH 04/62] Initial commit --- lib/round.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 lib/round.rb diff --git a/lib/round.rb b/lib/round.rb new file mode 100644 index 000000000..e69de29bb From 8ecb4df74682158ac105af4640827c353edd853f Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 16:09:16 -0600 Subject: [PATCH 05/62] Initial commit --- spec/deck_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/deck_spec.rb diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb new file mode 100644 index 000000000..e69de29bb From ea6b5860845bb47ac71c5972d59a34b0c6266afd Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 16:09:31 -0600 Subject: [PATCH 06/62] Initial commit --- spec/round_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/round_spec.rb diff --git a/spec/round_spec.rb b/spec/round_spec.rb new file mode 100644 index 000000000..e69de29bb From 497788cdaea92d5b3825006fbb3c6630e56aa1fb Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 16:19:24 -0600 Subject: [PATCH 07/62] Initial commit --- spec/turn_spec.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/turn_spec.rb diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb new file mode 100644 index 000000000..e69de29bb From ba11aea70a6f1cd3932527bd9a167c4572f4b92d Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 16:30:38 -0600 Subject: [PATCH 08/62] initialize class to make it 'exists' do test pass git status exit cd .. cd clear git status --- lib/card.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/card.rb b/lib/card.rb index 9bedaf872..437505c03 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -1,6 +1,10 @@ class Card - + def initialize(question, answer, category) + @question = question + @answer = answer + @category = category + end end def question @@ -15,5 +19,5 @@ def category end -card_1 = Card.new(question, answer, category) +# card_1 = Card.new(question, answer, category) From 0751c5836bad0e8b9cb6aa43dc47b20e700de4c6 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 16:41:30 -0600 Subject: [PATCH 09/62] add attr_reader and modify code to make first 4 tests pass --- lib/card.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/card.rb b/lib/card.rb index 437505c03..142b66f70 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -1,23 +1,10 @@ class Card + attr_reader :question, :answer, :category + def initialize(question, answer, category) @question = question @answer = answer @category = category end -end - -def question - -end - -def answer - -end - -def category - -end - -# card_1 = Card.new(question, answer, category) - +end \ No newline at end of file From d245019141a960bfdc9ec217facdc4f2b32e4f5f Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 20:07:54 -0600 Subject: [PATCH 10/62] create initial rspec tests --- spec/turn_spec.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index e69de29bb..5c4033a03 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -0,0 +1,43 @@ +require './lib/turn' +require './lib/card' + +RSpec.describe Turn do + it 'exists' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Juneau", card) + + expect(turn).to be_instance_of(Turn) + expect(turn.card).to eq(card) + end + + xit 'returns a guess' do + turn = Turn.new("Juneau", card) + + expect(Turn.guess).to eq("Juneau") + end + + xit 'returns the Card' do + turn = Turn.new("Juneau", card) + + expect(Turn.card).to eq("What is the capital of Alaska?", "Juneau", :Geography) + + end + xit 'refers to the card object from the Card class' do + Turn.new("Juneau", card) + + expect(turn.answer).to eq(card) + end + + xit 'evaluates wheteher the answer is correct' do + card = Turn.new("Juneau", card) + + expect(turn.correct?).to eq() + end + + xit 'provides feedback' do + card = Turn.new("Juneau", card) + + expect(turn.feedback).to eq("Correct!") + end + +end From b88b2589ce0bf327c2232af54b8dc1999b7eda26 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 21:01:38 -0600 Subject: [PATCH 11/62] update rspec tests --- spec/turn_spec.rb | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index 5c4033a03..2cc5ad280 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -1,5 +1,5 @@ -require './lib/turn' require './lib/card' +require './lib/turn' RSpec.describe Turn do it 'exists' do @@ -10,32 +10,37 @@ expect(turn.card).to eq(card) end - xit 'returns a guess' do + it 'is Juneau by default' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) turn = Turn.new("Juneau", card) - expect(Turn.guess).to eq("Juneau") + expect(turn.guess).to eq("Juneau") end - xit 'returns the Card' do - turn = Turn.new("Juneau", card) - - expect(Turn.card).to eq("What is the capital of Alaska?", "Juneau", :Geography) + it "does not have to be Juneau" do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Spain", card) + expect(turn.guess).to eq("Spain") end - xit 'refers to the card object from the Card class' do - Turn.new("Juneau", card) - expect(turn.answer).to eq(card) - end + it 'returns the Card' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Juneau", card) - xit 'evaluates wheteher the answer is correct' do - card = Turn.new("Juneau", card) + expect(turn.card).to eq(card) + end + + it 'indicates if the guess matched the answer on the card' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Juneau", card) - expect(turn.correct?).to eq() + expect(turn.correct?).to eq(true) end - xit 'provides feedback' do - card = Turn.new("Juneau", card) + it 'provides feedback' do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Juneau", card) expect(turn.feedback).to eq("Correct!") end From c266b202cfd357e5a9fd22a51e302853f9c0764d Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 21:02:46 -0600 Subject: [PATCH 12/62] update code so all rspec tests pass --- lib/turn.rb | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index 64fabe080..ba0db4e32 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,19 +1,23 @@ -class Turn - -end - -def guess - -end - -def correct? +require './lib/card' -end - -def feedback - -end - -turn_1 = Turn.new(guess, card) - -#class objects can become the parameter for the next class instance \ No newline at end of file +class Turn + attr_reader :card, :guess + + def initialize(guess = "Juneau", card) + @guess = guess + @card = card + end + + def correct? + return true if guess == card.answer + false + end + + def feedback + if guess == card.answer + "Correct!" + else + "Incorrect." + end + end +end \ No newline at end of file From 39f0eb876134c9a23730229d9dd73cc7e39c91e2 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 21:14:05 -0600 Subject: [PATCH 13/62] update code to remove require --- spec/turn_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index 2cc5ad280..955109889 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -7,7 +7,6 @@ turn = Turn.new("Juneau", card) expect(turn).to be_instance_of(Turn) - expect(turn.card).to eq(card) end it 'is Juneau by default' do From aef0be935c6ae4d1c62fc8367d1841c9de75074f Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Wed, 21 Aug 2024 21:15:21 -0600 Subject: [PATCH 14/62] update code to remove require --- lib/turn.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index ba0db4e32..f8b547c41 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,5 +1,3 @@ -require './lib/card' - class Turn attr_reader :card, :guess From bcd78ca123159164ac97f18cb91684a905256658 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 06:24:06 -0600 Subject: [PATCH 15/62] add first passing test --- spec/deck_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index e69de29bb..b5e2402b2 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -0,0 +1,11 @@ +require './lib/card' +require './lib/deck' + +RSpec.describe Deck do + it 'exists' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + deck = Deck.new + + expect(card_1).to be_instance_of(Card) + end +end From 676ab50663d77f82b7565f5cd1a425aaf76350ce Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 06:24:41 -0600 Subject: [PATCH 16/62] initialize class --- lib/deck.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/deck.rb b/lib/deck.rb index e69de29bb..af1d3add6 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -0,0 +1,7 @@ +class Deck + attr_reader :cards + + def initialize + @cards = [] + end +end \ No newline at end of file From e04eb3ac1ddf984448809b7bb8c041742afe0bc5 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 12:09:53 -0600 Subject: [PATCH 17/62] initialize class --- lib/deck.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index af1d3add6..dc46220de 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -1,7 +1,17 @@ + +require 'card.rb' + class Deck attr_reader :cards - def initialize - @cards = [] + def initialize; end + + def cards + ObjectSpace.each_object(Card) .to_a end -end \ No newline at end of file +end + +card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) +card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) +card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) +deck = Deck.new(cards) From 8f48cbee6ee16805acae512ce9c0a579d672b25c Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 12:10:20 -0600 Subject: [PATCH 18/62] require card.rb --- lib/turn.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/turn.rb b/lib/turn.rb index f8b547c41..73b66fbd5 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,3 +1,5 @@ +require './card.rb' + class Turn attr_reader :card, :guess From 3d19645889197292edd373622434930e5e14995c Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 16:08:02 -0600 Subject: [PATCH 19/62] add cards variable to make first 2 tests pass --- spec/deck_spec.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index b5e2402b2..7f6f3b0e2 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -4,8 +4,34 @@ RSpec.describe Deck do it 'exists' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - deck = Deck.new + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new(cards) - expect(card_1).to be_instance_of(Card) + expect(deck).to be_instance_of(Deck) end + + it 'returns cards' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new(cards) + + expect(deck.cards).to eq(cards) + end + + it 'identifies_category' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new(cards) + category = card.category + + expect(deck.category).to eq(cards[n].category) + end + + end From 9e3bd066627dcca7cdb95a2d5fb2054943c708ce Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 16:17:17 -0600 Subject: [PATCH 20/62] simplified code --- lib/turn.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index 73b66fbd5..564c18839 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,9 +1,7 @@ -require './card.rb' - class Turn attr_reader :card, :guess - def initialize(guess = "Juneau", card) + def initialize(guess, card) @guess = guess @card = card end From 92b57a9e353fb74dca6c6eced4db0ea8cd16cd82 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 16:30:54 -0600 Subject: [PATCH 21/62] delete unnecessary code --- lib/deck.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index dc46220de..6de746cc7 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -1,17 +1,14 @@ -require 'card.rb' - class Deck attr_reader :cards - def initialize; end - - def cards - ObjectSpace.each_object(Card) .to_a + def initialize(cards) + @cards = cards end -end -card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) -card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) -card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) -deck = Deck.new(cards) + def identify_category(category) + @cards.select do |card| + card.category == category + end + end +end \ No newline at end of file From abee39bc48f9e84367d1af89db0d803935e018ae Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 20:17:05 -0600 Subject: [PATCH 22/62] modify code to make first 4 tests pass --- spec/deck_spec.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 7f6f3b0e2..25697f380 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -12,7 +12,7 @@ expect(deck).to be_instance_of(Deck) end - it 'returns cards' do + it 'returns_cards' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @@ -22,16 +22,24 @@ expect(deck.cards).to eq(cards) end - it 'identifies_category' do + it 'counts _cards' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) cards = [card_1, card_2, card_3] deck = Deck.new(cards) - category = card.category - expect(deck.category).to eq(cards[n].category) + expect(deck.count).to eq(3) end +# require 'pry';binding.pry + it 'identifies_category' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new(cards) + card = @cards - + expect(deck.cards_in_category(:STEM)).to eq([card_2, card_3]) + end end From 7eee7da709f5ed39847fa9b8a88f7286bb794693 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 20:17:39 -0600 Subject: [PATCH 23/62] add count and cards_in_category methods --- lib/deck.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index 6de746cc7..b92cde905 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -5,10 +5,14 @@ class Deck def initialize(cards) @cards = cards end +# require 'pry'; binding.pry + def count + @cards.length + end - def identify_category(category) + def cards_in_category(category) @cards.select do |card| - card.category == category + category == card.category end end end \ No newline at end of file From 2c9c837dcd40678e4f979956f6be1725b1a34062 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 21:57:06 -0600 Subject: [PATCH 24/62] add first two tests --- spec/round_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index e69de29bb..e627ba448 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -0,0 +1,39 @@ +require './lib/card' +require './lib/turn' +require './lib/deck' +require './lib/round' + +RSpec.describe Round do + xit 'exists' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + + expect(deck).to be_instance_of(Deck) + end + + xit 'returns_deck' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + + expect(round.deck).to eq(deck) + end + + it 'starts_turns' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + + expect(round.turns).to eq([]) + end +end \ No newline at end of file From 0fcf665a41bad0298d15fdc712fd2114f4d16240 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Thu, 22 Aug 2024 21:57:47 -0600 Subject: [PATCH 25/62] initialize class and define turns method --- lib/round.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/round.rb b/lib/round.rb index e69de29bb..215ee49a3 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -0,0 +1,11 @@ +class Round + attr_reader :deck + + def initialize(deck) + @deck = deck + end + + def turns + @deck = [] + end +end \ No newline at end of file From 731f95470c1548ae2e6cdd5c140c11c14162d106 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 16:39:30 -0600 Subject: [PATCH 26/62] add tests 3 and 4 --- spec/deck_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 25697f380..05a4f488a 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -31,7 +31,7 @@ expect(deck.count).to eq(3) end -# require 'pry';binding.pry + it 'identifies_category' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @@ -39,7 +39,7 @@ cards = [card_1, card_2, card_3] deck = Deck.new(cards) card = @cards - + expect(deck.cards_in_category(:STEM)).to eq([card_2, card_3]) end end From 756f2b6400f1742d9c4f3d130d0049c46526d4e4 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 16:39:30 -0600 Subject: [PATCH 27/62] accidental push - minor formatting changes --- spec/deck_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 25697f380..05a4f488a 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -31,7 +31,7 @@ expect(deck.count).to eq(3) end -# require 'pry';binding.pry + it 'identifies_category' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @@ -39,7 +39,7 @@ cards = [card_1, card_2, card_3] deck = Deck.new(cards) card = @cards - + expect(deck.cards_in_category(:STEM)).to eq([card_2, card_3]) end end From 0a6712ca5956894204560ea14477ca57f18c6d74 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 16:45:48 -0600 Subject: [PATCH 28/62] add passing currernt_card method --- lib/round.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 215ee49a3..32b1d2036 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,11 +1,30 @@ class Round - attr_reader :deck + attr_reader :deck, :cards def initialize(deck) @deck = deck + @cards = cards end def turns @deck = [] end -end \ No newline at end of file + + def current_card + @deck.cards[0] + end + + # while @deck.cards.empty? == false do + + # end +end + +# def take_turn(guess) +# new_turn = Tnrn.new(guess,@deck.cards[@turns.count]) +# @turns << new_turn +# new_turn +# end + +# turns.length = 0 (turns.length should go up one every turn) + + From ace5fdce4efe71270baf745903a0e507696747d2 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 16:55:41 -0600 Subject: [PATCH 29/62] add successful test 4 --- spec/round_spec.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index e627ba448..bb96574da 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -4,7 +4,7 @@ require './lib/round' RSpec.describe Round do - xit 'exists' do + it 'exists' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @@ -15,7 +15,7 @@ expect(deck).to be_instance_of(Deck) end - xit 'returns_deck' do + it 'returns_deck' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @@ -30,10 +30,26 @@ card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] + cards = @cards deck = Deck.new([card_1, card_2, card_3]) round = Round.new(deck) expect(round.turns).to eq([]) end + + it 'pulls_current_card' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) +# require 'pry'; binding.pry + expect(round.current_card).to eq(card_1) + end + + + +# new_turn = round.take_turn + end \ No newline at end of file From c9143af8bf1a2c67901b1f1d93e31120b52c9af8 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 21:42:38 -0600 Subject: [PATCH 30/62] add 3 new tests --- spec/round_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index bb96574da..1507431d8 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -48,6 +48,48 @@ expect(round.current_card).to eq(card_1) end + it 'takes_turns' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + turn = Turn.new("Juneau", @card) + + expect(round.take_turn("Juneau")).to eq(@turn << turn) + end + + xit 'says_if_correct' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + turn = Turn.new("Juneau", @card) + new_turn = @turn + round.deck + + round.take_turn("Juneau") == @turn +# require 'pry'; binding.pry + expect(new_turn.correct?).to eq(true) + end + + xit 'identifies_number_correct' do + card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + cards = [card_1, card_2, card_3] + deck = Deck.new([card_1, card_2, card_3]) + round = Round.new(deck) + turn = Turn.new("Juneau", @card) + current_card = @deck.cards[0] + + expect(round.number_correct).to eq(1) + + end + # new_turn = round.take_turn From 97346971b840f03066fbfadb6242c65205468996 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 21:44:26 -0600 Subject: [PATCH 31/62] modify take_turn method --- lib/round.rb | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 32b1d2036..125cbbabd 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,8 +1,11 @@ class Round - attr_reader :deck, :cards + attr_reader :deck, :cards, :card, :turn, :turns def initialize(deck) @deck = deck + @turn = turn + @turns = turns + @card = card @cards = cards end @@ -15,12 +18,42 @@ def current_card end # while @deck.cards.empty? == false do + # # end + + def count + + def take_turn(guess) + new_turn = Turn.new(guess, @deck.cards[@turns.count]) + @turns << new_turn + new_turn + end + + def correct? + new_turn = @turn + current_card = @deck.cards[0] + return true if new_turn[0] == current_card[1] + false + end end + # def number_correct + + # end + + # # def last + + # end + + # def feedback + + # end + + + # def take_turn(guess) -# new_turn = Tnrn.new(guess,@deck.cards[@turns.count]) +# new_turn = Turn.new(guess,@deck.cards[@turns.count]) # @turns << new_turn # new_turn # end @@ -28,3 +61,5 @@ def current_card # turns.length = 0 (turns.length should go up one every turn) +# turn should pull the card and return it to the end of the array + From 82affc8c0d4c33411cc63ed8b112159df09f44eb Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Fri, 23 Aug 2024 21:45:07 -0600 Subject: [PATCH 32/62] change category test name --- spec/deck_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 05a4f488a..d1fc3d3c4 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -32,7 +32,7 @@ expect(deck.count).to eq(3) end - it 'identifies_category' do + it 'cards_in_category' do card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) From 28fc424eabbd0262c7f893936078929b22ba4f12 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 10:32:53 -0600 Subject: [PATCH 33/62] modify take turn test according to interaction pattern --- spec/round_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 1507431d8..c54fc308e 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -52,12 +52,14 @@ card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] deck = Deck.new([card_1, card_2, card_3]) round = Round.new(deck) - turn = Turn.new("Juneau", @card) - - expect(round.take_turn("Juneau")).to eq(@turn << turn) + turn = Turn.new("Juneau", card_1) + turns = [] + user_guesses = [] + number_correct = 0 +require 'pry'; binding.pry + expect(round.take_turn("Juneau")).to eq(Turn.new("Juneau", card_1)) end xit 'says_if_correct' do @@ -68,7 +70,6 @@ deck = Deck.new([card_1, card_2, card_3]) round = Round.new(deck) turn = Turn.new("Juneau", @card) - new_turn = @turn round.deck round.take_turn("Juneau") == @turn From 6bfaced2f45425224eb6eaa4775ee0ad181bd227 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 10:33:26 -0600 Subject: [PATCH 34/62] modify take_turn method according to interaction pattern --- lib/round.rb | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 125cbbabd..644954895 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,40 +1,33 @@ +require 'turn.rb' + class Round - attr_reader :deck, :cards, :card, :turn, :turns + attr_reader :deck, :turns, :user_guesses, :number_correct def initialize(deck) @deck = deck - @turn = turn - @turns = turns - @card = card - @cards = cards + @turns = [] + @card_number = 0 + @number_correct = 0 + @user_guesses = [] end def turns - @deck = [] + @turns end - def current_card - @deck.cards[0] + def user_guesses + @user_guesses end - # while @deck.cards.empty? == false do - # - - # end - - def count + def current_card + @deck.cards[@card_number] + end def take_turn(guess) - new_turn = Turn.new(guess, @deck.cards[@turns.count]) - @turns << new_turn - new_turn - end - - def correct? - new_turn = @turn - current_card = @deck.cards[0] - return true if new_turn[0] == current_card[1] - false + return turns << guess = Turn.new(guess, current_card) + user_guesses << guess.correct? + @number_correct += 1 if guess.correct? + @card_number += 1 end end From 9f1b06b4ddee2037ebc95dae942af36b347b32b9 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 10:34:57 -0600 Subject: [PATCH 35/62] modify correct? and feedback code to account for case errors in user input --- lib/turn.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index 564c18839..1902d0a6a 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,12 +7,12 @@ def initialize(guess, card) end def correct? - return true if guess == card.answer + return true if guess.downcase == card.answer.downcase false end def feedback - if guess == card.answer + if guess.downcase == card.answer.downcase "Correct!" else "Incorrect." From 1fec09ad48c71f4b5c2054139564a3d92de876b2 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 14:55:00 -0600 Subject: [PATCH 36/62] add before(:each) do to streamline tests --- spec/round_spec.rb | 100 +++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 71 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index c54fc308e..172b4e9d9 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -4,95 +4,53 @@ require './lib/round' RSpec.describe Round do - it 'exists' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) - expect(deck).to be_instance_of(Deck) + before(:each) do + + @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + @cards = [@card_1, @card_2, @card_3] + @deck = Deck.new(@cards) + @turn = Turn.new("Juneau", @card_1) + @round = Round.new(@deck) + @turns = [] + @user_guesses = [] + @number_correct = 0 + end - it 'returns_deck' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) + it 'exists' do + expect(@round).to be_instance_of(Round) + end - expect(round.deck).to eq(deck) + it 'loads_deck_into_round' do + expect(@round.deck).to eq(@deck) end it 'starts_turns' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = @cards - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) - - expect(round.turns).to eq([]) + expect(@round.turns).to eq([]) end it 'pulls_current_card' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) -# require 'pry'; binding.pry - expect(round.current_card).to eq(card_1) + expect(@round.current_card).to eq(@card_1) + end + + it 'starts_with_empty_turns_array' do + expect(@round.turns).to eq([]) end it 'takes_turns' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) - turn = Turn.new("Juneau", card_1) - turns = [] - user_guesses = [] - number_correct = 0 -require 'pry'; binding.pry - expect(round.take_turn("Juneau")).to eq(Turn.new("Juneau", card_1)) + expect(@round.take_turn("Juneau")).to eq(@turn) end - xit 'says_if_correct' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) - turn = Turn.new("Juneau", @card) - round.deck + it 'says_if_correct' do + new_turn = Turn.new("Juneau", @card_1) - round.take_turn("Juneau") == @turn -# require 'pry'; binding.pry expect(new_turn.correct?).to eq(true) end - xit 'identifies_number_correct' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new([card_1, card_2, card_3]) - round = Round.new(deck) - turn = Turn.new("Juneau", @card) - current_card = @deck.cards[0] - - expect(round.number_correct).to eq(1) - + xit 'adds_to_number_correct' do + expect(@round.number_correct).to eq(1) end - - - -# new_turn = round.take_turn - end \ No newline at end of file From 25cdd1b5894cbf0c0058f01b8a7224f448d8ab5e Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 14:58:19 -0600 Subject: [PATCH 37/62] add before(:each) do to streamline tests --- spec/deck_spec.rb | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index d1fc3d3c4..b3580498d 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -2,44 +2,28 @@ require './lib/deck' RSpec.describe Deck do - it 'exists' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new(cards) - expect(deck).to be_instance_of(Deck) + before(:each) do + @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + @cards = [@card_1, @card_2, @card_3] + @deck = Deck.new(@cards) end - it 'returns_cards' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new(cards) + it 'exists' do + expect(@deck).to be_instance_of(Deck) + end - expect(deck.cards).to eq(cards) + it 'returns_cards' do + expect(@deck.cards).to eq(@cards) end it 'counts _cards' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new(cards) - - expect(deck.count).to eq(3) + expect(@deck.count).to eq(3) end it 'cards_in_category' do - card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - cards = [card_1, card_2, card_3] - deck = Deck.new(cards) - card = @cards - - expect(deck.cards_in_category(:STEM)).to eq([card_2, card_3]) + expect(@deck.cards_in_category(:STEM)).to eq([@card_2, @card_3]) end end From 2563d5b56946412a7f287fec8fffc7261fe6a4f0 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 18:14:25 -0600 Subject: [PATCH 38/62] modify correct? test to pass --- spec/round_spec.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 172b4e9d9..cc133ee1f 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -2,6 +2,7 @@ require './lib/turn' require './lib/deck' require './lib/round' +require 'pry' RSpec.describe Round do @@ -17,7 +18,8 @@ @turns = [] @user_guesses = [] @number_correct = 0 - + @card_number = 0 + end it 'exists' do @@ -50,7 +52,11 @@ expect(new_turn.correct?).to eq(true) end - xit 'adds_to_number_correct' do + it 'adds_to_number_correct' do + new_turn = Turn.new("Juneau", @card_1) + + # require 'pry'; binding.pry + expect(@round.number_correct).to eq(1) end end \ No newline at end of file From 1c8495537eb3cd6e4d1eef967d05ebd3d4a2f2a6 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 18:16:27 -0600 Subject: [PATCH 39/62] add potential test to add cards to deck --- spec/deck_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index b3580498d..20c3d7d55 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -19,10 +19,16 @@ expect(@deck.cards).to eq(@cards) end - it 'counts _cards' do + it 'counts_cards' do expect(@deck.count).to eq(3) end + # it 'can_add_cards' do + # card_4 = Card.new("What is Danielle's cat's name", "Furriosa", :Turing_students) + + # expect(@deck.add_card(card_4)). to eq([@card_1, @card_2, @card_3, card_4]) + # end + it 'cards_in_category' do expect(@deck.cards_in_category(:STEM)).to eq([@card_2, @card_3]) end From 7a9a9d46953e8f8c92f85f5a98a218113b0db321 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 18:17:12 -0600 Subject: [PATCH 40/62] modify take_turn method to pass tests --- lib/round.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 644954895..0aa96d844 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,7 +1,7 @@ require 'turn.rb' class Round - attr_reader :deck, :turns, :user_guesses, :number_correct + attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number def initialize(deck) @deck = deck @@ -24,10 +24,12 @@ def current_card end def take_turn(guess) - return turns << guess = Turn.new(guess, current_card) - user_guesses << guess.correct? - @number_correct += 1 if guess.correct? + new_turn = Turn.new(guess, current_card) + @turns << new_turn + @user_guesses << new_turn.correct? + @number_correct += 1 if new_turn.correct? @card_number += 1 + new_turn end end From 500feb0e7193c601a6679ce3532a4165b5866499 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 18:18:19 -0600 Subject: [PATCH 41/62] add == method to resolve testing issue --- lib/turn.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index 1902d0a6a..d32870262 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -7,15 +7,19 @@ def initialize(guess, card) end def correct? - return true if guess.downcase == card.answer.downcase + return true if @guess.downcase == @card.answer.downcase false end def feedback - if guess.downcase == card.answer.downcase + if @guess.downcase == @card.answer.downcase "Correct!" else "Incorrect." end end + + def ==(other_turn) + self.guess == other_turn.guess && self.card == other_turn.card + end end \ No newline at end of file From 43f2bf974ba9898f1458a243bbef3deac27a5bc1 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 21:27:27 -0600 Subject: [PATCH 42/62] add require relative to pull in card.rb for add card method --- lib/deck.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/deck.rb b/lib/deck.rb index b92cde905..715ab9593 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -1,9 +1,11 @@ +# require_relative './card.rb' (may need to add to make method to add cards work) class Deck attr_reader :cards def initialize(cards) @cards = cards + end # require 'pry'; binding.pry def count @@ -15,4 +17,9 @@ def cards_in_category(category) category == card.category end end + + # def add_card(new_card) + # @cards.push(Card.new(question, answer, category)) + # end + end \ No newline at end of file From af236067169f84cada321c02f398702b4f74da41 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 21:27:49 -0600 Subject: [PATCH 43/62] Initial commit --- lib/flashcard_runner.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/flashcard_runner.rb diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb new file mode 100644 index 000000000..62b9e4532 --- /dev/null +++ b/lib/flashcard_runner.rb @@ -0,0 +1,35 @@ +require_relative './card.rb' +require_relative './turn.rb' +require_relative './round.rb' +require_relative './deck.rb' + +class Game + def initialize_game + @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) + @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) + @deck = Deck.new(@cards) + @turn = Turn.new("Juneau", @card_1) + @round = Round.new(@deck) + end + + def welcome + "Welcome! You're playing with #{@cards.length} cards." + puts @round.welcome + end + + def play_game + + end +end + + +# @cards = [@card_1, @card_2, @card_3] +# @turns = [] +# @user_guesses = [] +# @number_correct = 0 +# @card_number = 0 + +# puts "---------------------------------------------------------------" +# puts "This is card number #{@card.number} out of #{@cards.length} cards." + From 172104fe6f54af127df1caef0c6bb44df5daa999 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 21:28:24 -0600 Subject: [PATCH 44/62] add require relative and number correct by category method --- lib/round.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 0aa96d844..0e8d5791a 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -1,4 +1,5 @@ -require 'turn.rb' +require_relative './turn.rb' +require_relative './card.rb' class Round attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number @@ -25,14 +26,17 @@ def current_card def take_turn(guess) new_turn = Turn.new(guess, current_card) - @turns << new_turn - @user_guesses << new_turn.correct? + @turns << new_turn + @user_guesses << new_turn.correct? #returns true/false boolean @number_correct += 1 if new_turn.correct? @card_number += 1 new_turn end -end + def number_correct_by_category(category) + @deck.current_card.category + end +end # def number_correct # end From c896643a7a8f47445013bd02606bd317c78cfa2f Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sat, 24 Aug 2024 21:28:51 -0600 Subject: [PATCH 45/62] add number correct by category test --- spec/round_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index cc133ee1f..5810bb630 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -12,6 +12,7 @@ @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @cards = [@card_1, @card_2, @card_3] + turn = Turn.new("Juneau", @card_1) @deck = Deck.new(@cards) @turn = Turn.new("Juneau", @card_1) @round = Round.new(@deck) @@ -59,4 +60,10 @@ expect(@round.number_correct).to eq(1) end + + xit 'identifies_number_correct_by_category' do + new_turn = Turn.new("Venus", @card_2) + + expect(@round.number_correct_by_category(:Geography).to eq(1)) + end end \ No newline at end of file From e38c0f29074da2bee97faaf13411c13c519fae47 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sun, 25 Aug 2024 12:16:39 -0600 Subject: [PATCH 46/62] delete unnecessary instance variables --- spec/round_spec.rb | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 5810bb630..044b7a940 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -12,15 +12,10 @@ @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @cards = [@card_1, @card_2, @card_3] - turn = Turn.new("Juneau", @card_1) @deck = Deck.new(@cards) @turn = Turn.new("Juneau", @card_1) @round = Round.new(@deck) - @turns = [] - @user_guesses = [] - @number_correct = 0 - @card_number = 0 - + end it 'exists' do @@ -44,26 +39,13 @@ end it 'takes_turns' do - expect(@round.take_turn("Juneau")).to eq(@turn) - end - - it 'says_if_correct' do new_turn = Turn.new("Juneau", @card_1) + expect(@round.take_turn("Juneau")).to eq(@turn) expect(new_turn.correct?).to eq(true) - end - - it 'adds_to_number_correct' do - new_turn = Turn.new("Juneau", @card_1) - - # require 'pry'; binding.pry - expect(@round.number_correct).to eq(1) - end - - xit 'identifies_number_correct_by_category' do - new_turn = Turn.new("Venus", @card_2) - - expect(@round.number_correct_by_category(:Geography).to eq(1)) + expect(@round.number_correct_by_category(:Geography)).to eq(1) + expect(@round.percent_correct).to eq(100) + expect(@round.percent_correct_by_category(:Geography)).to eq(50) end end \ No newline at end of file From 4dda6f88a538b9ec46854ba6cba770b98731e83d Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sun, 25 Aug 2024 12:18:06 -0600 Subject: [PATCH 47/62] delete unnecessary game class and add start method --- lib/flashcard_runner.rb | 57 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index 62b9e4532..f4fe85699 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -3,26 +3,47 @@ require_relative './round.rb' require_relative './deck.rb' -class Game - def initialize_game - @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) - @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) - @deck = Deck.new(@cards) - @turn = Turn.new("Juneau", @card_1) - @round = Round.new(@deck) - end - - def welcome - "Welcome! You're playing with #{@cards.length} cards." - puts @round.welcome - end - - def play_game - - end + +@card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) +@card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) +@card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) +@cards = [@card_1, @card_2, @card_3] +@deck = Deck.new(@cards) +@round = Round.new(@deck) + + +def start + puts "Welcome! You're playing with #{@cards.length} cards." + puts "----------------------------------------------------------" + puts "This is card number #{@round.card_number} out of #{@cards.length}." + puts "Question: #{@round.current_card.question}" + user_input = gets.chomp + puts user_input end +# gets.chomp + +start +# class Game +# def initialize_game +# @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) +# @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) +# @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) +# @deck = Deck.new(@cards) +# @turn = Turn.new("Juneau", @card_1) +# @round = Round.new(@deck) +# end + +# def welcome +# +# puts @round.welcome +# end + +# def play_game + +# end +# end + # @cards = [@card_1, @card_2, @card_3] # @turns = [] From 2f9711b94025a7dbc02390b043066591456216de Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Sun, 25 Aug 2024 12:19:42 -0600 Subject: [PATCH 48/62] add number and percent correct by category methods --- lib/round.rb | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 0e8d5791a..5087525aa 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -2,14 +2,18 @@ require_relative './card.rb' class Round - attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number + attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category def initialize(deck) @deck = deck @turns = [] @card_number = 0 @number_correct = 0 + @number_correct_by_category = 0 @user_guesses = [] + @current_card = current_card + @percent_correct = 0 + @percent_correct_by_category = 0 end def turns @@ -21,7 +25,15 @@ def user_guesses end def current_card - @deck.cards[@card_number] + @current_card = @deck.cards[@card_number] + end + + def number_correct_by_category(category) + @number_correct_by_category + end + + def percent_correct_by_category(category) + @percent_correct_by_category end def take_turn(guess) @@ -29,36 +41,10 @@ def take_turn(guess) @turns << new_turn @user_guesses << new_turn.correct? #returns true/false boolean @number_correct += 1 if new_turn.correct? + @number_correct_by_category += 1 if new_turn.correct? @card_number += 1 + @percent_correct = ((@number_correct.to_f / @turns.length) * 100).round(2) + @percent_correct_by_category = ((@number_correct_by_category.to_f / deck.cards.length) * 100).round(2) new_turn end - - def number_correct_by_category(category) - @deck.current_card.category - end -end - # def number_correct - - # end - - # # def last - - # end - - # def feedback - - # end - - - -# def take_turn(guess) -# new_turn = Turn.new(guess,@deck.cards[@turns.count]) -# @turns << new_turn -# new_turn -# end - -# turns.length = 0 (turns.length should go up one every turn) - - -# turn should pull the card and return it to the end of the array - +end \ No newline at end of file From a53376987ed49c074c74f4a33049db39d0c3271a Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:17:07 -0600 Subject: [PATCH 49/62] fix bugs in take turn method --- spec/round_spec.rb | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index 044b7a940..b76dd4fb9 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -13,7 +13,6 @@ @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) @cards = [@card_1, @card_2, @card_3] @deck = Deck.new(@cards) - @turn = Turn.new("Juneau", @card_1) @round = Round.new(@deck) end @@ -38,14 +37,36 @@ expect(@round.turns).to eq([]) end - it 'takes_turns' do - new_turn = Turn.new("Juneau", @card_1) + it 'logs the new turn into the turns array' do + new_turn = @round.take_turn("Juneau") + + expect(@round.turns.last).to eq(new_turn) +# require 'pry'; binding.pry + end + + it 'add to number correct' do + new_turn = @round.take_turn("Juneau") - expect(@round.take_turn("Juneau")).to eq(@turn) - expect(new_turn.correct?).to eq(true) expect(@round.number_correct).to eq(1) - expect(@round.number_correct_by_category(:Geography)).to eq(1) - expect(@round.percent_correct).to eq(100) - expect(@round.percent_correct_by_category(:Geography)).to eq(50) end + + it 'identifies percent correct' do + new_turn = @round.take_turn("Juneau") + + expect(@round.percent_correct).to eq(100) + end + + it 'identifies number correct by category' do + new_turn = @round.take_turn("Juneau") + + expect(@round.number_correct_by_category(:Geography)).to eq(1) + end + + # 'adds to number correct by category' do + # expect(@round.number_correct_by_category(:Geography)).to eq(1) + + # expect(@round.percent_correct_by_category(:Geography)).to eq(100) + + # end + end \ No newline at end of file From 6a1bb364f085ba434117c57950630610e1b35215 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:18:42 -0600 Subject: [PATCH 50/62] fix method order in take turn method --- lib/round.rb | 59 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index 5087525aa..b655a6718 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -2,49 +2,62 @@ require_relative './card.rb' class Round - attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category + attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number + attr_writer :turns def initialize(deck) @deck = deck @turns = [] @card_number = 0 + @turn_number = 1 @number_correct = 0 @number_correct_by_category = 0 @user_guesses = [] @current_card = current_card - @percent_correct = 0 + @percent_correct = 0.0 @percent_correct_by_category = 0 + end - def turns - @turns + def current_card + @current_card = @deck.cards[@card_number] end - def user_guesses - @user_guesses + def take_turn(guess) + new_turn = Turn.new(guess, current_card) #@current_card) #need to try to find a way for new_turn to pull in guess and card + @turns. << new_turn + user_guesses << new_turn.correct? #returns true/false boolean + @number_correct += 1 if new_turn.correct? + # require 'pry'; binding.pry + @card_number += 1 + @turn_number += 1 + new_turn end - def current_card - @current_card = @deck.cards[@card_number] + def percent_correct + @percent_correct = ((@number_correct.to_f / @turns.length) * 100).round(2) end - + def number_correct_by_category(category) - @number_correct_by_category + @number_correct.cards.category + # category = @current_card.category + # @number_correct_by_category = end - def percent_correct_by_category(category) + def percent_correct_by_category(category) #needed a method here because I couldn't include the parameter in the instance variable @percent_correct_by_category end +end - def take_turn(guess) - new_turn = Turn.new(guess, current_card) - @turns << new_turn - @user_guesses << new_turn.correct? #returns true/false boolean - @number_correct += 1 if new_turn.correct? - @number_correct_by_category += 1 if new_turn.correct? - @card_number += 1 - @percent_correct = ((@number_correct.to_f / @turns.length) * 100).round(2) - @percent_correct_by_category = ((@number_correct_by_category.to_f / deck.cards.length) * 100).round(2) - new_turn - end -end \ No newline at end of file + # def number_correct_by_category + # if new_turn.correct? do + + # end + # correct_by_category = + # += 1 if new_turn.correct? + # end + + + # def percent_correct_by_category + # @percent_correct_by_category = ((@number_correct_by_category.count.to_f / @turns.length) * 100).round(2) + # end From dc3825685f18f3f3029f1aae14e8451f1ea88aac Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:19:42 -0600 Subject: [PATCH 51/62] fix bugs in correct? and feedback methods --- lib/turn.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index d32870262..2d1add9d2 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,5 +1,6 @@ class Turn attr_reader :card, :guess + attr_writer :card, :guess def initialize(guess, card) @guess = guess @@ -7,19 +8,15 @@ def initialize(guess, card) end def correct? - return true if @guess.downcase == @card.answer.downcase + return true if card.answer.downcase == guess.downcase false end def feedback - if @guess.downcase == @card.answer.downcase + if card.answer.downcase == guess.downcase "Correct!" else "Incorrect." end end - - def ==(other_turn) - self.guess == other_turn.guess && self.card == other_turn.card - end end \ No newline at end of file From 0532586574f7ca7ac695d934857acc942e3f8898 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:37:44 -0600 Subject: [PATCH 52/62] add new turn method and game play enumerable --- lib/flashcard_runner.rb | 62 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index f4fe85699..ab2b90acc 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -7,50 +7,30 @@ @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) +# @card = Card.new(@question, @answer, @category) @cards = [@card_1, @card_2, @card_3] @deck = Deck.new(@cards) +@turn = Turn.new(@guess, @card) @round = Round.new(@deck) - -def start - puts "Welcome! You're playing with #{@cards.length} cards." - puts "----------------------------------------------------------" - puts "This is card number #{@round.card_number} out of #{@cards.length}." - puts "Question: #{@round.current_card.question}" - user_input = gets.chomp - puts user_input +# require 'pry'; binding.pry +def start + @round.deck + @round.turns + puts "Welcome! You're playing with #{@cards.length} cards." + puts "----------------------------------------------------------" + @round.deck.cards.length.times do + puts "This is card number #{@round.turn_number} out of #{@cards.length}." + puts "Question: #{@round.current_card.question}" + user_input = gets.chomp + new_turn = @round.take_turn(user_input) + # require 'pry'; binding.pry + puts new_turn.feedback + end + puts "****** Game over! ******" + require 'pry'; binding.pry + puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}." + puts end -# gets.chomp - -start -# class Game -# def initialize_game -# @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) -# @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) -# @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) -# @deck = Deck.new(@cards) -# @turn = Turn.new("Juneau", @card_1) -# @round = Round.new(@deck) -# end - -# def welcome -# -# puts @round.welcome -# end - -# def play_game - -# end -# end - - -# @cards = [@card_1, @card_2, @card_3] -# @turns = [] -# @user_guesses = [] -# @number_correct = 0 -# @card_number = 0 - -# puts "---------------------------------------------------------------" -# puts "This is card number #{@card.number} out of #{@cards.length} cards." - +start \ No newline at end of file From a139e1ab42a19619cb513f53fa1418ea336f2e82 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:38:23 -0600 Subject: [PATCH 53/62] fix bug in add new card feature --- lib/deck.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index 715ab9593..8d94a602f 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -1,11 +1,11 @@ # require_relative './card.rb' (may need to add to make method to add cards work) class Deck - attr_reader :cards + attr_reader :card, :cards + attr_writer :cards def initialize(cards) @cards = cards - end # require 'pry'; binding.pry def count @@ -18,8 +18,8 @@ def cards_in_category(category) end end - # def add_card(new_card) - # @cards.push(Card.new(question, answer, category)) - # end + def add_card(new_card) + @cards << new_card + end end \ No newline at end of file From 9bc87c4fc10bab30a38e6980796a40c7f71cd3af Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:39:40 -0600 Subject: [PATCH 54/62] add before each method --- spec/card_spec.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/spec/card_spec.rb b/spec/card_spec.rb index 84a45a7a6..58c054e7e 100644 --- a/spec/card_spec.rb +++ b/spec/card_spec.rb @@ -1,27 +1,24 @@ require './lib/card' RSpec.describe Card do - it 'exists' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - expect(card).to be_instance_of(Card) + before(:each) do + @card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) end - it 'has a question' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + it 'exists' do + expect(@card).to be_instance_of(Card) + end - expect(card.question).to eq("What is the capital of Alaska?") + it 'has a question' do + expect(@card.question).to eq("What is the capital of Alaska?") end it 'has an answer' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - - expect(card.answer).to eq("Juneau") + expect(@card.answer).to eq("Juneau") end it 'has a category' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - - expect(card.category).to eq(:Geography) + expect(@card.category).to eq(:Geography) end end From f0ca9fbbf841840f98b6babcf60962b594c9f0b3 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 17:40:33 -0600 Subject: [PATCH 55/62] feat: add new cards to deck --- spec/deck_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 20c3d7d55..9447f6918 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -23,13 +23,15 @@ expect(@deck.count).to eq(3) end - # it 'can_add_cards' do - # card_4 = Card.new("What is Danielle's cat's name", "Furriosa", :Turing_students) + it 'identifies cards in each category' do + expect(@deck.cards_in_category(:STEM)).to eq([@card_2, @card_3]) + expect(@deck.cards_in_category(:Geography)).to eq([@card_1]) + end - # expect(@deck.add_card(card_4)). to eq([@card_1, @card_2, @card_3, card_4]) - # end + it 'can_add_cards' do + card_4 = Card.new("What is Danielle's cat's name", "Furriosa", :Turing_students) - it 'cards_in_category' do - expect(@deck.cards_in_category(:STEM)).to eq([@card_2, @card_3]) + expect(@deck.add_card(card_4)). to eq([@card_1, @card_2, @card_3, card_4]) end + end From b9648ecd73278e9952ba2789d69a3b13fea6915e Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 21:52:36 -0600 Subject: [PATCH 56/62] fix bugs in number and percent correct by category code --- lib/round.rb | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/round.rb b/lib/round.rb index b655a6718..8326634aa 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -2,7 +2,7 @@ require_relative './card.rb' class Round - attr_reader :deck, :turns, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number + attr_reader :deck, :turns, :current_card, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number, :new_turn_category attr_writer :turns def initialize(deck) @@ -16,6 +16,8 @@ def initialize(deck) @current_card = current_card @percent_correct = 0.0 @percent_correct_by_category = 0 + @new_turn_category = [] + @correct_by_category = Hash.new(0) end @@ -24,10 +26,14 @@ def current_card end def take_turn(guess) - new_turn = Turn.new(guess, current_card) #@current_card) #need to try to find a way for new_turn to pull in guess and card + new_turn = Turn.new(guess, current_card) @turns. << new_turn - user_guesses << new_turn.correct? #returns true/false boolean - @number_correct += 1 if new_turn.correct? + user_guesses << new_turn.correct? #returns true/false boolean + + if new_turn.correct? + @number_correct += 1 + @correct_by_category[current_card.category] += 1 #@correct_by_category hash tracks the number of correct guesses by category + end # require 'pry'; binding.pry @card_number += 1 @turn_number += 1 @@ -38,26 +44,23 @@ def percent_correct @percent_correct = ((@number_correct.to_f / @turns.length) * 100).round(2) end - def number_correct_by_category(category) - @number_correct.cards.category - # category = @current_card.category - # @number_correct_by_category = + def number_correct_by_category(category) + @correct_by_category[category] #this pulls the category argument into the correct_by_category hash to identify the number of correct answers per category end - def percent_correct_by_category(category) #needed a method here because I couldn't include the parameter in the instance variable - @percent_correct_by_category + def percent_correct_by_category(category) + total_in_category = @turns.count { |turn| turn.card.category == category} + #{ |turn| turn.card.category == category } checks if each card associated with a turn object belongs to whatever category is declared in the argument + return 0.0 if total_in_category == 0 + ((number_correct_by_category(category).to_f / total_in_category) * 100).round(2) end -end - - # def number_correct_by_category - # if new_turn.correct? do - # end - # correct_by_category = - # += 1 if new_turn.correct? + # def unique_categories + # @deck.cards.map(&:category).uniq # end - - # def percent_correct_by_category - # @percent_correct_by_category = ((@number_correct_by_category.count.to_f / @turns.length) * 100).round(2) + # def return_percent_correct_by_category + # unique_categories.each do |category| # end + +end \ No newline at end of file From bbb2395cfd62b5b12cdab46d660ecfebed65b537 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 21:54:59 -0600 Subject: [PATCH 57/62] correct test for adds to number correct by category --- spec/round_spec.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/round_spec.rb b/spec/round_spec.rb index b76dd4fb9..b07e567f1 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -56,17 +56,16 @@ expect(@round.percent_correct).to eq(100) end - it 'identifies number correct by category' do + it 'identifies number of cards correct by category' do new_turn = @round.take_turn("Juneau") - +# require 'pry'; binding.pry expect(@round.number_correct_by_category(:Geography)).to eq(1) end - # 'adds to number correct by category' do - # expect(@round.number_correct_by_category(:Geography)).to eq(1) - - # expect(@round.percent_correct_by_category(:Geography)).to eq(100) - - # end + it 'adds to number correct by category' do + new_turn = @round.take_turn("Juneau") + # require 'pry'; binding.pry + expect(@round.percent_correct_by_category(:Geography)).to eq(100) + end end \ No newline at end of file From 4dc194d824e5a2d1f5c43c04879343d9f29352e2 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Mon, 26 Aug 2024 21:56:44 -0600 Subject: [PATCH 58/62] add initial code for percent correct by category results --- lib/flashcard_runner.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index ab2b90acc..5028145c8 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -19,6 +19,7 @@ def start @round.turns puts "Welcome! You're playing with #{@cards.length} cards." puts "----------------------------------------------------------" + @round.deck.cards.length.times do puts "This is card number #{@round.turn_number} out of #{@cards.length}." puts "Question: #{@round.current_card.question}" @@ -27,10 +28,12 @@ def start # require 'pry'; binding.pry puts new_turn.feedback end + puts "****** Game over! ******" - require 'pry'; binding.pry - puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}." - puts + # require 'pry'; binding.pry + puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}%." + puts "#{category} - #{@round.percent_correct_by_category(category)}% correct" #need to figure out how to get these to print for each category + puts "#{category} - #{@round.percent_correct_by_category(category)}% correct" end start \ No newline at end of file From c6888efd98ca0597677e428a4e3dcdf7093627af Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Tue, 27 Aug 2024 11:36:35 -0600 Subject: [PATCH 59/62] fix return percent correct by category method --- lib/flashcard_runner.rb | 6 +----- lib/round.rb | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index 5028145c8..95c42046a 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -7,13 +7,11 @@ @card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) @card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the surface of which planet?", "Mars", :STEM) @card_3 = Card.new("Describe in words the exact direction that is 697.5° clockwise from due north?", "North north west", :STEM) -# @card = Card.new(@question, @answer, @category) @cards = [@card_1, @card_2, @card_3] @deck = Deck.new(@cards) @turn = Turn.new(@guess, @card) @round = Round.new(@deck) -# require 'pry'; binding.pry def start @round.deck @round.turns @@ -30,10 +28,8 @@ def start end puts "****** Game over! ******" - # require 'pry'; binding.pry puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}%." - puts "#{category} - #{@round.percent_correct_by_category(category)}% correct" #need to figure out how to get these to print for each category - puts "#{category} - #{@round.percent_correct_by_category(category)}% correct" + @round.return_percent_correct_by_category end start \ No newline at end of file diff --git a/lib/round.rb b/lib/round.rb index 8326634aa..7ee4daac0 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -49,18 +49,23 @@ def number_correct_by_category(category) end def percent_correct_by_category(category) - total_in_category = @turns.count { |turn| turn.card.category == category} - #{ |turn| turn.card.category == category } checks if each card associated with a turn object belongs to whatever category is declared in the argument - return 0.0 if total_in_category == 0 + total_in_category = @turns.count { |turn| turn.card.category == category} #use block code here - |turn| is the argument, and the block iterates over each turn in the @turns array + #identifies whether the category of the card associated with each turn in the @turns array matches the cateegory of the argument passed into the method + + return 0.0 if total_in_category == 0 #don't care about empty categories ((number_correct_by_category(category).to_f / total_in_category) * 100).round(2) + end - # def unique_categories - # @deck.cards.map(&:category).uniq - # end + def unique_categories + @deck.cards.map(&:category).uniq + end - # def return_percent_correct_by_category - # unique_categories.each do |category| - # end + def return_percent_correct_by_category + unique_categories.each do |category| + correct_count = number_correct_by_category(category) + puts "#{category}: #{percent_correct_by_category(category)}%" + end + end -end \ No newline at end of file +end From 2e5e567b8d243728caca6a9ab28e985ad62d8ec0 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Tue, 27 Aug 2024 13:37:32 -0600 Subject: [PATCH 60/62] fix return percent by category method and delete unnecessary line 66 in round.rb --- lib/flashcard_runner.rb | 2 +- lib/round.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index 95c42046a..4dfa740b4 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -32,4 +32,4 @@ def start @round.return_percent_correct_by_category end -start \ No newline at end of file +start diff --git a/lib/round.rb b/lib/round.rb index 7ee4daac0..fe38bd503 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -63,7 +63,6 @@ def unique_categories def return_percent_correct_by_category unique_categories.each do |category| - correct_count = number_correct_by_category(category) puts "#{category}: #{percent_correct_by_category(category)}%" end end From 06a380bda72a675ba214676929325f3c17007fc1 Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Tue, 27 Aug 2024 15:17:19 -0600 Subject: [PATCH 61/62] cleaned up formatting for final submission --- lib/deck.rb | 10 +--------- lib/flashcard_runner.rb | 3 +-- lib/round.rb | 10 ++++------ lib/turn.rb | 3 +-- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/deck.rb b/lib/deck.rb index 8d94a602f..60d9595c6 100644 --- a/lib/deck.rb +++ b/lib/deck.rb @@ -1,13 +1,10 @@ -# require_relative './card.rb' (may need to add to make method to add cards work) - class Deck attr_reader :card, :cards - attr_writer :cards def initialize(cards) @cards = cards end -# require 'pry'; binding.pry + def count @cards.length end @@ -17,9 +14,4 @@ def cards_in_category(category) category == card.category end end - - def add_card(new_card) - @cards << new_card - end - end \ No newline at end of file diff --git a/lib/flashcard_runner.rb b/lib/flashcard_runner.rb index 4dfa740b4..8d3dbd3d9 100644 --- a/lib/flashcard_runner.rb +++ b/lib/flashcard_runner.rb @@ -23,12 +23,11 @@ def start puts "Question: #{@round.current_card.question}" user_input = gets.chomp new_turn = @round.take_turn(user_input) - # require 'pry'; binding.pry puts new_turn.feedback end puts "****** Game over! ******" - puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}%." + puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}." @round.return_percent_correct_by_category end diff --git a/lib/round.rb b/lib/round.rb index fe38bd503..86fcc8fdd 100644 --- a/lib/round.rb +++ b/lib/round.rb @@ -2,8 +2,7 @@ require_relative './card.rb' class Round - attr_reader :deck, :turns, :current_card, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number, :new_turn_category - attr_writer :turns + attr_reader :deck, :turns, :current_card, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number, :new_turn_category, :new_card def initialize(deck) @deck = deck @@ -16,7 +15,6 @@ def initialize(deck) @current_card = current_card @percent_correct = 0.0 @percent_correct_by_category = 0 - @new_turn_category = [] @correct_by_category = Hash.new(0) end @@ -34,7 +32,7 @@ def take_turn(guess) @number_correct += 1 @correct_by_category[current_card.category] += 1 #@correct_by_category hash tracks the number of correct guesses by category end - # require 'pry'; binding.pry + @card_number += 1 @turn_number += 1 new_turn @@ -52,7 +50,7 @@ def percent_correct_by_category(category) total_in_category = @turns.count { |turn| turn.card.category == category} #use block code here - |turn| is the argument, and the block iterates over each turn in the @turns array #identifies whether the category of the card associated with each turn in the @turns array matches the cateegory of the argument passed into the method - return 0.0 if total_in_category == 0 #don't care about empty categories + return 0 if total_in_category == 0 ((number_correct_by_category(category).to_f / total_in_category) * 100).round(2) end @@ -63,7 +61,7 @@ def unique_categories def return_percent_correct_by_category unique_categories.each do |category| - puts "#{category}: #{percent_correct_by_category(category)}%" + puts "#{category}: #{percent_correct_by_category(category)}% correct" end end diff --git a/lib/turn.rb b/lib/turn.rb index 2d1add9d2..259d36e02 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -1,6 +1,5 @@ class Turn attr_reader :card, :guess - attr_writer :card, :guess def initialize(guess, card) @guess = guess @@ -13,7 +12,7 @@ def correct? end def feedback - if card.answer.downcase == guess.downcase + if correct? "Correct!" else "Incorrect." From 13ba6c8a8ec779647f3f5a9cb3d68c3e4853215b Mon Sep 17 00:00:00 2001 From: Danielle Cardona Date: Tue, 27 Aug 2024 15:17:49 -0600 Subject: [PATCH 62/62] cleaned up formatting for final submission --- spec/deck_spec.rb | 13 +++---------- spec/round_spec.rb | 33 ++++++++++++++++----------------- spec/turn_spec.rb | 25 ++++++++++++------------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/spec/deck_spec.rb b/spec/deck_spec.rb index 9447f6918..7c346f0e7 100644 --- a/spec/deck_spec.rb +++ b/spec/deck_spec.rb @@ -15,23 +15,16 @@ expect(@deck).to be_instance_of(Deck) end - it 'returns_cards' do + it 'loads cards into the deck' do expect(@deck.cards).to eq(@cards) end - it 'counts_cards' do + it 'counts the number of cards in the deck' do expect(@deck.count).to eq(3) end - it 'identifies cards in each category' do + it 'identifies all of the cards in each category' do expect(@deck.cards_in_category(:STEM)).to eq([@card_2, @card_3]) expect(@deck.cards_in_category(:Geography)).to eq([@card_1]) end - - it 'can_add_cards' do - card_4 = Card.new("What is Danielle's cat's name", "Furriosa", :Turing_students) - - expect(@deck.add_card(card_4)). to eq([@card_1, @card_2, @card_3, card_4]) - end - end diff --git a/spec/round_spec.rb b/spec/round_spec.rb index b07e567f1..357e1fe47 100644 --- a/spec/round_spec.rb +++ b/spec/round_spec.rb @@ -2,7 +2,6 @@ require './lib/turn' require './lib/deck' require './lib/round' -require 'pry' RSpec.describe Round do @@ -21,51 +20,51 @@ expect(@round).to be_instance_of(Round) end - it 'loads_deck_into_round' do + it 'loads the deck into the round' do expect(@round.deck).to eq(@deck) end - it 'starts_turns' do + it 'starts the turn with an empty turns array' do expect(@round.turns).to eq([]) end - it 'pulls_current_card' do + it 'pulls the current card in the deck' do expect(@round.current_card).to eq(@card_1) end - it 'starts_with_empty_turns_array' do - expect(@round.turns).to eq([]) - end - - it 'logs the new turn into the turns array' do + it 'logs each new turn into the turns array' do new_turn = @round.take_turn("Juneau") expect(@round.turns.last).to eq(new_turn) -# require 'pry'; binding.pry end - it 'add to number correct' do + it 'add correct answers to the number correct counter' do new_turn = @round.take_turn("Juneau") expect(@round.number_correct).to eq(1) end - it 'identifies percent correct' do + it 'identifies the percent of correct answers per round' do new_turn = @round.take_turn("Juneau") expect(@round.percent_correct).to eq(100) end - it 'identifies number of cards correct by category' do + it 'identifies the number of correct answers in the round by category' do new_turn = @round.take_turn("Juneau") -# require 'pry'; binding.pry + expect(@round.number_correct_by_category(:Geography)).to eq(1) end - it 'adds to number correct by category' do + it 'calculates the percent of correct answers in the round by category' do new_turn = @round.take_turn("Juneau") - # require 'pry'; binding.pry + expect(@round.percent_correct_by_category(:Geography)).to eq(100) end - + + it 'identifies each unique category in the round' do + new_turn = @round.take_turn("Juneau") + + expect(@round.deck.cards.map(&:category).uniq).to eq([:Geography, :STEM]) + end end \ No newline at end of file diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index 955109889..32d68f563 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -2,44 +2,43 @@ require './lib/turn' RSpec.describe Turn do + + before(:each) do + @card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + end + it 'exists' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Juneau", card) + turn = Turn.new("Juneau", @card) expect(turn).to be_instance_of(Turn) end it 'is Juneau by default' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Juneau", card) + turn = Turn.new("Juneau", @card) expect(turn.guess).to eq("Juneau") end it "does not have to be Juneau" do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Spain", card) + turn = Turn.new("Spain", @card) expect(turn.guess).to eq("Spain") end it 'returns the Card' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Juneau", card) + turn = Turn.new("Juneau", @card) - expect(turn.card).to eq(card) + expect(turn.card).to eq(@card) end it 'indicates if the guess matched the answer on the card' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Juneau", card) + turn = Turn.new("Juneau", @card) expect(turn.correct?).to eq(true) end it 'provides feedback' do - card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) - turn = Turn.new("Juneau", card) + turn = Turn.new("Juneau", @card) expect(turn.feedback).to eq("Correct!") end