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

Billy Wallace #563

Open
wants to merge 67 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
dc7ae50
Create card class
wallacebilly1 Feb 1, 2024
ca155d1
Add test for Turn instantiation
wallacebilly1 Feb 1, 2024
c457746
Ignore .DS_Store
wallacebilly1 Feb 1, 2024
f619097
Create Turn class
wallacebilly1 Feb 1, 2024
3f3230c
Add test for returning guess
wallacebilly1 Feb 1, 2024
90f18d5
Add guess instance variable to attr_reader
wallacebilly1 Feb 1, 2024
c769134
Update test for returning guess
wallacebilly1 Feb 1, 2024
d31b731
Add test for returning card
wallacebilly1 Feb 1, 2024
1137464
Add test for correct? method
wallacebilly1 Feb 1, 2024
3341046
Create correct? method
wallacebilly1 Feb 1, 2024
64b15f8
Add test for feedback method
wallacebilly1 Feb 1, 2024
736a175
Create feedback method
wallacebilly1 Feb 1, 2024
ff618ea
Fix feedback test typo
wallacebilly1 Feb 1, 2024
4ae32ff
Add test for Deck instantiation
wallacebilly1 Feb 1, 2024
48d79c8
Create Deck class
wallacebilly1 Feb 1, 2024
c23039f
Partially set-up Deck Class and Array Test
wallacebilly1 Feb 2, 2024
2a47449
Fix spacing issues
wallacebilly1 Feb 2, 2024
a0e8cbd
Add rSpec configuration
wallacebilly1 Feb 2, 2024
cb620bd
Add rSpec configuration
wallacebilly1 Feb 2, 2024
812e179
Add rSpec configuration
wallacebilly1 Feb 2, 2024
a9aaf42
Add test for deck cards count
wallacebilly1 Feb 2, 2024
ea51821
Create count instance variable
wallacebilly1 Feb 2, 2024
f8861bf
Create test to return cards in specific category
wallacebilly1 Feb 2, 2024
962a06d
Create cards_in_category method
wallacebilly1 Feb 2, 2024
3f8454b
Update test for returning cards from a specific category
wallacebilly1 Feb 2, 2024
00c638a
Create test for returning an empty array for and invalid category
wallacebilly1 Feb 2, 2024
c1f7195
Adjusted count method
wallacebilly1 Feb 2, 2024
0462af1
Add test for Round instatiation
wallacebilly1 Feb 3, 2024
b8f1f99
Create Round class
wallacebilly1 Feb 3, 2024
43fbe82
Fix formatting
wallacebilly1 Feb 3, 2024
20ff10c
Add test for empty turns array
wallacebilly1 Feb 3, 2024
e89d4c7
Create empty turns array
wallacebilly1 Feb 3, 2024
2062341
Add test for current_card method
wallacebilly1 Feb 3, 2024
3ebea0b
Create current_card method
wallacebilly1 Feb 3, 2024
9f15123
Add test for take_turn method
wallacebilly1 Feb 3, 2024
e08ddfb
Create take_turn method
wallacebilly1 Feb 3, 2024
0c11712
Add test for returning whether guess is correct
wallacebilly1 Feb 3, 2024
6d7a8a4
Add test for adding the last turn into the turns array
wallacebilly1 Feb 3, 2024
1cb1c24
Update take_turn method with adding current turn into turns array
wallacebilly1 Feb 3, 2024
3eed903
Update test for adding last turn to array
wallacebilly1 Feb 5, 2024
0479e1d
Add number_correct method
wallacebilly1 Feb 5, 2024
6afcfba
Add test for how many guesses are correct
wallacebilly1 Feb 5, 2024
b2f327a
Add number_correct_by_category method
wallacebilly1 Feb 5, 2024
cead9aa
Add test for returning how many guesses are correct by category
wallacebilly1 Feb 5, 2024
e152483
Update order of tests and added some expect statements to tests
wallacebilly1 Feb 6, 2024
b40a27c
Update order of tests and added some expect statements to tests
wallacebilly1 Feb 6, 2024
9628383
Add test for returning feedback from last guess
wallacebilly1 Feb 6, 2024
067a43e
Add test for returning feedback from last guess
wallacebilly1 Feb 6, 2024
f434504
Add percent correct method
wallacebilly1 Feb 6, 2024
bd236b2
Add test for returning percent correct
wallacebilly1 Feb 6, 2024
2ccfa39
Create percent_correct_by_category method
wallacebilly1 Feb 6, 2024
92c7ac9
Add test for returning what percent of answers in a category are correct
wallacebilly1 Feb 6, 2024
54161ef
Add test for returning what percent of answers in a category are correct
wallacebilly1 Feb 6, 2024
75c2c8b
Fix count method issue
wallacebilly1 Feb 6, 2024
a8654f1
Add start method
wallacebilly1 Feb 6, 2024
a4b4614
Add print commands to feedback method
wallacebilly1 Feb 6, 2024
660d54b
Create cards, deck, and round
wallacebilly1 Feb 6, 2024
343404d
Add summary method and fix issues
wallacebilly1 Feb 6, 2024
df02b62
Fix issue
wallacebilly1 Feb 6, 2024
83aef45
Add more cards
wallacebilly1 Feb 6, 2024
6e695f9
Merge pull request #1 from wallacebilly1/feat/command_line_interface
wallacebilly1 Feb 6, 2024
29d188b
Fix test issue
wallacebilly1 Feb 6, 2024
065173e
Fix issue
wallacebilly1 Feb 6, 2024
801f2cf
Update feedback method
wallacebilly1 Feb 6, 2024
76e5cf7
Fix test failing
wallacebilly1 Feb 6, 2024
7258754
Fix test failing
wallacebilly1 Feb 6, 2024
a0f830e
Merge pull request #2 from wallacebilly1/fix/fix_tests
wallacebilly1 Feb 6, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
25 changes: 25 additions & 0 deletions flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'pry'
require './lib/card.rb'
require './lib/turn.rb'
require './lib/deck.rb'
require './lib/round.rb'

card_1 = Card.new("Who is leading the NBA in points per game?", "Luka Doncic", :"Basic Stats")
card_2 = Card.new("What team is leading the NBA in points per game?", "Indiana Pacers", :"Team Stats")
card_3 = Card.new("Who is leading the NBA in Box Plus/Minus?", "Nikola Jokic", :"Advanced Stats")
card_4 = Card.new("Who is leading the NBA in VORP?", "Nikola Jokic", :"Advanced Stats")
card_5 = Card.new("How many assists per game is Tyrese Halliburton averaging?", 12, :"Basic Stats")
card_6 = Card.new("What team has most wins in the NBA?", "Boston Celtics", :"Team Stats")
card_7 = Card.new("Who is the worst team in the NBA?", "Detroit Pistons", :"Team Stats")
card_8 = Card.new("Who is the reigning NBA champion?", "Denver Nuggets", :"Team Stats")
card_9 = Card.new("Who is the all time leader in points scored?", "Lebron James", :"Basic Stats")
card_10 = Card.new("Who has the highest effective field goal percentage?", "Dereck Lively", :"Advanced Stats")

cards = [card_1, card_2, card_3, card_4, card_5, card_6, card_7, card_8, card_9, card_10]

deck = Deck.new(cards)

round = Round.new(deck)

round.start
round.summary
11 changes: 11 additions & 0 deletions lib/card.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Card
attr_reader :question,
:answer,
:category

def initialize(question, answer, category)
@question = question
@answer = answer
@category = category
end
end
15 changes: 15 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Deck
attr_reader :cards

def initialize(cards)
@cards = cards
end

def count
@cards.count
end

def cards_in_category(category)
cards.select { |card| card.category == category}
end
end
66 changes: 66 additions & 0 deletions lib/round.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Round
attr_reader :deck, :turns, :number_correct

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

def current_card
@deck.cards[0]
end

def take_turn(guess)
current_turn = Turn.new(guess, current_card)
puts current_turn.feedback
@turns << current_turn
if current_turn.correct?
@number_correct += 1
else
end
@deck.cards.rotate!
current_turn
end

def number_correct_by_category(category)
@turns.count { |turn| turn.card.category == category && turn.correct?}
end

def percent_correct
((@number_correct.to_f / @turns.count) * 100).round(2)
end

def percent_correct_by_category(category)
category_correct = @turns.count { |turn| turn.card.category == category && turn.correct?}
category_count = @turns.count { |turn| turn.card.category == category}
((category_correct.to_f / category_count) * 100).round(2)
end

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

deck.cards.each do
puts "This is card number #{turns.count+1} out of #{deck.count}"
puts "Question: #{current_card.question}"

guess = gets.chomp
take_turn(guess)
end
end

def summary
puts "***** Game over! *****"

puts "You had #{number_correct} correct guesses out of #{deck.count} for a total score of #{percent_correct}%."
category_array = []
turns.each do |turn|
category = turn.card.category
category_array << category
end
category_array.uniq.each do |category|
puts "#{category} - #{percent_correct_by_category(category)}% 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
@card = card
end

def correct?
@guess == card.answer
end

def feedback
if correct? == true
"Correct!"
else
"Incorrect."
end
end
end
37 changes: 21 additions & 16 deletions spec/card_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
require './lib/card'
require 'rspec'

RSpec.configure do |config|
config.formatter = :documentation
end

RSpec.describe Card do
it 'exists' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)
it 'exists' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)

expect(card).to be_instance_of(Card)
end
expect(card).to be_instance_of(Card)
end

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

expect(card.question).to eq("What is the capital of Alaska?")
end
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)
it 'has an answer' do
card = Card.new("What is the capital of Alaska?", "Juneau", :Geography)

expect(card.answer).to eq("Juneau")
end
expect(card.answer).to eq("Juneau")
end

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

expect(card.category).to eq(:Geography)
end
expect(card.category).to eq(:Geography)
end
end
76 changes: 76 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require './lib/card'
require './lib/deck'
require 'rspec'

RSpec.configure do |config|
config.formatter = :documentation
end

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 'is an array' 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 be(cards)
end

it 'returns how many cards there are' 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(cards.count).to eq(3)
end

it 'returns cards from a specific 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)

stem_cards = deck.cards_in_category(:STEM)
geography_cards = deck.cards_in_category(:Geography)

expect(stem_cards).to eq([card_2, card_3])
expect(geography_cards).to eq([card_1])
end

it 'returns an empty array if an invalid category is entered' 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)

pop_culture_cards = deck.cards_in_category("Pop Culture")

expect(pop_culture_cards).to eq([])
end

end
Loading