From f51ff3997a980a6d6c385b6ff67266e3558c742f Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Tue, 14 Aug 2018 14:30:40 -0700 Subject: [PATCH 01/21] completed wave one --- lib/adagrams.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..4f63ab9 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,13 @@ +def draw_letters() + letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] + # puts letters +end +draw_letters + +ten_letters = [] +1.times do |letter| + letter = draw_letters.shuffle.pop(10) + ten_letters << letter +end + +puts ten_letters From c29579f45d2cb9a6a3514a59daeb96fa99e728f7 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Wed, 15 Aug 2018 14:32:55 -0700 Subject: [PATCH 02/21] wave 1 complete --- lib/adagrams.rb | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 4f63ab9..f12deb2 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,13 +1,34 @@ +require 'pry' def draw_letters() letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] - # puts letters + + letter = letters.shuffle.pop(10) + + return letter end -draw_letters -ten_letters = [] -1.times do |letter| - letter = draw_letters.shuffle.pop(10) - ten_letters << letter +def welcome + puts "Welcome to adagrams. Here are your letters." + puts draw_letters.join(' , ') end -puts ten_letters +puts welcome + puts "Based on these letters, give us a word." + print "Word: " + user_input = gets.chomp + + +def uses_available_letters(user_input, draw_letters) + letters = user_input.chars.to_a + if letters.include?(welcome) == true + puts "yay" + end + binding.pry + # letters_in_hand = draw_letters + # input = user_input.slice(0..9) + # test = letters_in_hand.include?(user_input) + # return test +end + + +# puts uses_available_letters(user_input, draw_letters) From 0a52ff5e9fbadfa4a78b3d6762d70e7977e4451a Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Wed, 15 Aug 2018 14:59:17 -0700 Subject: [PATCH 03/21] wave 1 refactored --- lib/adagrams.rb | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index f12deb2..75e53f6 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,34 +1,38 @@ -require 'pry' -def draw_letters() +# require 'pry' +# wave 1 +def stores_letters letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] +end - letter = letters.shuffle.pop(10) - +def shuffle_letters + letter = stores_letters.shuffle.pop(10) return letter end + def welcome puts "Welcome to adagrams. Here are your letters." - puts draw_letters.join(' , ') + return shuffle_letters.join(' , ') end + puts welcome - puts "Based on these letters, give us a word." - print "Word: " - user_input = gets.chomp - - -def uses_available_letters(user_input, draw_letters) - letters = user_input.chars.to_a - if letters.include?(welcome) == true - puts "yay" - end - binding.pry - # letters_in_hand = draw_letters - # input = user_input.slice(0..9) - # test = letters_in_hand.include?(user_input) - # return test -end +puts "Based on these letters, give us a word." +print "Word: " +user_input = gets.chomp + +# +# def uses_available_letters(user_input, draw_letters) +# letters = user_input.chars.to_a +# if letters.include?(welcome) == true +# puts "yay" +# end +# binding.pry +# # letters_in_hand = draw_letters +# # input = user_input.slice(0..9) +# # test = letters_in_hand.include?(user_input) +# # return test +# end # puts uses_available_letters(user_input, draw_letters) From e20d2db3778cb32c4213a5349f931d8c098ba74c Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Wed, 15 Aug 2018 15:27:04 -0700 Subject: [PATCH 04/21] wave 2 --- lib/adagrams.rb | 51 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 75e53f6..a7b46ba 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -6,33 +6,42 @@ def stores_letters def shuffle_letters letter = stores_letters.shuffle.pop(10) - return letter + return letter.join(' , ') end def welcome puts "Welcome to adagrams. Here are your letters." - return shuffle_letters.join(' , ') + shuffle_letters end puts welcome -puts "Based on these letters, give us a word." -print "Word: " -user_input = gets.chomp - -# -# def uses_available_letters(user_input, draw_letters) -# letters = user_input.chars.to_a -# if letters.include?(welcome) == true -# puts "yay" -# end -# binding.pry -# # letters_in_hand = draw_letters -# # input = user_input.slice(0..9) -# # test = letters_in_hand.include?(user_input) -# # return test -# end - - -# puts uses_available_letters(user_input, draw_letters) + +def game_instructions + puts "Based on these letters, give us a word." + print "Word: " +end + +def get_user_input + user_input = gets.chomp +end + +# wave 2 +def uses_available_letters(get_user_input, shuffle_letters) + user_input = get_user_input.upcase.split("") + if user_input.include?(shuffle_letters) == true + else + puts "You entered in a word that contains characters not in the letter bank" + game_instructions + get_user_input + end +end + +puts uses_available_letters(user_input, shuffle_letters) + +# binding.pry +# letters_in_hand = draw_letters +# input = user_input.slice(0..9) +# test = letters_in_hand.include?(user_input) +# return test From 6cd1df6ab0a2f26a4ffd1009742f6ea5f0397af2 Mon Sep 17 00:00:00 2001 From: Layla Date: Wed, 15 Aug 2018 21:20:14 -0700 Subject: [PATCH 05/21] updated wave 2 --- lib/adagrams.rb | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index a7b46ba..d88c35a 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -4,20 +4,17 @@ def stores_letters letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] end -def shuffle_letters +def draw_letters letter = stores_letters.shuffle.pop(10) - return letter.join(' , ') + return letter end - def welcome puts "Welcome to adagrams. Here are your letters." shuffle_letters end -puts welcome - def game_instructions puts "Based on these letters, give us a word." print "Word: " @@ -25,23 +22,22 @@ def game_instructions def get_user_input user_input = gets.chomp + return user_input end # wave 2 -def uses_available_letters(get_user_input, shuffle_letters) - user_input = get_user_input.upcase.split("") - if user_input.include?(shuffle_letters) == true - else - puts "You entered in a word that contains characters not in the letter bank" - game_instructions - get_user_input +def uses_available_letters?(input, letters_in_hand) + input = input.upcase.split("") + input.each do |letter| + if letters_in_hand.include?(letter) + letters_in_hand.delete(letter) + else + return false + end end + return true end -puts uses_available_letters(user_input, shuffle_letters) - -# binding.pry -# letters_in_hand = draw_letters -# input = user_input.slice(0..9) -# test = letters_in_hand.include?(user_input) -# return test +# wave 3 +def score_word(word) +end From eb9c648d221b497d72e501de6f52cb90b3cbea80 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Thu, 16 Aug 2018 13:34:25 -0700 Subject: [PATCH 06/21] trying to get updates --- lib/adagrams.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index a7b46ba..540984d 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -4,19 +4,20 @@ def stores_letters letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] end -def shuffle_letters +def draw_letters letter = stores_letters.shuffle.pop(10) - return letter.join(' , ') + return letter end def welcome puts "Welcome to adagrams. Here are your letters." - shuffle_letters + draw_letters end puts welcome +# binding.pry def game_instructions puts "Based on these letters, give us a word." @@ -38,7 +39,9 @@ def uses_available_letters(get_user_input, shuffle_letters) end end -puts uses_available_letters(user_input, shuffle_letters) +# puts uses_available_letters(get_user_input, shuffle_letters) + + # binding.pry # letters_in_hand = draw_letters From fe5c492170c5cf1830fc68b0d9ff0b33ba1657e4 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Thu, 16 Aug 2018 13:40:49 -0700 Subject: [PATCH 07/21] updating specs sheet --- specs/adagrams_spec.rb | 250 ++++++++++++++++++++--------------------- 1 file changed, 125 insertions(+), 125 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index ae2ccd0..3cd8733 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -2,7 +2,7 @@ require 'minitest/reporters' require 'minitest/skip_dsl' -require_relative '../lib/adagrams' +require_relative'../lib/adagrams' # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -26,8 +26,8 @@ end end - describe 'uses_available_letters? method' do - +# describe 'uses_available_letters? method' do +# it 'returns true if the submitted letters are valid against the drawn letters' do drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] test_word = 'DOG' @@ -46,126 +46,126 @@ expect(is_valid).must_equal false end - it 'returns false word contains repeated letters more than in the drawn letters' do - drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] - test_word = 'AAA' - - is_valid = uses_available_letters? test_word, drawn_letters - - expect(is_valid).must_equal false - end - - end - - describe 'score_word method' do - it 'returns an accurate numerical score according to the score chart' do - expect(score_word("A")).must_equal 1 - expect(score_word("DOG")).must_equal 5 - expect(score_word("WHIMSY")).must_equal 17 - end - - it 'returns a score regardless of input case' do - expect(score_word("a")).must_equal 1 - expect(score_word("dog")).must_equal 5 - expect(score_word("wHiMsY")).must_equal 17 - end - - it 'returns a score of 0 if given an empty input' do - expect(score_word("")).must_equal 0 - end - - it 'adds an extra 8 points if the word is 7 or more characters long' do - expect(score_word("XXXXXXX")).must_equal 64 - expect(score_word("XXXXXXXX")).must_equal 72 - expect(score_word("XXXXXXXXX")).must_equal 80 - end - end - - describe 'highest_score_from method' do - it 'returns a hash that contains the word and score of best word in an array' do - words = ['X', 'XX', 'XXX', 'XXXX'] - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'XXXX' - expect(best_word[:score]).must_equal 32 - end - - it 'accurately finds best scoring word even if not sorted' do - words = ['XXX', 'XXXX', 'XX', 'X'] - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'XXXX' - expect(best_word[:score]).must_equal 32 - end - - it 'in case of tied score, prefers the word with fewer letters' do - # the character 'M' is worth 3 points, 'W' is 4 points - words = ['MMMM', 'WWW'] - - # verify both have a score of 12 - expect(score_word(words.first)).must_equal 12 - expect(score_word(words.last)).must_equal 12 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'WWW' - expect(best_word[:score]).must_equal 12 - end - - it 'in case of tied score, prefers the word with fewer letters regardless of order' do - # the character 'M' is worth 3 points, 'W' is 4 points - words = ['WWW', 'MMMM'] - - # verify both have a score of 12 - expect(score_word(words.first)).must_equal 12 - expect(score_word(words.last)).must_equal 12 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'WWW' - expect(best_word[:score]).must_equal 12 - end - - it 'in case of tied score, prefers most the word with 10 letters' do - # the character 'A' is worth 1 point, 'B' is 3 points - words = ['AAAAAAAAAA', 'BBBBBB'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'AAAAAAAAAA' - expect(best_word[:score]).must_equal 18 - end - - it 'in case of tied score, prefers most the word with 10 letters regardless of order' do - # the character 'A' is worth 1 point, 'B' is 3 points - words = ['BBBBBB', 'AAAAAAAAAA'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'AAAAAAAAAA' - expect(best_word[:score]).must_equal 18 - end - - it 'in case of tied score and same length words, prefers the first word' do - # the character 'A' is worth 1 point, 'E' is 1 point - words = ['AAAAAAAAAA', 'EEEEEEEEEE'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal words.first - expect(best_word[:score]).must_equal 18 - end - end +# it 'returns false word contains repeated letters more than in the drawn letters' do +# drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] +# test_word = 'AAA' +# +# is_valid = uses_available_letters? test_word, drawn_letters +# +# expect(is_valid).must_equal false +# end +# +# end +# +# describe 'score_word method' do +# it 'returns an accurate numerical score according to the score chart' do +# expect(score_word("A")).must_equal 1 +# expect(score_word("DOG")).must_equal 5 +# expect(score_word("WHIMSY")).must_equal 17 +# end +# +# it 'returns a score regardless of input case' do +# expect(score_word("a")).must_equal 1 +# expect(score_word("dog")).must_equal 5 +# expect(score_word("wHiMsY")).must_equal 17 +# end +# +# it 'returns a score of 0 if given an empty input' do +# expect(score_word("")).must_equal 0 +# end +# +# it 'adds an extra 8 points if the word is 7 or more characters long' do +# expect(score_word("XXXXXXX")).must_equal 64 +# expect(score_word("XXXXXXXX")).must_equal 72 +# expect(score_word("XXXXXXXXX")).must_equal 80 +# end +# end +# +# describe 'highest_score_from method' do +# it 'returns a hash that contains the word and score of best word in an array' do +# words = ['X', 'XX', 'XXX', 'XXXX'] +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'XXXX' +# expect(best_word[:score]).must_equal 32 +# end +# +# it 'accurately finds best scoring word even if not sorted' do +# words = ['XXX', 'XXXX', 'XX', 'X'] +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'XXXX' +# expect(best_word[:score]).must_equal 32 +# end +# +# it 'in case of tied score, prefers the word with fewer letters' do +# # the character 'M' is worth 3 points, 'W' is 4 points +# words = ['MMMM', 'WWW'] +# +# # verify both have a score of 12 +# expect(score_word(words.first)).must_equal 12 +# expect(score_word(words.last)).must_equal 12 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'WWW' +# expect(best_word[:score]).must_equal 12 +# end +# +# it 'in case of tied score, prefers the word with fewer letters regardless of order' do +# # the character 'M' is worth 3 points, 'W' is 4 points +# words = ['WWW', 'MMMM'] +# +# # verify both have a score of 12 +# expect(score_word(words.first)).must_equal 12 +# expect(score_word(words.last)).must_equal 12 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'WWW' +# expect(best_word[:score]).must_equal 12 +# end +# +# it 'in case of tied score, prefers most the word with 10 letters' do +# # the character 'A' is worth 1 point, 'B' is 3 points +# words = ['AAAAAAAAAA', 'BBBBBB'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'AAAAAAAAAA' +# expect(best_word[:score]).must_equal 18 +# end +# +# it 'in case of tied score, prefers most the word with 10 letters regardless of order' do +# # the character 'A' is worth 1 point, 'B' is 3 points +# words = ['BBBBBB', 'AAAAAAAAAA'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'AAAAAAAAAA' +# expect(best_word[:score]).must_equal 18 +# end +# +# it 'in case of tied score and same length words, prefers the first word' do +# # the character 'A' is worth 1 point, 'E' is 1 point +# words = ['AAAAAAAAAA', 'EEEEEEEEEE'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal words.first +# expect(best_word[:score]).must_equal 18 +# end +# end end From 3a50e81aa5b4720aa7f236e99bdb09b0fc47466e Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 13:42:39 -0700 Subject: [PATCH 08/21] updated wave 3 --- lib/adagrams.rb | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index d88c35a..84fef04 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -20,10 +20,10 @@ def game_instructions print "Word: " end -def get_user_input - user_input = gets.chomp - return user_input -end +# def get_user_input +# user_input = gets.chomp +# return user_input +# end # wave 2 def uses_available_letters?(input, letters_in_hand) @@ -40,4 +40,30 @@ def uses_available_letters?(input, letters_in_hand) # wave 3 def score_word(word) + score = 0 + + score_hash = { + "A" => 1, + "E" => 1, + "I" => 1, + "D" => 2, + "G" => 2, + "O" => 1, + "W" => 4, + "H" => 4, + "M" => 3, + "S" => 1, + "Y" => 4, + "X" => 8 + } + + word = word.upcase.split("") + word.each do |letter| + score += score_hash[letter] + end + bonus_length = [7, 8, 9, 10] + if bonus_length.include?(word.length) + score += 8 + end + return score end From b2dba0b11095eb965011df5c55b10f0df9a08d2e Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 14:15:12 -0700 Subject: [PATCH 09/21] wave 3 complete --- lib/adagrams.rb | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 84fef04..1f7a62a 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -46,15 +46,29 @@ def score_word(word) "A" => 1, "E" => 1, "I" => 1, + "O" => 1, + "U" => 1, + "L" => 1, + "N" => 1, + "R" => 1, + "S" => 1, + "T" => 1, "D" => 2, "G" => 2, - "O" => 1, - "W" => 4, - "H" => 4, + "B" => 3, + "C" => 3, "M" => 3, - "S" => 1, + "P" => 3, + "F" => 4, + "H" => 4, + "V" => 4, + "W" => 4, "Y" => 4, - "X" => 8 + "K" => 5, + "J" => 8, + "X" => 8, + "Q" => 10, + "Z" => 10 } word = word.upcase.split("") @@ -65,5 +79,7 @@ def score_word(word) if bonus_length.include?(word.length) score += 8 end - return score + return score end + +# wave 4 From 1741514b5448d6acf2f0b54ca267604140f3a547 Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 14:16:38 -0700 Subject: [PATCH 10/21] updated specs --- specs/adagrams_spec.rb | 182 +++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 88 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index ae2ccd0..0161bf8 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -7,6 +7,7 @@ # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +# wave 1 describe 'Adagrams' do describe 'draw_letters method' do it 'draws ten letters from the letter pool' do @@ -26,6 +27,7 @@ end end +# wave 2 describe 'uses_available_letters? method' do it 'returns true if the submitted letters are valid against the drawn letters' do @@ -57,6 +59,8 @@ end + +# wave 3 describe 'score_word method' do it 'returns an accurate numerical score according to the score chart' do expect(score_word("A")).must_equal 1 @@ -80,92 +84,94 @@ expect(score_word("XXXXXXXXX")).must_equal 80 end end - - describe 'highest_score_from method' do - it 'returns a hash that contains the word and score of best word in an array' do - words = ['X', 'XX', 'XXX', 'XXXX'] - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'XXXX' - expect(best_word[:score]).must_equal 32 - end - - it 'accurately finds best scoring word even if not sorted' do - words = ['XXX', 'XXXX', 'XX', 'X'] - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'XXXX' - expect(best_word[:score]).must_equal 32 - end - - it 'in case of tied score, prefers the word with fewer letters' do - # the character 'M' is worth 3 points, 'W' is 4 points - words = ['MMMM', 'WWW'] - - # verify both have a score of 12 - expect(score_word(words.first)).must_equal 12 - expect(score_word(words.last)).must_equal 12 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'WWW' - expect(best_word[:score]).must_equal 12 - end - - it 'in case of tied score, prefers the word with fewer letters regardless of order' do - # the character 'M' is worth 3 points, 'W' is 4 points - words = ['WWW', 'MMMM'] - - # verify both have a score of 12 - expect(score_word(words.first)).must_equal 12 - expect(score_word(words.last)).must_equal 12 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'WWW' - expect(best_word[:score]).must_equal 12 - end - - it 'in case of tied score, prefers most the word with 10 letters' do - # the character 'A' is worth 1 point, 'B' is 3 points - words = ['AAAAAAAAAA', 'BBBBBB'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'AAAAAAAAAA' - expect(best_word[:score]).must_equal 18 - end - - it 'in case of tied score, prefers most the word with 10 letters regardless of order' do - # the character 'A' is worth 1 point, 'B' is 3 points - words = ['BBBBBB', 'AAAAAAAAAA'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal 'AAAAAAAAAA' - expect(best_word[:score]).must_equal 18 - end - - it 'in case of tied score and same length words, prefers the first word' do - # the character 'A' is worth 1 point, 'E' is 1 point - words = ['AAAAAAAAAA', 'EEEEEEEEEE'] - - # verify both have a score of 10 - expect(score_word(words.first)).must_equal 18 - expect(score_word(words.last)).must_equal 18 - - best_word = highest_score_from words - - expect(best_word[:word]).must_equal words.first - expect(best_word[:score]).must_equal 18 - end - end +# +# +# # wave 4 +# describe 'highest_score_from method' do +# it 'returns a hash that contains the word and score of best word in an array' do +# words = ['X', 'XX', 'XXX', 'XXXX'] +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'XXXX' +# expect(best_word[:score]).must_equal 32 +# end +# +# it 'accurately finds best scoring word even if not sorted' do +# words = ['XXX', 'XXXX', 'XX', 'X'] +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'XXXX' +# expect(best_word[:score]).must_equal 32 +# end +# +# it 'in case of tied score, prefers the word with fewer letters' do +# # the character 'M' is worth 3 points, 'W' is 4 points +# words = ['MMMM', 'WWW'] +# +# # verify both have a score of 12 +# expect(score_word(words.first)).must_equal 12 +# expect(score_word(words.last)).must_equal 12 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'WWW' +# expect(best_word[:score]).must_equal 12 +# end +# +# it 'in case of tied score, prefers the word with fewer letters regardless of order' do +# # the character 'M' is worth 3 points, 'W' is 4 points +# words = ['WWW', 'MMMM'] +# +# # verify both have a score of 12 +# expect(score_word(words.first)).must_equal 12 +# expect(score_word(words.last)).must_equal 12 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'WWW' +# expect(best_word[:score]).must_equal 12 +# end +# +# it 'in case of tied score, prefers most the word with 10 letters' do +# # the character 'A' is worth 1 point, 'B' is 3 points +# words = ['AAAAAAAAAA', 'BBBBBB'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'AAAAAAAAAA' +# expect(best_word[:score]).must_equal 18 +# end +# +# it 'in case of tied score, prefers most the word with 10 letters regardless of order' do +# # the character 'A' is worth 1 point, 'B' is 3 points +# words = ['BBBBBB', 'AAAAAAAAAA'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal 'AAAAAAAAAA' +# expect(best_word[:score]).must_equal 18 +# end +# +# it 'in case of tied score and same length words, prefers the first word' do +# # the character 'A' is worth 1 point, 'E' is 1 point +# words = ['AAAAAAAAAA', 'EEEEEEEEEE'] +# +# # verify both have a score of 10 +# expect(score_word(words.first)).must_equal 18 +# expect(score_word(words.last)).must_equal 18 +# +# best_word = highest_score_from words +# +# expect(best_word[:word]).must_equal words.first +# expect(best_word[:score]).must_equal 18 +# end +# end end From 59ed1a23ba4f7f837fe4e8a175337be24e9021ed Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 16:52:27 -0700 Subject: [PATCH 11/21] broken wave 4 --- lib/adagrams.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 1f7a62a..bf26225 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,4 @@ -# require 'pry' +require 'pry' # wave 1 def stores_letters letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] @@ -82,4 +82,48 @@ def score_word(word) return score end -# wave 4 +# +# # wave 4 +def highest_score_from(words) + winning_word_and_score = {} + best_word = nil # array to store hashes of user word and it's score + max_score = 0 + max_word = "" + max_scores = [] + + +binding.pry + words.each do |word| + score = score_word(word) + + if word[:score] > max_score + max_score = word[:score] + max_word = word[:word] + best_word << {word: max_word, score: max_score} + end + return + + end + + + +binding.pry + # + # word_and_score.each do |highest_score| + # if highest_score[:score] == max_score + # best_word = highest_score[:word] + # max_scores << {word: best_word, score: max_score} + # end + # end +# binding.pry +# puts highest_score_from + +# best_words = highest_score_from +# +# +# highest_score = 0 +# score_word.each do |score| +# +# +# return hash +end From 4b8645cfe32f35314b8e22d8b3421bb2233e02da Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Thu, 16 Aug 2018 16:54:38 -0700 Subject: [PATCH 12/21] not real changes --- lib/adagrams.rb | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index a9779c6..d1ebf6f 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -15,12 +15,6 @@ def welcome end -<<<<<<< HEAD -puts welcome -# binding.pry - -======= ->>>>>>> 6cd1df6ab0a2f26a4ffd1009742f6ea5f0397af2 def game_instructions puts "Based on these letters, give us a word." print "Word: " @@ -44,17 +38,7 @@ def uses_available_letters?(input, letters_in_hand) return true end -<<<<<<< HEAD -# puts uses_available_letters(get_user_input, shuffle_letters) - - -# binding.pry -# letters_in_hand = draw_letters -# input = user_input.slice(0..9) -# test = letters_in_hand.include?(user_input) -# return test -======= # wave 3 def score_word(word) score = 0 @@ -82,6 +66,5 @@ def score_word(word) if bonus_length.include?(word.length) score += 8 end - return score + return score end ->>>>>>> 6cd1df6ab0a2f26a4ffd1009742f6ea5f0397af2 From 0c5651b47cbe06ffca25979421b9e672e51e2d62 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Thu, 16 Aug 2018 16:56:31 -0700 Subject: [PATCH 13/21] some specs --- specs/adagrams_spec.rb | 254 +++++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 126 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 3cd8733..cc3eb39 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -7,45 +7,46 @@ # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new -describe 'Adagrams' do - describe 'draw_letters method' do - it 'draws ten letters from the letter pool' do - drawn_letters = draw_letters - expect(drawn_letters.size).must_equal 10 - end - - it 'returns an array, and each item is a single-letter string' do - drawn_letters = draw_letters - expect(drawn_letters.size).must_equal 10 - - expect(drawn_letters).must_be_instance_of Array - drawn_letters.each do |letter| - expect(letter).must_be_instance_of String - expect(letter.length).must_equal 1 - end - end - end - -# describe 'uses_available_letters? method' do +# wave 1 +# describe 'Adagrams' do +# describe 'draw_letters method' do +# it 'draws ten letters from the letter pool' do +# drawn_letters = draw_letters +# expect(drawn_letters.size).must_equal 10 +# end +# +# it 'returns an array, and each item is a single-letter string' do +# drawn_letters = draw_letters +# expect(drawn_letters.size).must_equal 10 +# +# expect(drawn_letters).must_be_instance_of Array +# drawn_letters.each do |letter| +# expect(letter).must_be_instance_of String +# expect(letter.length).must_equal 1 +# end +# end +# end +# +# # wave 2 +# # describe 'uses_available_letters? method' do +# it 'returns true if the submitted letters are valid against the drawn letters' do +# drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] +# test_word = 'DOG' +# +# is_valid = uses_available_letters? test_word, drawn_letters +# +# expect(is_valid).must_equal true +# end +# +# it 'returns false word contains letters not in the drawn letters' do +# drawn_letters = ['D', 'O', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] +# test_word = 'DOG' +# +# is_valid = uses_available_letters? test_word, drawn_letters +# +# expect(is_valid).must_equal false +# end # - it 'returns true if the submitted letters are valid against the drawn letters' do - drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] - test_word = 'DOG' - - is_valid = uses_available_letters? test_word, drawn_letters - - expect(is_valid).must_equal true - end - - it 'returns false word contains letters not in the drawn letters' do - drawn_letters = ['D', 'O', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] - test_word = 'DOG' - - is_valid = uses_available_letters? test_word, drawn_letters - - expect(is_valid).must_equal false - end - # it 'returns false word contains repeated letters more than in the drawn letters' do # drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] # test_word = 'AAA' @@ -56,7 +57,7 @@ # end # # end -# +# # wave 3 # describe 'score_word method' do # it 'returns an accurate numerical score according to the score chart' do # expect(score_word("A")).must_equal 1 @@ -81,91 +82,92 @@ # end # end # -# describe 'highest_score_from method' do -# it 'returns a hash that contains the word and score of best word in an array' do -# words = ['X', 'XX', 'XXX', 'XXXX'] -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'XXXX' -# expect(best_word[:score]).must_equal 32 -# end -# -# it 'accurately finds best scoring word even if not sorted' do -# words = ['XXX', 'XXXX', 'XX', 'X'] -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'XXXX' -# expect(best_word[:score]).must_equal 32 -# end -# -# it 'in case of tied score, prefers the word with fewer letters' do -# # the character 'M' is worth 3 points, 'W' is 4 points -# words = ['MMMM', 'WWW'] -# -# # verify both have a score of 12 -# expect(score_word(words.first)).must_equal 12 -# expect(score_word(words.last)).must_equal 12 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'WWW' -# expect(best_word[:score]).must_equal 12 -# end -# -# it 'in case of tied score, prefers the word with fewer letters regardless of order' do -# # the character 'M' is worth 3 points, 'W' is 4 points -# words = ['WWW', 'MMMM'] -# -# # verify both have a score of 12 -# expect(score_word(words.first)).must_equal 12 -# expect(score_word(words.last)).must_equal 12 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'WWW' -# expect(best_word[:score]).must_equal 12 -# end -# -# it 'in case of tied score, prefers most the word with 10 letters' do -# # the character 'A' is worth 1 point, 'B' is 3 points -# words = ['AAAAAAAAAA', 'BBBBBB'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'AAAAAAAAAA' -# expect(best_word[:score]).must_equal 18 -# end -# -# it 'in case of tied score, prefers most the word with 10 letters regardless of order' do -# # the character 'A' is worth 1 point, 'B' is 3 points -# words = ['BBBBBB', 'AAAAAAAAAA'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'AAAAAAAAAA' -# expect(best_word[:score]).must_equal 18 -# end -# -# it 'in case of tied score and same length words, prefers the first word' do -# # the character 'A' is worth 1 point, 'E' is 1 point -# words = ['AAAAAAAAAA', 'EEEEEEEEEE'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal words.first -# expect(best_word[:score]).must_equal 18 -# end -# end +# wave 4 + describe 'highest_score_from method' do + it 'returns a hash that contains the word and score of best word in an array' do + words = ['X', 'XX', 'XXX', 'XXXX'] + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'XXXX' + expect(best_word[:score]).must_equal 32 + end + + it 'accurately finds best scoring word even if not sorted' do + words = ['XXX', 'XXXX', 'XX', 'X'] + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'XXXX' + expect(best_word[:score]).must_equal 32 + end + + it 'in case of tied score, prefers the word with fewer letters' do + # the character 'M' is worth 3 points, 'W' is 4 points + words = ['MMMM', 'WWW'] + + # verify both have a score of 12 + expect(score_word(words.first)).must_equal 12 + expect(score_word(words.last)).must_equal 12 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'WWW' + expect(best_word[:score]).must_equal 12 + end + + it 'in case of tied score, prefers the word with fewer letters regardless of order' do + # the character 'M' is worth 3 points, 'W' is 4 points + words = ['WWW', 'MMMM'] + + # verify both have a score of 12 + expect(score_word(words.first)).must_equal 12 + expect(score_word(words.last)).must_equal 12 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'WWW' + expect(best_word[:score]).must_equal 12 + end + + it 'in case of tied score, prefers most the word with 10 letters' do + # the character 'A' is worth 1 point, 'B' is 3 points + words = ['AAAAAAAAAA', 'BBBBBB'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'AAAAAAAAAA' + expect(best_word[:score]).must_equal 18 + end + + it 'in case of tied score, prefers most the word with 10 letters regardless of order' do + # the character 'A' is worth 1 point, 'B' is 3 points + words = ['BBBBBB', 'AAAAAAAAAA'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'AAAAAAAAAA' + expect(best_word[:score]).must_equal 18 + end + + it 'in case of tied score and same length words, prefers the first word' do + # the character 'A' is worth 1 point, 'E' is 1 point + words = ['AAAAAAAAAA', 'EEEEEEEEEE'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal words.first + expect(best_word[:score]).must_equal 18 + end + end end From cdb0362316d9d87955e39068a5ee789ea3955c16 Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 20:15:21 -0700 Subject: [PATCH 14/21] sharing wave 4 update --- lib/adagrams.rb | 58 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index bf26225..478d595 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,4 @@ -require 'pry' +# require 'pry' # wave 1 def stores_letters letters = [ "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "C", "C", "D", "D", "D", "D", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "E", "F", "F", "G", "G", "G", "H", "H", "I", "I", "I", "I", "I", "I", "I", "I", "I", "J", "K", "L", "L", "L", "L", "M", "M", "N", "N", "N", "N", "N", "N", "O", "O", "O", "O", "O", "O", "O", "O", "P", "P", "Q", "R", "R", "R", "R", "R", "R", "S", "S", "S", "S", "T", "T", "T", "T", "T", "T", "U", "U", "U", "U", "V", "V", "W", "W", "X", "Y", "Y", "Z" ] @@ -85,29 +85,56 @@ def score_word(word) # # # wave 4 def highest_score_from(words) - winning_word_and_score = {} - best_word = nil # array to store hashes of user word and it's score - max_score = 0 - max_word = "" - max_scores = [] + winning_word_and_score = { + word: "", + score: 0 + } -binding.pry words.each do |word| score = score_word(word) - - if word[:score] > max_score - max_score = word[:score] - max_word = word[:word] - best_word << {word: max_word, score: max_score} + if score > winning_word_and_score[:score] + winning_word_and_score[:score] = score + winning_word_and_score[:word] = word + # elsif score == winning_word_and_score[:score] + # if winning_word_and_score[:word].length == 10 + # winning_word_and_score[:word] + # end - return - end -binding.pry + return winning_word_and_score +end + + + + + + + +# best_word = nil +# max_score = 0 +# max_word = "" +# max_scores = [] +# +# +# binding.pry +# words.each do |word| +# + # if word[:score] > max_score + # max_score = word[:score] + # max_word = word[:word] + # best_word << {word: max_word, score: max_score} + # end +# return +# +# end + + + +# binding.pry # # word_and_score.each do |highest_score| # if highest_score[:score] == max_score @@ -126,4 +153,3 @@ def highest_score_from(words) # # # return hash -end From 0ca9b1d3ee374a9811da9117aea2379101ec944d Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 20:46:05 -0700 Subject: [PATCH 15/21] fixing test file --- specs/adagrams_spec.rb | 176 ++++++++++++++++++++--------------------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 0161bf8..4ddf344 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -86,92 +86,92 @@ end # # -# # wave 4 -# describe 'highest_score_from method' do -# it 'returns a hash that contains the word and score of best word in an array' do -# words = ['X', 'XX', 'XXX', 'XXXX'] -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'XXXX' -# expect(best_word[:score]).must_equal 32 -# end -# -# it 'accurately finds best scoring word even if not sorted' do -# words = ['XXX', 'XXXX', 'XX', 'X'] -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'XXXX' -# expect(best_word[:score]).must_equal 32 -# end -# -# it 'in case of tied score, prefers the word with fewer letters' do -# # the character 'M' is worth 3 points, 'W' is 4 points -# words = ['MMMM', 'WWW'] -# -# # verify both have a score of 12 -# expect(score_word(words.first)).must_equal 12 -# expect(score_word(words.last)).must_equal 12 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'WWW' -# expect(best_word[:score]).must_equal 12 -# end -# -# it 'in case of tied score, prefers the word with fewer letters regardless of order' do -# # the character 'M' is worth 3 points, 'W' is 4 points -# words = ['WWW', 'MMMM'] -# -# # verify both have a score of 12 -# expect(score_word(words.first)).must_equal 12 -# expect(score_word(words.last)).must_equal 12 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'WWW' -# expect(best_word[:score]).must_equal 12 -# end -# -# it 'in case of tied score, prefers most the word with 10 letters' do -# # the character 'A' is worth 1 point, 'B' is 3 points -# words = ['AAAAAAAAAA', 'BBBBBB'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'AAAAAAAAAA' -# expect(best_word[:score]).must_equal 18 -# end -# -# it 'in case of tied score, prefers most the word with 10 letters regardless of order' do -# # the character 'A' is worth 1 point, 'B' is 3 points -# words = ['BBBBBB', 'AAAAAAAAAA'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal 'AAAAAAAAAA' -# expect(best_word[:score]).must_equal 18 -# end -# -# it 'in case of tied score and same length words, prefers the first word' do -# # the character 'A' is worth 1 point, 'E' is 1 point -# words = ['AAAAAAAAAA', 'EEEEEEEEEE'] -# -# # verify both have a score of 10 -# expect(score_word(words.first)).must_equal 18 -# expect(score_word(words.last)).must_equal 18 -# -# best_word = highest_score_from words -# -# expect(best_word[:word]).must_equal words.first -# expect(best_word[:score]).must_equal 18 -# end -# end +# wave 4 + describe 'highest_score_from method' do + it 'returns a hash that contains the word and score of best word in an array' do + words = ['X', 'XX', 'XXX', 'XXXX'] + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'XXXX' + expect(best_word[:score]).must_equal 32 + end + + it 'accurately finds best scoring word even if not sorted' do + words = ['XXX', 'XXXX', 'XX', 'X'] + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'XXXX' + expect(best_word[:score]).must_equal 32 + end + + it 'in case of tied score, prefers the word with fewer letters' do + # the character 'M' is worth 3 points, 'W' is 4 points + words = ['MMMM', 'WWW'] + + # verify both have a score of 12 + expect(score_word(words.first)).must_equal 12 + expect(score_word(words.last)).must_equal 12 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'WWW' + expect(best_word[:score]).must_equal 12 + end + + it 'in case of tied score, prefers the word with fewer letters regardless of order' do + # the character 'M' is worth 3 points, 'W' is 4 points + words = ['WWW', 'MMMM'] + + # verify both have a score of 12 + expect(score_word(words.first)).must_equal 12 + expect(score_word(words.last)).must_equal 12 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'WWW' + expect(best_word[:score]).must_equal 12 + end + + it 'in case of tied score, prefers most the word with 10 letters' do + # the character 'A' is worth 1 point, 'B' is 3 points + words = ['AAAAAAAAAA', 'BBBBBB'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'AAAAAAAAAA' + expect(best_word[:score]).must_equal 18 + end + + it 'in case of tied score, prefers most the word with 10 letters regardless of order' do + # the character 'A' is worth 1 point, 'B' is 3 points + words = ['BBBBBB', 'AAAAAAAAAA'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal 'AAAAAAAAAA' + expect(best_word[:score]).must_equal 18 + end + + it 'in case of tied score and same length words, prefers the first word' do + # the character 'A' is worth 1 point, 'E' is 1 point + words = ['AAAAAAAAAA', 'EEEEEEEEEE'] + + # verify both have a score of 10 + expect(score_word(words.first)).must_equal 18 + expect(score_word(words.last)).must_equal 18 + + best_word = highest_score_from words + + expect(best_word[:word]).must_equal words.first + expect(best_word[:score]).must_equal 18 + end + end end From a822e4ea4fb8cda5a14f226af452d912f1b5e282 Mon Sep 17 00:00:00 2001 From: Layla Date: Thu, 16 Aug 2018 20:46:29 -0700 Subject: [PATCH 16/21] updating wave 4 --- lib/adagrams.rb | 70 +++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 54 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 478d595..ccaedb3 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -82,8 +82,8 @@ def score_word(word) return score end -# -# # wave 4 + +# wave 4 def highest_score_from(words) winning_word_and_score = { @@ -96,60 +96,22 @@ def highest_score_from(words) if score > winning_word_and_score[:score] winning_word_and_score[:score] = score winning_word_and_score[:word] = word - # elsif score == winning_word_and_score[:score] - # if winning_word_and_score[:word].length == 10 - # winning_word_and_score[:word] - # + elsif score == winning_word_and_score[:score] #if it is a tie + # if current word has 10 letters and current winner does not, + # current word becomes new current winner. + if word.length == 10 && winning_word_and_score[:word].length != 10 + winning_word_and_score[:word] = word + # is current word has less letters than current winner, + # and current winner has less than 10 letters, current word + # becomes new current winner. + # backslash at the end of the line allows the line to continue onto the + # next line. + elsif (word.length < winning_word_and_score[:word].length) \ + && (winning_word_and_score[:word].length != 10) + winning_word_and_score[:word] = word + end end end - - return winning_word_and_score end - - - - - - - -# best_word = nil -# max_score = 0 -# max_word = "" -# max_scores = [] -# -# -# binding.pry -# words.each do |word| -# - # if word[:score] > max_score - # max_score = word[:score] - # max_word = word[:word] - # best_word << {word: max_word, score: max_score} - # end -# return -# -# end - - - -# binding.pry - # - # word_and_score.each do |highest_score| - # if highest_score[:score] == max_score - # best_word = highest_score[:word] - # max_scores << {word: best_word, score: max_score} - # end - # end -# binding.pry -# puts highest_score_from - -# best_words = highest_score_from -# -# -# highest_score = 0 -# score_word.each do |score| -# -# -# return hash From f5ab92e16ade22c4a9035ee280c2e05fc0fc8913 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Thu, 16 Aug 2018 20:58:56 -0700 Subject: [PATCH 17/21] why can't i merge this --- specs/adagrams_spec.rb | 148 ++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 41665c2..f964478 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -8,80 +8,80 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # wave 1 -# describe 'Adagrams' do -# describe 'draw_letters method' do -# it 'draws ten letters from the letter pool' do -# drawn_letters = draw_letters -# expect(drawn_letters.size).must_equal 10 -# end -# -# it 'returns an array, and each item is a single-letter string' do -# drawn_letters = draw_letters -# expect(drawn_letters.size).must_equal 10 -# -# expect(drawn_letters).must_be_instance_of Array -# drawn_letters.each do |letter| -# expect(letter).must_be_instance_of String -# expect(letter.length).must_equal 1 -# end -# end -# end -# -# # wave 2 -# # describe 'uses_available_letters? method' do -# it 'returns true if the submitted letters are valid against the drawn letters' do -# drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] -# test_word = 'DOG' -# -# is_valid = uses_available_letters? test_word, drawn_letters -# -# expect(is_valid).must_equal true -# end -# -# it 'returns false word contains letters not in the drawn letters' do -# drawn_letters = ['D', 'O', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] -# test_word = 'DOG' -# -# is_valid = uses_available_letters? test_word, drawn_letters -# -# expect(is_valid).must_equal false -# end -# -# it 'returns false word contains repeated letters more than in the drawn letters' do -# drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] -# test_word = 'AAA' -# -# is_valid = uses_available_letters? test_word, drawn_letters -# -# expect(is_valid).must_equal false -# end -# -# end - -# # wave 3 -# describe 'score_word method' do -# it 'returns an accurate numerical score according to the score chart' do -# expect(score_word("A")).must_equal 1 -# expect(score_word("DOG")).must_equal 5 -# expect(score_word("WHIMSY")).must_equal 17 -# end -# -# it 'returns a score regardless of input case' do -# expect(score_word("a")).must_equal 1 -# expect(score_word("dog")).must_equal 5 -# expect(score_word("wHiMsY")).must_equal 17 -# end -# -# it 'returns a score of 0 if given an empty input' do -# expect(score_word("")).must_equal 0 -# end -# -# it 'adds an extra 8 points if the word is 7 or more characters long' do -# expect(score_word("XXXXXXX")).must_equal 64 -# expect(score_word("XXXXXXXX")).must_equal 72 -# expect(score_word("XXXXXXXXX")).must_equal 80 -# end -# end +describe 'Adagrams' do + describe 'draw_letters method' do + it 'draws ten letters from the letter pool' do + drawn_letters = draw_letters + expect(drawn_letters.size).must_equal 10 + end + + it 'returns an array, and each item is a single-letter string' do + drawn_letters = draw_letters + expect(drawn_letters.size).must_equal 10 + + expect(drawn_letters).must_be_instance_of Array + drawn_letters.each do |letter| + expect(letter).must_be_instance_of String + expect(letter.length).must_equal 1 + end + end + end + +# wave 2 +# describe 'uses_available_letters? method' do + it 'returns true if the submitted letters are valid against the drawn letters' do + drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] + test_word = 'DOG' + + is_valid = uses_available_letters? test_word, drawn_letters + + expect(is_valid).must_equal true + end + + it 'returns false word contains letters not in the drawn letters' do + drawn_letters = ['D', 'O', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] + test_word = 'DOG' + + is_valid = uses_available_letters? test_word, drawn_letters + + expect(is_valid).must_equal false + end + + it 'returns false word contains repeated letters more than in the drawn letters' do + drawn_letters = ['A', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] + test_word = 'AAA' + + is_valid = uses_available_letters? test_word, drawn_letters + + expect(is_valid).must_equal false + end + + end + +# wave 3 + describe 'score_word method' do + it 'returns an accurate numerical score according to the score chart' do + expect(score_word("A")).must_equal 1 + expect(score_word("DOG")).must_equal 5 + expect(score_word("WHIMSY")).must_equal 17 + end + + it 'returns a score regardless of input case' do + expect(score_word("a")).must_equal 1 + expect(score_word("dog")).must_equal 5 + expect(score_word("wHiMsY")).must_equal 17 + end + + it 'returns a score of 0 if given an empty input' do + expect(score_word("")).must_equal 0 + end + + it 'adds an extra 8 points if the word is 7 or more characters long' do + expect(score_word("XXXXXXX")).must_equal 64 + expect(score_word("XXXXXXXX")).must_equal 72 + expect(score_word("XXXXXXXXX")).must_equal 80 + end + end # # wave 4 describe 'highest_score_from method' do From 9b44062c3cd73b1f65ece7a547a6744000009116 Mon Sep 17 00:00:00 2001 From: Layla Date: Fri, 17 Aug 2018 14:04:47 -0700 Subject: [PATCH 18/21] commiting again for partner --- lib/adagrams.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index ccaedb3..8be73b6 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -93,6 +93,7 @@ def highest_score_from(words) words.each do |word| score = score_word(word) + if score > winning_word_and_score[:score] winning_word_and_score[:score] = score winning_word_and_score[:word] = word From 06eda51b33d64b53ac4260954540e9d7bd802804 Mon Sep 17 00:00:00 2001 From: Layla Date: Fri, 17 Aug 2018 14:17:27 -0700 Subject: [PATCH 19/21] removed merge conflict markers --- lib/adagrams.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index bf508f0..ccc7726 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -83,12 +83,8 @@ def score_word(word) end return score -<<<<<<< HEAD -# # wave 4 -======= # wave 4 ->>>>>>> a822e4ea4fb8cda5a14f226af452d912f1b5e282 def highest_score_from(words) winning_word_and_score = { From 456d01f275f1857eb06245948cfc046de6d3536f Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Fri, 17 Aug 2018 14:32:22 -0700 Subject: [PATCH 20/21] fixed merge bugs --- lib/adagrams.rb | 3 +-- specs/adagrams_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index ccc7726..7e7c35b 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -82,7 +82,7 @@ def score_word(word) score += 8 end return score - +end # wave 4 def highest_score_from(words) @@ -116,5 +116,4 @@ def highest_score_from(words) end return winning_word_and_score - end end diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index a277c50..2cd05cd 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -2,7 +2,7 @@ require 'minitest/reporters' require 'minitest/skip_dsl' -require_relative'../lib/adagrams' +require_relative '../lib/adagrams' # Get that nice colorized output Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new @@ -28,7 +28,7 @@ end # wave 2 -# describe 'uses_available_letters? method' do + describe 'uses_available_letters? method' do it 'returns true if the submitted letters are valid against the drawn letters' do drawn_letters = ['D', 'O', 'G', 'X', 'X', 'X', 'X', 'X', 'X', 'X'] test_word = 'DOG' From 978f603db893c9490c6bbeaaae1ef60c119e23c4 Mon Sep 17 00:00:00 2001 From: Dionisia Montanez Date: Fri, 17 Aug 2018 15:30:12 -0700 Subject: [PATCH 21/21] uploading final version --- lib/adagrams.rb | 10 +++++++++- specs/adagrams_spec.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 7e7c35b..dcdebc9 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,4 +1,4 @@ -# require 'pry' +require 'csv' # wave 1 def stores_letters @@ -117,3 +117,11 @@ def highest_score_from(words) return winning_word_and_score end + +# wave 5 +def is_in_english_dict?(input) + CSV.open("assets/dictionary-english.csv", "r").each do |word| + return true if word.include?(input.downcase) + end + return false +end diff --git a/specs/adagrams_spec.rb b/specs/adagrams_spec.rb index 2cd05cd..a58f01e 100644 --- a/specs/adagrams_spec.rb +++ b/specs/adagrams_spec.rb @@ -171,6 +171,17 @@ expect(best_word[:word]).must_equal words.first expect(best_word[:score]).must_equal 18 end + + it 'if the user_input is in the dictionary' do + # Arrange + user_input = 'CAT' + + # Act + result = is_in_english_dict?(user_input) + + # Assert + expect(result).must_equal true + end end end