From eebb4872f71f5611358464af50bdc48b1c28b471 Mon Sep 17 00:00:00 2001 From: Yieni Date: Mon, 10 Feb 2020 16:29:03 -0800 Subject: [PATCH 01/17] add file. create draw letters method --- adagrams.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 adagrams.rb diff --git a/adagrams.rb b/adagrams.rb new file mode 100644 index 0000000..bd8aa18 --- /dev/null +++ b/adagrams.rb @@ -0,0 +1,10 @@ +def draw_letters + letter_choices = Array('A'..'Z') + user_hand = Array.new() + user_hand << letter_choices.sample(10) + + puts user_hand.count("J") + p user_hand +end + +draw_letters \ No newline at end of file From a3951388ed1e1fa22033da6988c7a799f9460a7e Mon Sep 17 00:00:00 2001 From: Yieni Date: Tue, 11 Feb 2020 16:00:53 -0800 Subject: [PATCH 02/17] create uses_available_letters def --- lib/adagrams.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index e69de29..dc594ff 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -0,0 +1,21 @@ +def draw_letters + letter_pool = [] + letter_choices = Hash( A: 9, B: 2, C: 2, D:4, E: 12, F: 2, G: 3, H: 2, I: 9, J: 1, K: 1, L: 4, M: 2, N: 6, O: 8, P: 2, Q: 1, R: 6, S: 4, T: 6, U: 4, V: 2, W: 2, X: 1, Y: 2, Z: 1) + letter_choices.map do |letter, number| + letter_pool << (letter.to_s * number).split(//) + end + letter_pool = letter_pool.flatten + user_hand = letter_pool.sample(10) + return user_hand +end + +p draw_letters + +def uses_available_letters(input, letters_in_hand) + split_input = input.split(//) + p letter_check = (split_input - letters_in_hand) + output = letter_check.empty? + p output +end + +uses_available_letters("a", draw_letters) \ No newline at end of file From 84ea5cd5e15391f02d22cf7585cefb4316c877da Mon Sep 17 00:00:00 2001 From: Yieni Date: Tue, 11 Feb 2020 16:28:19 -0800 Subject: [PATCH 03/17] finish second wave --- lib/adagrams.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index dc594ff..b1c50f1 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -9,13 +9,10 @@ def draw_letters return user_hand end -p draw_letters - -def uses_available_letters(input, letters_in_hand) - split_input = input.split(//) +def uses_available_letters?(input, letters_in_hand) + p split_input = input.upcase.split(//) + letter_check = 0 p letter_check = (split_input - letters_in_hand) output = letter_check.empty? p output end - -uses_available_letters("a", draw_letters) \ No newline at end of file From fcc907b92472ac33f5c3728a7992e8d2f57b6d90 Mon Sep 17 00:00:00 2001 From: Yieni Date: Tue, 11 Feb 2020 16:44:19 -0800 Subject: [PATCH 04/17] finish wave 3 --- lib/adagrams.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b1c50f1..a383787 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -16,3 +16,33 @@ def uses_available_letters?(input, letters_in_hand) output = letter_check.empty? p output end + +def score_word(word) + score_count = 0 + + split_input = word.upcase.split(//) + + split_input.each do |letter| + case letter + when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" + score_count += 1 + when "D", "G" + score_count += 2 + when "B", "C", "M", "P" + score_count += 3 + when "F", "H", "V", "W", "Y" + score_count += 4 + when "K" + score_count += 5 + when "J", "X" + score_count += 8 + when "Q", "Z" + score_count += 10 + when word.length >= 7 + score_count += 8 + end + end + return score_count +end + +p score_word("hello") \ No newline at end of file From fb61d6d12ac82257ff4abad39c1027a6e5d0e49b Mon Sep 17 00:00:00 2001 From: Yieni Date: Tue, 11 Feb 2020 20:43:34 -0800 Subject: [PATCH 05/17] refactor wave 2 --- lib/adagrams.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index a383787..477a855 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -9,14 +9,18 @@ def draw_letters return user_hand end + + def uses_available_letters?(input, letters_in_hand) - p split_input = input.upcase.split(//) - letter_check = 0 - p letter_check = (split_input - letters_in_hand) - output = letter_check.empty? - p output + split_input = input.upcase.split(//) + + letters_in_hand.each do |letter| + split_input.delete_at(split_input.index(letter)) unless split_input.index(letter).nil? + end + return split_input.empty? end + def score_word(word) score_count = 0 @@ -45,4 +49,5 @@ def score_word(word) return score_count end -p score_word("hello") \ No newline at end of file + + From 75d84f0394323ffaa0f8ec29d2f115b63ec81508 Mon Sep 17 00:00:00 2001 From: Yieni Date: Wed, 12 Feb 2020 14:40:25 -0800 Subject: [PATCH 06/17] start wave 4 --- lib/adagrams.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 477a855..8352771 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -49,5 +49,9 @@ def score_word(word) return score_count end +def highest_core_from(words) + words = Arrray.new("") + winning_hash = {:word => "", :score => 0} +end From e7288bdf8a97f936a266905710ab5a5f2f453dbc Mon Sep 17 00:00:00 2001 From: Yieni Date: Wed, 12 Feb 2020 15:31:18 -0800 Subject: [PATCH 07/17] update wave 2 to score word over 7 characters --- adagrams.rb | 10 ---------- lib/adagrams.rb | 13 +++++++------ 2 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 adagrams.rb diff --git a/adagrams.rb b/adagrams.rb deleted file mode 100644 index bd8aa18..0000000 --- a/adagrams.rb +++ /dev/null @@ -1,10 +0,0 @@ -def draw_letters - letter_choices = Array('A'..'Z') - user_hand = Array.new() - user_hand << letter_choices.sample(10) - - puts user_hand.count("J") - p user_hand -end - -draw_letters \ No newline at end of file diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 8352771..b8462f7 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -42,16 +42,17 @@ def score_word(word) score_count += 8 when "Q", "Z" score_count += 10 - when word.length >= 7 - score_count += 8 end end + score_count += 8 if word.length >= 7 return score_count end -def highest_core_from(words) - words = Arrray.new("") - winning_hash = {:word => "", :score => 0} -end +puts score_word("xylophone") + +# def highest_score_from(words) +# words = Array.new("") +# winning_hash = {:word => "", :score => 0} +# end From 1870270cceeb968ac8d1fae48a0ec2fbeb1b2ebb Mon Sep 17 00:00:00 2001 From: Yieni Date: Wed, 12 Feb 2020 16:06:08 -0800 Subject: [PATCH 08/17] wave 4 code to output word with highest score --- lib/adagrams.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b8462f7..641043a 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -48,11 +48,25 @@ def score_word(word) return score_count end -puts score_word("xylophone") +def highest_score_from(words) + word_score_array = Array.new + word_score_hash = Hash.new + highest_score = 0 + winning_word = "" + words.each do |word| + score = score_word(word) + word_score_hash[word] = score + word_score_array << word_score_hash + end -# def highest_score_from(words) -# words = Array.new("") -# winning_hash = {:word => "", :score => 0} -# end + word_score_array = word_score_array.uniq + + word_score_array.each do |check| + highest_score = check.values.max + winning_word = check.key(highest_score) + end + return winning_hash = {:word => winning_word, :score => highest_score} +end +p highest_score_from(['sharpen','pen', 'sharp']) From 30911bdd8023f946319a702f57832a29e8ad96c0 Mon Sep 17 00:00:00 2001 From: Yieni Date: Wed, 12 Feb 2020 17:37:51 -0800 Subject: [PATCH 09/17] write code for tie with shortest length and tie with same length --- lib/adagrams.rb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 641043a..9f3f3f6 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -53,6 +53,8 @@ def highest_score_from(words) word_score_hash = Hash.new highest_score = 0 winning_word = "" + shortest_word_length = 0 + words.each do |word| score = score_word(word) word_score_hash[word] = score @@ -60,13 +62,30 @@ def highest_score_from(words) end word_score_array = word_score_array.uniq - - word_score_array.each do |check| - highest_score = check.values.max - winning_word = check.key(highest_score) - end + word_score_array.each do |set| + highest_score = set.values.max + + tie = set.select { |k, v| v == highest_score} + if tie.length >= 2 + tie.each do |word, score| + if word.length > shortest_word_length + shortest_word_length += word.length + + elsif word.length < shortest_word_length + winning_word = word + + elsif word.length == shortest_word_length + winning_word = set.key(highest_score) + end + end + else + winning_word = set.key(highest_score) + end + end return winning_hash = {:word => winning_word, :score => highest_score} end -p highest_score_from(['sharpen','pen', 'sharp']) +puts highest_score_from(['sharpen','qz', 'sharp']) + + From 6f0682cf60d7b684558a00809b55aaabdce4927a Mon Sep 17 00:00:00 2001 From: Yieni Date: Wed, 12 Feb 2020 18:37:04 -0800 Subject: [PATCH 10/17] passes all tests through wave 4 --- lib/adagrams.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 9f3f3f6..b14d99c 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -69,13 +69,23 @@ def highest_score_from(words) tie = set.select { |k, v| v == highest_score} if tie.length >= 2 tie.each do |word, score| - if word.length > shortest_word_length - shortest_word_length += word.length - + if word.length > shortest_word_length + if shortest_word_length == 0 + shortest_word_length = word.length + winning_word = word + elsif word.length == 10 + shortest_word_length = word.length + winning_word = word + end + elsif word.length < shortest_word_length - winning_word = word + if shortest_word_length == 10 + nil + else + winning_word = word + end - elsif word.length == shortest_word_length + elsif word.length == shortest_word_length winning_word = set.key(highest_score) end end @@ -86,6 +96,6 @@ def highest_score_from(words) return winning_hash = {:word => winning_word, :score => highest_score} end -puts highest_score_from(['sharpen','qz', 'sharp']) + From 80e546039ce4a7761a8ea535cc9e1c4b4a70d2f0 Mon Sep 17 00:00:00 2001 From: Charlotte Adams Date: Thu, 13 Feb 2020 08:38:48 -0800 Subject: [PATCH 11/17] learning about git --- lib/adagrams.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b8462f7..b1a4863 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -48,11 +48,10 @@ def score_word(word) return score_count end -puts score_word("xylophone") -# def highest_score_from(words) -# words = Array.new("") -# winning_hash = {:word => "", :score => 0} -# end +def highest_score_from(words) + words = Array.new("") + winning_hash = {:word => "", :score => 0} +end From f9eb3432c770a725590456ccfcbd0fcd15126e64 Mon Sep 17 00:00:00 2001 From: Yieni Date: Thu, 13 Feb 2020 14:44:36 -0800 Subject: [PATCH 12/17] passes all 4 mandatory waves --- lib/adagrams.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b14d99c..279e537 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -95,7 +95,3 @@ def highest_score_from(words) end return winning_hash = {:word => winning_word, :score => highest_score} end - - - - From b44c0f41ed66b9396119f4e94da95dee0c17d109 Mon Sep 17 00:00:00 2001 From: Yieni Date: Thu, 13 Feb 2020 15:02:43 -0800 Subject: [PATCH 13/17] fixing origin/master --- lib/adagrams.rb | 53 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 6007cd7..f1035d7 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -9,8 +9,6 @@ def draw_letters return user_hand end - - def uses_available_letters?(input, letters_in_hand) split_input = input.upcase.split(//) @@ -20,7 +18,6 @@ def uses_available_letters?(input, letters_in_hand) return split_input.empty? end - def score_word(word) score_count = 0 @@ -48,8 +45,50 @@ def score_word(word) return score_count end - def highest_score_from(words) - words = Array.new("") - winning_hash = {:word => "", :score => 0} -end + word_score_array = Array.new + word_score_hash = Hash.new + highest_score = 0 + winning_word = "" + shortest_word_length = 0 + + words.each do |word| + score = score_word(word) + word_score_hash[word] = score + word_score_array << word_score_hash + end + + word_score_array = word_score_array.uniq + + word_score_array.each do |set| + highest_score = set.values.max + + tie = set.select { |k, v| v == highest_score} + if tie.length >= 2 + tie.each do |word, score| + if word.length > shortest_word_length + if shortest_word_length == 0 + shortest_word_length = word.length + winning_word = word + elsif word.length == 10 + shortest_word_length = word.length + winning_word = word + end + + elsif word.length < shortest_word_length + if shortest_word_length == 10 + nil + else + winning_word = word + end + + elsif word.length == shortest_word_length + winning_word = set.key(highest_score) + end + end + else + winning_word = set.key(highest_score) + end + end + return winning_hash = {:word => winning_word, :score => highest_score} +end \ No newline at end of file From c232ba42965d2713a53d77e8312ee41a7b54d009 Mon Sep 17 00:00:00 2001 From: Charlotte Adams Date: Thu, 13 Feb 2020 15:05:45 -0800 Subject: [PATCH 14/17] get correct code --- lib/adagrams.rb | 51 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index b1a4863..f1035d7 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -9,8 +9,6 @@ def draw_letters return user_hand end - - def uses_available_letters?(input, letters_in_hand) split_input = input.upcase.split(//) @@ -20,7 +18,6 @@ def uses_available_letters?(input, letters_in_hand) return split_input.empty? end - def score_word(word) score_count = 0 @@ -48,10 +45,50 @@ def score_word(word) return score_count end - def highest_score_from(words) - words = Array.new("") - winning_hash = {:word => "", :score => 0} -end + word_score_array = Array.new + word_score_hash = Hash.new + highest_score = 0 + winning_word = "" + shortest_word_length = 0 + + words.each do |word| + score = score_word(word) + word_score_hash[word] = score + word_score_array << word_score_hash + end + + word_score_array = word_score_array.uniq + + word_score_array.each do |set| + highest_score = set.values.max + tie = set.select { |k, v| v == highest_score} + if tie.length >= 2 + tie.each do |word, score| + if word.length > shortest_word_length + if shortest_word_length == 0 + shortest_word_length = word.length + winning_word = word + elsif word.length == 10 + shortest_word_length = word.length + winning_word = word + end + elsif word.length < shortest_word_length + if shortest_word_length == 10 + nil + else + winning_word = word + end + + elsif word.length == shortest_word_length + winning_word = set.key(highest_score) + end + end + else + winning_word = set.key(highest_score) + end + end + return winning_hash = {:word => winning_word, :score => highest_score} +end \ No newline at end of file From 30495242f08b4bf255f12f27454696033b30c7fe Mon Sep 17 00:00:00 2001 From: Charlotte Adams Date: Thu, 13 Feb 2020 15:24:31 -0800 Subject: [PATCH 15/17] add dictionary csv --- lib/adagrams.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index f1035d7..53a3207 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -1,3 +1,6 @@ +require 'csv' +require 'awesome_print' + def draw_letters letter_pool = [] letter_choices = Hash( A: 9, B: 2, C: 2, D:4, E: 12, F: 2, G: 3, H: 2, I: 9, J: 1, K: 1, L: 4, M: 2, N: 6, O: 8, P: 2, Q: 1, R: 6, S: 4, T: 6, U: 4, V: 2, W: 2, X: 1, Y: 2, Z: 1) @@ -91,4 +94,12 @@ def highest_score_from(words) end end return winning_hash = {:word => winning_word, :score => highest_score} -end \ No newline at end of file +end + +def is_in_english_dict?(input) + dictionary = CSV.read('assets/dictionary-english.csv', headers: true) + return dictionary.include?(input) + +end + +p is_in_english_dict?("hello") \ No newline at end of file From f359fb538994195ae5753e2242f5cc4d6012a28d Mon Sep 17 00:00:00 2001 From: Yieni Date: Thu, 13 Feb 2020 16:54:28 -0800 Subject: [PATCH 16/17] started wave 5 and added tests for wave 5 --- .vscode/launch.json | 11 +++++++++++ lib/adagrams.rb | 12 +++++++----- test/adagrams_test.rb | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..591f8b0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + + null + ] +} \ No newline at end of file diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 53a3207..47457a3 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -67,7 +67,7 @@ def highest_score_from(words) highest_score = set.values.max tie = set.select { |k, v| v == highest_score} - if tie.length >= 2 + if tie.length > 1 tie.each do |word, score| if word.length > shortest_word_length if shortest_word_length == 0 @@ -97,9 +97,11 @@ def highest_score_from(words) end def is_in_english_dict?(input) - dictionary = CSV.read('assets/dictionary-english.csv', headers: true) - return dictionary.include?(input) - + + dictionary = CSV.read('assets/dictionary-english.csv') + dictionary = dictionary.flatten + return dictionary.include?(input) + end -p is_in_english_dict?("hello") \ No newline at end of file +p is_in_english_dict?("dasfads") \ No newline at end of file diff --git a/test/adagrams_test.rb b/test/adagrams_test.rb index 90ec44d..7a570fe 100644 --- a/test/adagrams_test.rb +++ b/test/adagrams_test.rb @@ -178,4 +178,26 @@ expect(best_word[:score]).must_equal 18 end end + + describe 'is_in_english_dict?' do + it 'checks if input word is in english dictionary' do + input = 'hello' + expect(is_in_english_dict?(input)).must_equal true + end + + it 'checks if input is not in the english dictionary' do + input = 'asdf' + expect(is_in_english_dict?(input)).must_equal false + end + + it 'calls ArgumentError on empty string' do + input = ' ' + expect{is_in_english_dict?(input)}.must_raise ArgumentError + end + + it "calls ArgumentError on non string inputs" do + input = "234sdf" + expect{is_in_english_dict?(input)}.must_raise ArgumentError + end + end end From 1744d564cec6d4d37981786dedbdf7570a7cb7ad Mon Sep 17 00:00:00 2001 From: Yieni Date: Fri, 14 Feb 2020 15:03:38 -0800 Subject: [PATCH 17/17] Final working code with all 5 waves --- lib/adagrams.rb | 73 +++++++++++++++++++++---------------------- test/adagrams_test.rb | 9 ++++-- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/adagrams.rb b/lib/adagrams.rb index 47457a3..97b8aa4 100644 --- a/lib/adagrams.rb +++ b/lib/adagrams.rb @@ -3,12 +3,15 @@ def draw_letters letter_pool = [] - letter_choices = Hash( A: 9, B: 2, C: 2, D:4, E: 12, F: 2, G: 3, H: 2, I: 9, J: 1, K: 1, L: 4, M: 2, N: 6, O: 8, P: 2, Q: 1, R: 6, S: 4, T: 6, U: 4, V: 2, W: 2, X: 1, Y: 2, Z: 1) + letter_choices = Hash( A: 9, B: 2, C: 2, D:4, E: 12, F: 2, G: 3, H: 2, I: 9, J: 1, K: 1, L: 4, M: 2, + N: 6, O: 8, P: 2, Q: 1, R: 6, S: 4, T: 6, U: 4, V: 2, W: 2, X: 1, Y: 2, Z: 1) + letter_choices.map do |letter, number| letter_pool << (letter.to_s * number).split(//) end letter_pool = letter_pool.flatten user_hand = letter_pool.sample(10) + return user_hand end @@ -18,12 +21,12 @@ def uses_available_letters?(input, letters_in_hand) letters_in_hand.each do |letter| split_input.delete_at(split_input.index(letter)) unless split_input.index(letter).nil? end + return split_input.empty? end def score_word(word) score_count = 0 - split_input = word.upcase.split(//) split_input.each do |letter| @@ -44,12 +47,12 @@ def score_word(word) score_count += 10 end end - score_count += 8 if word.length >= 7 + + score_count += 8 if word.length > 6 return score_count end def highest_score_from(words) - word_score_array = Array.new word_score_hash = Hash.new highest_score = 0 winning_word = "" @@ -58,50 +61,44 @@ def highest_score_from(words) words.each do |word| score = score_word(word) word_score_hash[word] = score - word_score_array << word_score_hash end + + highest_score = word_score_hash.values.max - word_score_array = word_score_array.uniq - - word_score_array.each do |set| - highest_score = set.values.max - - tie = set.select { |k, v| v == highest_score} - if tie.length > 1 - tie.each do |word, score| - if word.length > shortest_word_length - if shortest_word_length == 0 - shortest_word_length = word.length - winning_word = word - elsif word.length == 10 - shortest_word_length = word.length - winning_word = word - end - - elsif word.length < shortest_word_length - if shortest_word_length == 10 - nil - else - winning_word = word - end + tie = word_score_hash.select { |k, v| v == highest_score} + if tie.length > 1 + tie.each do |word, score| + if word.length > shortest_word_length + if shortest_word_length == 0 + shortest_word_length = word.length + winning_word = word + elsif word.length == 10 + shortest_word_length = word.length + winning_word = word + end - elsif word.length == shortest_word_length - winning_word = set.key(highest_score) + elsif word.length < shortest_word_length + if shortest_word_length == 10 + nil + else + winning_word = word end + + elsif word.length == shortest_word_length + winning_word = word_score_hash.key(highest_score) end - else - winning_word = set.key(highest_score) end + else + winning_word = word_score_hash.key(highest_score) end return winning_hash = {:word => winning_word, :score => highest_score} end def is_in_english_dict?(input) - dictionary = CSV.read('assets/dictionary-english.csv') dictionary = dictionary.flatten - return dictionary.include?(input) - -end - -p is_in_english_dict?("dasfads") \ No newline at end of file + raise ArgumentError if input == "" + raise ArgumentError if input.nil? + raise ArgumentError if input.class != String + return dictionary.include?(input) +end \ No newline at end of file diff --git a/test/adagrams_test.rb b/test/adagrams_test.rb index 7a570fe..9fb26e2 100644 --- a/test/adagrams_test.rb +++ b/test/adagrams_test.rb @@ -191,12 +191,17 @@ end it 'calls ArgumentError on empty string' do - input = ' ' + input = "" + expect{is_in_english_dict?(input)}.must_raise ArgumentError + end + + it 'calls ArgumentError if input is nil' do + input = nil expect{is_in_english_dict?(input)}.must_raise ArgumentError end it "calls ArgumentError on non string inputs" do - input = "234sdf" + input = 234 expect{is_in_english_dict?(input)}.must_raise ArgumentError end end