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

Sebastian Mckee #625

Open
wants to merge 98 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
60a2392
Add initialize method
0nehundr3d Dec 3, 2024
d372891
Add question attribute
0nehundr3d Dec 3, 2024
fba2c01
Add answer attribute
0nehundr3d Dec 3, 2024
3ebc2c5
Add category attribute
0nehundr3d Dec 3, 2024
07c3cce
Initial Commit
0nehundr3d Dec 3, 2024
9f20c2c
Create class skeleton
0nehundr3d Dec 3, 2024
4d7d592
Add require rspec to fall in line with codebase
0nehundr3d Dec 3, 2024
5e6b02d
Add turn exists test
0nehundr3d Dec 3, 2024
1d65cb7
Change card method to attr_reader
0nehundr3d Dec 3, 2024
fc0aa98
Add has a card test
0nehundr3d Dec 3, 2024
8396e07
Change guess method to attr_reader
0nehundr3d Dec 3, 2024
bf42bce
Add guess and correct? tests
0nehundr3d Dec 3, 2024
31c86ff
Add correct? method
0nehundr3d Dec 3, 2024
49359b1
Add feedback test
0nehundr3d Dec 3, 2024
b9f1bf7
Add feedback method
0nehundr3d Dec 3, 2024
972fa49
Add false test to correct? method
0nehundr3d Dec 3, 2024
e2e53b3
Add negative feedback test
0nehundr3d Dec 3, 2024
1ae19b8
Change feedback method to work with incorrect answer
0nehundr3d Dec 3, 2024
39f9dfc
Initial Commit
0nehundr3d Dec 3, 2024
34b169b
Add Deck exists test
0nehundr3d Dec 3, 2024
09e2f7c
Create Deck class
0nehundr3d Dec 3, 2024
eef2970
Add has cards test
0nehundr3d Dec 3, 2024
a1ec5a3
Add cards attribute
0nehundr3d Dec 3, 2024
c49daa3
Update exists test for new Deck args
0nehundr3d Dec 3, 2024
2b2c06e
Add card count test
0nehundr3d Dec 3, 2024
b1a6b16
Add count method
0nehundr3d Dec 3, 2024
727126a
Add cards_in_category test
0nehundr3d Dec 4, 2024
5e541b6
Add cards_in_category method
0nehundr3d Dec 4, 2024
8395668
Initial Commit
0nehundr3d Dec 4, 2024
90ef4cb
Add Round exists test
0nehundr3d Dec 4, 2024
b198159
Add Round class
0nehundr3d Dec 4, 2024
014e2c5
Change exists tag to require deck arg
0nehundr3d Dec 4, 2024
f5245aa
Add deck arg to class
0nehundr3d Dec 4, 2024
009dca7
Add has a deck test
0nehundr3d Dec 4, 2024
6db407c
Add has turns test
0nehundr3d Dec 4, 2024
972124a
Fix checking deck instead of rounds
0nehundr3d Dec 4, 2024
7d85bf9
Add turns array
0nehundr3d Dec 4, 2024
20da7fa
Add current_card test
0nehundr3d Dec 4, 2024
a9db798
Add current_card method
0nehundr3d Dec 4, 2024
9ea9fdc
Add can create turns test
0nehundr3d Dec 4, 2024
36850c2
Add take_turn method
0nehundr3d Dec 4, 2024
986a417
Add can create valid turns test
0nehundr3d Dec 4, 2024
51881b3
Fix args being givin in wrong order in take_turn method
0nehundr3d Dec 4, 2024
3597345
Make take_turn params more clear
0nehundr3d Dec 4, 2024
404f930
Add stores previous turns test
0nehundr3d Dec 4, 2024
f176830
Change take_turn method to store turns
0nehundr3d Dec 4, 2024
13960b5
Add can track number of correct answers test
0nehundr3d Dec 4, 2024
2c3eac0
Add number_correct attribute and increment functionality
0nehundr3d Dec 4, 2024
28a81f4
Change take_turn method to cycle through deck
0nehundr3d Dec 4, 2024
2257abd
Add can cycle through deck test
0nehundr3d Dec 4, 2024
2b7e90c
Add stores all previous taken turns test
0nehundr3d Dec 4, 2024
ca28076
Update stores all previous taken turns to be more robust
0nehundr3d Dec 4, 2024
721c3b8
Add number_correct test to stores all previous taken turns in order test
0nehundr3d Dec 4, 2024
6ee0b68
Add correct by category test
0nehundr3d Dec 4, 2024
3ef018d
Fix bugs causing number by category test to always fail
0nehundr3d Dec 4, 2024
2226e5f
Add number_correct_by_category method
0nehundr3d Dec 4, 2024
817a382
Add percent correct test
0nehundr3d Dec 4, 2024
953c4ee
Add percent_correct method
0nehundr3d Dec 4, 2024
9ba014d
add perceny by category test
0nehundr3d Dec 4, 2024
a451e1f
Add percent_correct_by_category method
0nehundr3d Dec 4, 2024
452ecb9
Initial Commit
0nehundr3d Dec 4, 2024
e7e5eec
Add categories attribute test
0nehundr3d Dec 4, 2024
c47a927
Add categories attribute
0nehundr3d Dec 4, 2024
4fe65c0
Remove redundant code in percent_correct_by_category
0nehundr3d Dec 4, 2024
56773a1
Change percent methods to round to the second decimal place
0nehundr3d Dec 4, 2024
3a98e9b
Add start function that runs flashcard game
0nehundr3d Dec 4, 2024
bcb9443
Change for loops to each loops for readability and removal of unneede…
0nehundr3d Dec 4, 2024
3f90bbd
Change for loops to each loops and change unclear temp variables
0nehundr3d Dec 4, 2024
9fd36af
Change @count attribute to be static
0nehundr3d Dec 4, 2024
9e8b7bb
Change runner file to utilize updated deck.count method
0nehundr3d Dec 4, 2024
77fdd33
Add documentation to less clear blocks of code
0nehundr3d Dec 4, 2024
8d6a721
Add documentation and line breaks for code readability
0nehundr3d Dec 4, 2024
3f3408a
Initial Commit
0nehundr3d Dec 4, 2024
7043327
Add CardGenerator exists test
0nehundr3d Dec 4, 2024
ab5edec
Create CardGenerator class
0nehundr3d Dec 4, 2024
8d6743b
Initial Commit
0nehundr3d Dec 4, 2024
e29ed72
Add generate cards test
0nehundr3d Dec 4, 2024
df31524
Add cards to be generated
0nehundr3d Dec 4, 2024
7295c43
Fix typo in card 4 category
0nehundr3d Dec 4, 2024
fcde3e3
Change initialize method to generate cards list
0nehundr3d Dec 4, 2024
c237a33
Change runner file to use CardGenerator class
0nehundr3d Dec 4, 2024
65f7ad2
Change .each to .find_all in cards_in_category
0nehundr3d Dec 5, 2024
9a9ef2e
Change each loop to find loop in percent_correct method
0nehundr3d Dec 5, 2024
c614310
Refractor percent_correct_by_category into two .find_all statements
0nehundr3d Dec 5, 2024
7802181
Refractor number_correct_by_category into one .find_all statement
0nehundr3d Dec 5, 2024
c7b5331
Clean up code in take_turn method
0nehundr3d Dec 5, 2024
71a494e
Change turn class to be case insensitive
0nehundr3d Dec 5, 2024
fcbe73c
Add missing % in score readout
0nehundr3d Dec 5, 2024
686ced8
change each loop to times loop
0nehundr3d Dec 6, 2024
f3c927b
Remove redundant variable
0nehundr3d Dec 6, 2024
7b8b38e
Refractor @categories initialazation into one line
0nehundr3d Dec 6, 2024
43b72ec
Refractor feedback into one line
0nehundr3d Dec 6, 2024
c984c1b
Add documentation mode to spec files
0nehundr3d Dec 6, 2024
69b4001
Remove redundent config settings
0nehundr3d Dec 6, 2024
e2e3a77
Change take_turn to no longer delete cards in array
0nehundr3d Dec 8, 2024
64b0055
Remove unneeded parens
0nehundr3d Dec 8, 2024
cbc6e72
Initial Commit
0nehundr3d Dec 10, 2024
e4fccbf
Change card generator spec to use seperate test text file
0nehundr3d Dec 10, 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
4 changes: 4 additions & 0 deletions cards.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
What is 5 + 5?,10,STEM
What is Rachel's favorite animal?,red panda,Turing Staff
What is Mike's middle name?,nobody knows,Turing Staff
What cardboard cutout lives at Turing?,Justin bieber,Pop Culture
29 changes: 29 additions & 0 deletions flashcard_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require './lib/round'
require './lib/card'
require './lib/turn'
require './lib/deck'
require './lib/card_generator'

def start
cards = CardGenerator.new("cards.txt").cards
deck = Deck.new(cards)
round = Round.new(deck)

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

deck.count.times do |round_num|
puts "This is card #{round_num + 1} out of #{deck.count}"
puts "Question: #{round.current_card.question}"
turn_result = round.take_turn(gets.chomp)
puts turn_result.feedback
end

puts "****** Game over! ******"
puts "You had #{round.number_correct} out of #{deck.count} for a total score of #{round.percent_correct}%"
round.deck.categories.each do |category|
puts "#{category} - #{round.percent_correct_by_category(category)}% correct"
end
end

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

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

def initialize(filename)
@cards = []

File.foreach(filename) do |line|
args = line.chomp.split(',')
@cards << Card.new(args[0], args[1], args[2])
end
end
end
17 changes: 17 additions & 0 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Deck
attr_reader :cards, :categories, :count

def initialize(cards)
@cards = cards
@categories = []
@count = cards.size

@cards.each {|card| @categories << card.category if [email protected]?(card.category)} #Create a list of all categories in the deck
end

def cards_in_category(category)
category_cards = []

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

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

def current_card
deck.cards[0]
end

def take_turn(guess)
turn = Turn.new(guess, current_card)

@number_correct += 1 if turn.correct?

@deck.cards << @deck.cards.shift #Removes the first element in the cards array, keeps current_card accurate

@turns << turn
turn
end

def number_correct_by_category(category)

@turns.find_all {|turn| turn.correct? && turn.card.category == category}.size

end

def percent_correct #All percents rounded to two decimal places

correct_turns = @turns.find_all {|turn| turn.correct?}


((correct_turns.size.to_f/turns.size) * 100).round(2)
end

def percent_correct_by_category(category)
correct = number_correct_by_category(category).to_f #Float used to ensure percentage not rounded prematurely

total_turns = @turns.find_all {|turn| turn.card.category == category}
correct_turns = total_turns.find_all {|turn| turn.correct?}

((correct_turns.size.to_f/total_turns.length) * 100).round(2)
end
end
16 changes: 16 additions & 0 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Turn
attr_reader :card, :guess

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

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

def feedback
correct? ? "Correct!" : "Incorrect."
end
end
27 changes: 27 additions & 0 deletions spec/card_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rspec'
require './lib/card_generator'
require './lib/card'

describe CardGenerator do
it 'exists' do
filename = "spec/cards.txt"

cards = CardGenerator.new(filename)

expect(cards).to be_a(CardGenerator)
end

it 'can generate cards' do
filename = "cards.txt"

answer_hash = {"What is 5 + 5?": "10", "What is Rachel's favorite animal?": "red panda", "What is Mike's middle name?": "nobody knows", "What cardboard cutout lives at Turing?": "Justin bieber"}
category_hash = {"What is 5 + 5?": "STEM", "What is Rachel's favorite animal?": "Turing Staff", "What is Mike's middle name?": "Turing Staff", "What cardboard cutout lives at Turing?": "Pop Culture"}

cards = CardGenerator.new(filename).cards

cards.each do |card|
expect(card.answer).to eq(answer_hash[card.question.to_sym])
expect(card.category).to eq(category_hash[card.question.to_sym])
end
end
end
3 changes: 2 additions & 1 deletion spec/card_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rspec'
require './lib/card'

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

Expand Down
4 changes: 4 additions & 0 deletions spec/cards.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
What is 5 + 5?,10,STEM
What is Rachel's favorite animal?,red panda,Turing Staff
What is Mike's middle name?,nobody knows,Turing Staff
What cardboard cutout lives at Turing?,Justin bieber,Pop Culture
62 changes: 62 additions & 0 deletions spec/deck_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'rspec'
require './lib/card'
require './lib/deck'

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_a(Deck)
end

it 'has 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 'can count 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)
end

it 'can check for cards in a givin 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)).to eq([card_2, card_3])
expect(deck.cards_in_category(:Geography)).to eq([card_1])
expect(deck.cards_in_category("Pop Culture")).to eq([])
end

it 'has a list of all categories in its 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.categories).to eq([:Geography, :STEM])
end
end
Loading