Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devlin Lynch #607

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0e8c811
feat: Add Card class and initialize
devklynch Aug 22, 2024
0f2ae8a
feat: Add Turn class and turn_spec
devklynch Aug 22, 2024
52ce0c8
feat: Added Turn initialize
devklynch Aug 22, 2024
298b07c
fix: Turn instance variable naming
devklynch Aug 22, 2024
3cf5b86
feat: Add correct? method and test
devklynch Aug 22, 2024
a3ff6da
feat: Add method for Turn feedback
devklynch Aug 22, 2024
3fb9f7b
test: Added tests for incorrect guesses
devklynch Aug 22, 2024
73e473b
feat: Add Deck initialize and spec
devklynch Aug 22, 2024
ba570f7
feat: Add count to deck
devklynch Aug 22, 2024
221fd46
feat: Add cards_in_category method
devklynch Aug 22, 2024
a30f68d
feat: Add Round method and initialize
devklynch Aug 22, 2024
27af4ed
feat: Add current_card method to Round
devklynch Aug 22, 2024
e2fa2bd
feat: Add take_turn method to Round with tests
devklynch Aug 23, 2024
2dee434
refactor: Refactor take_turn method in round
devklynch Aug 23, 2024
af61e3b
refactor: Refactor take_turn method in round
devklynch Aug 23, 2024
91a0c5b
test: Add tests for number_correct and current_card to Round
devklynch Aug 24, 2024
93a7126
feat: Add number_correct_by_category to Round class
devklynch Aug 24, 2024
985cb59
feat: Added code for percent correct to Round
devklynch Aug 24, 2024
e71c7d1
feat: Add percent_correct_by_category to Round
devklynch Aug 24, 2024
0c6cb76
test: updated category test for Deck
devklynch Aug 24, 2024
3845700
feat: Add flascard_runner
devklynch Aug 24, 2024
df4440e
test: Clean up round_spec
devklynch Aug 24, 2024
4eb2e4b
feat: add start method to round
devklynch Aug 25, 2024
547476d
test: cleaning up test formatting for card and turn
devklynch Aug 25, 2024
b24656f
feat: Updated Turn to account for casing issues
devklynch Aug 25, 2024
b03669c
test: cleaned up tests for Deck and Round
devklynch Aug 25, 2024
568371d
refactor: Round class
devklynch Aug 25, 2024
76954eb
refactor: Minor change to rename a variable
devklynch Aug 27, 2024
250d49c
refactor: naming in Round class
devklynch Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Card
attr_reader :question,
:answer,
:category
def initialize(question,answer,category)
@question=question
@answer=answer
@category=category
end
end
18 changes: 18 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Deck
attr_reader :cards

def initialize(cards)
@cards=cards
end

def count
@cards.count
end

def cards_in_category(cat)
cards.filter_map do |card|
card if card.category == cat
end
end

end
13 changes: 13 additions & 0 deletions lib/flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require './lib/turn'
require './lib/card'
require './lib/deck'
require './lib/round'

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_4 = Card.new("Lisa Vanderpump starred on what reality show before getting her own show, Vanderpump Rules?(Acroynm please)", "Rhobh", "Pop Culture")

deck = Deck.new([card_1, card_2, card_3,card_4])
round = Round.new(deck)
round.start
81 changes: 81 additions & 0 deletions lib/round.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
class Round
attr_reader :deck,
:turns,
:number_correct,
:percent_correct,
:unique_categories


def initialize(deck)
@deck=deck
@turns=[]
@number_correct=0
@percent_correct=0
@unique_categories=[]

end

def current_card
@deck.cards[@turns.count]
end

def take_turn(guess)
new_turn = Turn.new(guess,current_card)
if new_turn.correct? == true
@number_correct +=1
end
@turns << new_turn
@percent_correct= ((@number_correct).to_f/ @turns.count)*100
new_turn
end

def number_correct_by_category(cat)
num_correct_by_cat=0
@turns.each do |turn|
if turn.card.category == cat
if turn.guess == turn.card.answer
num_correct_by_cat +=1
end
end
end
num_correct_by_cat
end

def percent_correct_by_category(cat)
total_by_cat=0
@turns.each do |turn|
if turn.card.category == cat
total_by_cat +=1
end
end
(((number_correct_by_category(cat)).to_f)/total_by_cat)*100
end

def get_unique_categories
deck.cards.each do |card|
@unique_categories << card.category
end
@unique_categories.uniq!
end

def start
puts "Welcome! You're playing with #{deck.count} cards"
puts "------------------------------------------------"

deck.cards.each do |card|
puts "This is card number #{deck.cards.index(card)+1} out of #{deck.count}. "
puts "Question: #{card.question}"
guess = gets.chomp
take_turn(guess)
puts turns.last.feedback
end

puts "**** Game over! ****"
puts "You had #{number_correct} out of #{turns.count} for a total score of #{percent_correct}%."

get_unique_categories
@unique_categories.each do |category|
puts "#{category} - #{(percent_correct_by_category(category)).round}% correct."
end
end
end
21 changes: 21 additions & 0 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Turn
attr_reader :guess,
:card

def initialize(guess,card)
@guess = guess.capitalize
@card = card
end

def correct?
@guess == @card.answer
end

def feedback
if @guess == @card.answer
"Correct!"
else
"Incorrect."
end
end
end
14 changes: 1 addition & 13 deletions spec/card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,13 @@
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
it 'has a question, answer, and category' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)

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")
end

it 'has a category' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)

expect(card.category).to eq(:Geography)
end
end
34 changes: 34 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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)
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)
end

it 'can return the count of cards in the 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(cards)
expect(deck.count).to eq(3)
end

it 'can give card info by 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)
expect(deck.cards_in_category(:STEM).count).to eq(2)
expect(deck.cards_in_category(:Geography).count).to eq(1)
expect(deck.cards_in_category("Pop Culture").count).to eq(0)
end

end
120 changes: 120 additions & 0 deletions spec/round_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
require './lib/turn'
require './lib/card'
require './lib/deck'
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)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round).to be_instance_of(Round)
end

it 'has a 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)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round.deck).to eq(deck)
end

it 'has a turn array and can take turn' 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)
expect(round.turns).to eq([])

new_turn=round.take_turn("Juneau")
expect(round.turns.count).to eq(1)
end

it 'can display current card in the 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)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
expect(round.current_card).to eq(card_1)

new_turn=round.take_turn("Juneau")
expect(round.current_card).to eq(card_2)
end

it 'can make a new Turn instance' 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)
new_turn=round.take_turn("Juneau")
expect(new_turn.class).to eq(Turn)
end

it 'lets you know how many questions are 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)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
new_turn=round.take_turn("Juneau")
expect(round.number_correct).to eq(1)
expect(round.current_card).to eq(card_2)
end

it 'moves on to turn 2'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)
new_turn=round.take_turn("Juneau")
round.take_turn("Venus")
expect(round.turns.count).to eq(2)
end

it 'can give feedback' 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)
new_turn=round.take_turn("Juneau")
expect(round.turns.last.feedback).to eq("Correct!")

round.take_turn("Venus")
expect(round.turns.last.feedback).to eq("Incorrect.")
end

it 'provides number correct and percent by 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)
deck = Deck.new([card_1, card_2, card_3])
round = Round.new(deck)
new_turn=round.take_turn("Juneau")
round.take_turn("Venus")
expect(round.number_correct_by_category(:Geography)).to eq(1)
expect(round.number_correct_by_category(:STEM)).to eq(0)
expect(round.percent_correct).to eq(50.0)
expect(round.percent_correct_by_category(:Geography)).to eq(100.0)
expect(round.percent_correct_by_category(:STEM)).to eq(0.0)

round.take_turn("North north west")
expect(round.percent_correct_by_category(:STEM)).to eq(50.0)
end

it 'creates array of unique categories' 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)
expect(round.get_unique_categories).to eq([:Geography, :STEM])
end
end
40 changes: 40 additions & 0 deletions spec/turn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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)
end

it 'has a guess and card' 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.card). to eq(card)
end

it 'checks if the guess is correct' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
turn = Turn.new("JUNEAU", card)
expect(turn.correct?). to eq(true)
end

it 'checks if the guess is incorrect' do
card = Card.new("Which planet is closest to the sun?", "Mercury", :STEM)
turn = Turn.new("Saturn", card)
expect(turn.correct?). to eq(false)
end

it 'provides feedback on the test' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
turn = Turn.new("Juneau", card)
expect(turn.feedback). to eq("Correct!")

card = Card.new("Which planet is closest to the sun?", "Mercury", :STEM)
turn = Turn.new("Saturn", card)
expect(turn.feedback). to eq("Incorrect.")
end

end