From 98df1db80943e41ca3dcdc23531de0f511e3ba3d Mon Sep 17 00:00:00 2001 From: Zion Mekonnen Date: Tue, 10 Dec 2024 07:08:24 -0800 Subject: [PATCH 1/2] card class --- lib/card.rb | 12 ++++++++++++ lib/turn.rb | 22 ++++++++++++++++++++++ spec/card_spec.rb | 5 +++-- spec/turn_spec.rb | 5 +++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 lib/turn.rb create mode 100644 spec/turn_spec.rb diff --git a/lib/card.rb b/lib/card.rb index e69de29bb..c67c1812b 100644 --- a/lib/card.rb +++ b/lib/card.rb @@ -0,0 +1,12 @@ +class Card + attr_reader :question, :answer, :category + + def initialize(question, answer, category) + @question = question + @answer = answer + @category = category + end + +end + + diff --git a/lib/turn.rb b/lib/turn.rb new file mode 100644 index 000000000..3d8527736 --- /dev/null +++ b/lib/turn.rb @@ -0,0 +1,22 @@ +class Turn + attr_reader :guess, :card, :correct, :feedback + + def initialize(guess, card ) + @guess = guess + @card = card + @correct = [] + @feedback = [] + end + + def correct? + @guess = card.answer + end + + def feedback + if @guess = card.answer + puts "Correct!" + else + puts "Incorrect!" + end + end +end \ No newline at end of file diff --git a/spec/card_spec.rb b/spec/card_spec.rb index 84a45a7a6..90f6823d4 100644 --- a/spec/card_spec.rb +++ b/spec/card_spec.rb @@ -1,12 +1,12 @@ require './lib/card' - +# require './lib/turn' 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) end - + it 'has a question' do card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) @@ -25,3 +25,4 @@ expect(card.category).to eq(:Geography) end end + diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb new file mode 100644 index 000000000..b4504d418 --- /dev/null +++ b/spec/turn_spec.rb @@ -0,0 +1,5 @@ +turn = Turn.new("Juneau", card) +turn.card +turn.guess +turn.correct +turn.feedback From ec0fb7142dd4a7acb75b6772e4d8a58f810a572e Mon Sep 17 00:00:00 2001 From: Zion Mekonnen Date: Tue, 10 Dec 2024 10:29:36 -0800 Subject: [PATCH 2/2] turn class incomplete --- lib/turn.rb | 4 ++-- spec/card_spec.rb | 3 ++- spec/turn_spec.rb | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/turn.rb b/lib/turn.rb index 3d8527736..5365b7a62 100644 --- a/lib/turn.rb +++ b/lib/turn.rb @@ -4,12 +4,12 @@ class Turn def initialize(guess, card ) @guess = guess @card = card - @correct = [] + @correct = correct @feedback = [] end def correct? - @guess = card.answer + @guess = @card.answer end def feedback diff --git a/spec/card_spec.rb b/spec/card_spec.rb index 90f6823d4..9760fe384 100644 --- a/spec/card_spec.rb +++ b/spec/card_spec.rb @@ -1,5 +1,6 @@ require './lib/card' -# require './lib/turn' +require 'pry' + RSpec.describe Card do it 'exists' do card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) diff --git a/spec/turn_spec.rb b/spec/turn_spec.rb index b4504d418..fc975fe69 100644 --- a/spec/turn_spec.rb +++ b/spec/turn_spec.rb @@ -1,5 +1,31 @@ -turn = Turn.new("Juneau", card) -turn.card -turn.guess -turn.correct -turn.feedback +require './lib/card' +require './lib/turn' +require 'pry' + +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) + end + it "returns correct" do + card = Card.new("What is the capital of Alaska?", "Juneau", :Geography) + turn = Turn.new("Juneau", card) + + expect(turn.correct?).to be true + end + + + + +end + + +# turn.card + +# turn.guess + +# turn.correct? + +# turn.feedback